chore(docs): improve website generation config (#11527)

This commit is contained in:
Lucian Mocanu 2025-06-14 09:39:49 +02:00 committed by GitHub
parent 42913b95d7
commit 03faa7867e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 1541 additions and 2097 deletions

View File

@ -179,10 +179,11 @@ const rawData = await dataSource.query(
- `sql` - Executes a raw SQL query using template literals.
```typescript
const rawData = await dataSource.sql`SELECT * FROM USERS WHERE name = ${'John'} and age = ${24}`
const rawData =
await dataSource.sql`SELECT * FROM USERS WHERE name = ${"John"} and age = ${24}`
```
Learn more about using the [SQL Tag syntax](sql-tag.md).
Learn more about using the [SQL Tag syntax](../guides/7-sql-tag.md).
- `createQueryBuilder` - Creates a query builder, which can be used to build queries.
Learn more about [QueryBuilder](../query-builder/1-select-query-builder.md).

View File

@ -68,10 +68,11 @@ const rawData = await manager.query(
- `sql` - Executes a raw SQL query using template literals.
```typescript
const rawData = await manager.sql`SELECT * FROM USERS WHERE name = ${'John'} and age = ${24}`
const rawData =
await manager.sql`SELECT * FROM USERS WHERE name = ${"John"} and age = ${24}`
```
Learn more about using the [SQL Tag syntax](sql-tag.md).
Learn more about using the [SQL Tag syntax](../guides/7-sql-tag.md).
- `createQueryBuilder` - Creates a query builder use to build SQL queries.
Learn more about [QueryBuilder](../query-builder/1-select-query-builder.md).
@ -186,7 +187,7 @@ await manager.update(User, 1, { firstName: "Rizzrak" })
// executes UPDATE user SET firstName = Rizzrak WHERE id = 1
```
- `updateAll` - Updates *all* entities of target type (without WHERE clause). Sets fields from supplied partial entity.
- `updateAll` - Updates _all_ entities of target type (without WHERE clause). Sets fields from supplied partial entity.
```typescript
await manager.updateAll(User, { category: "ADULT" })
@ -221,7 +222,7 @@ await manager.delete(User, [1, 2, 3])
await manager.delete(User, { firstName: "Timber" })
```
- `deleteAll` - Deletes *all* entities of target type (without WHERE clause).
- `deleteAll` - Deletes _all_ entities of target type (without WHERE clause).
```typescript
await manager.deleteAll(User)

View File

@ -46,7 +46,7 @@ const config: Config = {
presets: [
[
"classic",
"@docusaurus/preset-classic",
{
docs: {
sidebarPath: "./sidebars.ts",
@ -55,6 +55,10 @@ const config: Config = {
editUrl:
"https://github.com/typeorm/typeorm/tree/master/docs/",
},
sitemap: {
lastmod: "datetime",
changefreq: null,
},
theme: {
customCss: "./src/css/custom.css",
},
@ -145,7 +149,13 @@ const config: Config = {
prism: {
theme: prismThemes.github,
darkTheme: prismThemes.dracula,
additionalLanguages: ["typescript", "javascript", "bash", "json"],
additionalLanguages: [
"typescript",
"javascript",
"bash",
"json",
"sql",
],
},
typesense: {
// Replace this with the name of your index/collection.

3485
docs/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -27,20 +27,20 @@
]
},
"dependencies": {
"@docusaurus/core": "3.7.0",
"@docusaurus/plugin-client-redirects": "^3.7.0",
"@docusaurus/preset-classic": "3.7.0",
"@docusaurus/core": "3.8.1",
"@docusaurus/plugin-client-redirects": "^3.8.1",
"@docusaurus/preset-classic": "3.8.1",
"@mdx-js/react": "^3.1.0",
"clsx": "^2.1.1",
"docusaurus-theme-search-typesense": "^0.24.0",
"docusaurus-theme-search-typesense": "^0.25.0",
"prism-react-renderer": "^2.4.1",
"react": "^19.1.0",
"react-dom": "^19.1.0"
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.7.0",
"@docusaurus/tsconfig": "3.7.0",
"@docusaurus/types": "3.7.0",
"@docusaurus/module-type-aliases": "3.8.1",
"@docusaurus/tsconfig": "3.8.1",
"@docusaurus/types": "3.8.1",
"typescript": "~5.8.3"
},
"engines": {

View File

@ -1,103 +0,0 @@
# SQL Tag
TypeORM provides a way to write SQL queries using template literals with automatic parameter handling based on your database type. This feature helps prevent SQL injection while making queries more readable. The SQL tag is implemented as a wrapper around the `.query` method, providing an alternative interface while maintaining the same underlying functionality.
## Basic Usage
The `sql` tag is available on DataSource, EntityManager, Repository and QueryRunner instances:
```typescript
const users = await dataSource.sql`SELECT * FROM users WHERE name = ${"John"}`
```
## Parameter Handling
Parameters are automatically escaped and formatted according to your database type:
- **PostgreSQL, CockroachDB, Aurora PostgreSQL, MariaDB**: Uses `$1`, `$2`, etc.
```typescript
// Query becomes: SELECT * FROM users WHERE name = $1
const users = await dataSource.sql`SELECT * FROM users WHERE name = ${"John"}`
```
- **MySQL, SQLite, Aurora MySQL**: Uses `?`
```typescript
// Query becomes: SELECT * FROM users WHERE name = ?
const users = await dataSource.sql`SELECT * FROM users WHERE name = ${"John"}`
```
- **Oracle**: Uses `:1`, `:2`, etc.
```typescript
// Query becomes: SELECT * FROM users WHERE name = :1
const users = await dataSource.sql`SELECT * FROM users WHERE name = ${"John"}`
```
- **MSSQL**: Uses `@1`, `@2`, etc.
```typescript
// Query becomes: SELECT * FROM users WHERE name = @1
const users = await dataSource.sql`SELECT * FROM users WHERE name = ${"John"}`
```
### Multiple Parameters
You can use multiple parameters and complex expressions:
```typescript
const name = "John"
const age = 30
const active = true
const users = await dataSource.sql`
SELECT * FROM users
WHERE name LIKE ${name + "%"}
AND age > ${age}
AND is_active = ${active}
`
```
### Expanding Parameter Lists
To transform an array of values into a dynamic list of parameters in a template expression, wrap the array in a function. This is commonly used to write an `IN (...)` expression in SQL, where each value in the list must be supplied as a separate parameter:
```typescript
// Query becomes: SELECT * FROM users WHERE id IN (?, ?, ?)
const users = await dataSource.sql`
SELECT * FROM users
WHERE id IN (${() => [1, 2, 3]})
`
```
### Interpolating Unescaped Expressions
When you want to insert a template expression which should _not_ be transformed into a database parameter, wrap the string in a function. This can be used to dynamically define column, table or schema names which can't be parameterized, or to conditionally set clauses in the SQL.
**Caution!** No escaping is performed on raw SQL inserted in this way. It is not safe to use this with values sourced from user input.
```typescript
// Query becomes: SELECT * FROM dynamic_table_name
const rawData = await dataSource.sql`
SELECT * FROM ${() => "dynamic_table_name"}
`
```
## Features
- **SQL Injection Prevention**: Parameters are properly escaped
- **Database Agnostic**: Parameter formatting is handled based on your database type
- **Readable Queries**: Template literals can make queries more readable than parameter arrays
## Comparison with Query Method
The traditional `query` method requires manual parameter placeholder handling:
```typescript
// Traditional query method
await dataSource.query(
"SELECT * FROM users WHERE name = $1 AND age > $2",
["John", 30]
)
// SQL tag alternative
await dataSource.sql`SELECT * FROM users WHERE name = ${"John"} AND age > ${30}`
```
The SQL tag handles parameter formatting automatically, which can reduce potential errors.

4
docs/static/robots.txt vendored Normal file
View File

@ -0,0 +1,4 @@
User-agent: *
Allow: /
Sitemap: https://typeorm.io/sitemap.xml