Skip to content

Commit 23e905e

Browse files
authored
Merge branch 'master' into feat/change-default-behavior-of-invalid-where-values-to-be-throw
2 parents e18a9fd + 09db48c commit 23e905e

27 files changed

Lines changed: 509 additions & 471 deletions

File tree

docs/docs/advanced-topics/3-indices.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ TypeORM supports generating SQL with this option when the concurrent option is s
144144

145145
For more information see the [Postgres documentation](https://www.postgresql.org/docs/current/sql-createindex.html).
146146

147+
## Index Type
148+
If you need to specify a custom type for the index, you can use the `type` property. If the `spatial` property is set, this field will be ignored.
149+
150+
```typescript
151+
@Index({ type: 'hash' })
152+
```
153+
154+
This feature is currently supported only for PostgreSQL.
155+
147156
## Disabling synchronization
148157

149158
TypeORM does not support some index options and definitions (e.g. `lower`, `pg_trgm`) due to many database-specific differences and multiple

docs/docs/guides/8-migration-v1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ Glob patterns are now handled by `tinyglobby` instead of `glob`. While `tinyglob
1111
## MySQL / MariaDB
1212

1313
The `connectorPackage` option was removed, together with the support for the old `mysql` client. The only database client supported is now `mysql2`, which TypeORM will try to load by default. If you were using `mysql` in your project, simply replace it with `mysql2`.
14+
15+
## Expo
16+
17+
Support for the legacy Expo SQLite driver has been removed. The legacy API was removed by Expo in SDK v52, so you'll need to use Expo SDK v52 or later with the modern async SQLite API.

src/decorator/Index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export function Index(
132132
? false
133133
: true,
134134
where: options ? options.where : undefined,
135+
type: options ? options.type : undefined,
135136
unique: options && options.unique ? true : false,
136137
spatial: options && options.spatial ? true : false,
137138
fulltext: options && options.fulltext ? true : false,

src/decorator/options/IndexOptions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { TableIndexTypes } from "../../schema-builder/options/TableIndexTypes"
2+
13
/**
24
* Describes all index options.
35
*/
@@ -63,4 +65,11 @@ export interface IndexOptions {
6365
* This option is only supported for mongodb database.
6466
*/
6567
expireAfterSeconds?: number
68+
69+
/**
70+
* The `type` option defines the type of the index being created.
71+
* Supported types include B-tree, Hash, GiST, SP-GiST, GIN, and BRIN
72+
* This option is only applicable in PostgreSQL.
73+
*/
74+
type?: TableIndexTypes
6675
}

src/driver/Driver.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { TableForeignKey } from "../schema-builder/table/TableForeignKey"
1616
import { UpsertType } from "./types/UpsertType"
1717
import { OnDeleteType } from "../metadata/types/OnDeleteType"
1818
import { OnUpdateType } from "../metadata/types/OnUpdateType"
19+
import { TableIndex } from "../schema-builder/table/TableIndex"
20+
import { IndexMetadata } from "../metadata/IndexMetadata"
21+
import { TableIndexTypes } from "../schema-builder/options/TableIndexTypes"
1922

2023
export type ReturningType = "insert" | "update" | "delete"
2124

@@ -96,6 +99,11 @@ export interface Driver {
9699
*/
97100
withLengthColumnTypes: ColumnType[]
98101

102+
/**
103+
* Supported index types
104+
*/
105+
supportedIndexTypes?: TableIndexTypes[]
106+
99107
/**
100108
* Gets list of column data types that support precision by a driver.
101109
*/
@@ -282,4 +290,12 @@ export interface Driver {
282290
* Creates an escaped parameter.
283291
*/
284292
createParameter(parameterName: string, index: number): string
293+
294+
/**
295+
* Returns true if both indexes types are equivalent
296+
*/
297+
compareTableIndexTypes?: (
298+
indexA: IndexMetadata,
299+
indexB: TableIndex,
300+
) => boolean
285301
}

src/driver/DriverFactory.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { NativescriptDriver } from "./nativescript/NativescriptDriver"
1010
import { SqljsDriver } from "./sqljs/SqljsDriver"
1111
import { MysqlDriver } from "./mysql/MysqlDriver"
1212
import { PostgresDriver } from "./postgres/PostgresDriver"
13-
import { ExpoDriverFactory } from "./expo/ExpoDriverFactory"
1413
import { AuroraMysqlDriver } from "./aurora-mysql/AuroraMysqlDriver"
1514
import { AuroraPostgresDriver } from "./aurora-postgres/AuroraPostgresDriver"
1615
import { Driver } from "./Driver"
@@ -19,13 +18,16 @@ import { SapDriver } from "./sap/SapDriver"
1918
import { BetterSqlite3Driver } from "./better-sqlite3/BetterSqlite3Driver"
2019
import { CapacitorDriver } from "./capacitor/CapacitorDriver"
2120
import { SpannerDriver } from "./spanner/SpannerDriver"
21+
import { ExpoDriver } from "./expo/ExpoDriver"
2222

2323
/**
2424
* Helps to create drivers.
2525
*/
2626
export class DriverFactory {
2727
/**
2828
* Creates a new driver depend on a given connection's driver type.
29+
* @param connection DataSource instance.
30+
* @returns Driver
2931
*/
3032
create(connection: DataSource): Driver {
3133
const { type } = connection.options
@@ -59,7 +61,7 @@ export class DriverFactory {
5961
case "mongodb":
6062
return new MongoDriver(connection)
6163
case "expo":
62-
return new ExpoDriverFactory(connection).create()
64+
return new ExpoDriver(connection)
6365
case "aurora-mysql":
6466
return new AuroraMysqlDriver(connection)
6567
case "aurora-postgres":

src/driver/cockroachdb/CockroachQueryRunner.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ export class CockroachQueryRunner
6161
/**
6262
* Stores all executed queries to be able to run them again if transaction fails.
6363
*/
64-
protected queries: { query: string; parameters?: any[] }[] = []
64+
protected queries: {
65+
query: string
66+
parameters?: any[]
67+
useStructuredResult: boolean
68+
}[] = []
6569

6670
/**
6771
* Indicates if running queries must be stored
@@ -278,7 +282,7 @@ export class CockroachQueryRunner
278282
const queryStartTime = Date.now()
279283

280284
if (this.isTransactionActive && this.storeQueries) {
281-
this.queries.push({ query, parameters })
285+
this.queries.push({ query, parameters, useStructuredResult })
282286
}
283287

284288
try {
@@ -365,7 +369,11 @@ export class CockroachQueryRunner
365369
q.parameters,
366370
this,
367371
)
368-
result = await this.query(q.query, q.parameters)
372+
result = await this.query(
373+
q.query,
374+
q.parameters,
375+
q.useStructuredResult,
376+
)
369377
}
370378
this.transactionRetries = 0
371379
this.storeQueries = true

src/driver/expo/ExpoDriver.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ import { ExpoConnectionOptions } from "./ExpoConnectionOptions"
33
import { ExpoQueryRunner } from "./ExpoQueryRunner"
44
import { QueryRunner } from "../../query-runner/QueryRunner"
55
import { DataSource } from "../../data-source/DataSource"
6+
import { TypeORMError } from "../../error"
67

78
export class ExpoDriver extends AbstractSqliteDriver {
89
declare options: ExpoConnectionOptions
910

1011
constructor(connection: DataSource) {
1112
super(connection)
13+
14+
if (this.isLegacyDriver) {
15+
throw new TypeORMError("Legacy Expo driver is not supported.")
16+
}
17+
1218
this.sqlite = this.options.driver
1319
}
1420

@@ -31,4 +37,8 @@ export class ExpoDriver extends AbstractSqliteDriver {
3137
await this.databaseConnection.runAsync("PRAGMA foreign_keys = ON")
3238
return this.databaseConnection
3339
}
40+
41+
private get isLegacyDriver(): boolean {
42+
return !("openDatabaseAsync" in this.options.driver)
43+
}
3444
}

src/driver/expo/ExpoDriverFactory.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/driver/expo/legacy/ExpoLegacyDriver.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)