@strapi/database 5.50.2 → 5.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connection.d.ts +8 -0
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +4 -3
- package/dist/connection.js.map +1 -1
- package/dist/connection.mjs +4 -4
- package/dist/connection.mjs.map +1 -1
- package/dist/dialects/mysql/index.d.ts +2 -1
- package/dist/dialects/mysql/index.d.ts.map +1 -1
- package/dist/dialects/mysql/index.js +2 -2
- package/dist/dialects/mysql/index.js.map +1 -1
- package/dist/dialects/mysql/index.mjs +2 -2
- package/dist/dialects/mysql/index.mjs.map +1 -1
- package/dist/entity-manager/index.d.ts.map +1 -1
- package/dist/entity-manager/index.js +14 -2
- package/dist/entity-manager/index.js.map +1 -1
- package/dist/entity-manager/index.mjs +14 -2
- package/dist/entity-manager/index.mjs.map +1 -1
- package/dist/entity-manager/relations-orderer.d.ts.map +1 -1
- package/dist/entity-manager/relations-orderer.js +36 -22
- package/dist/entity-manager/relations-orderer.js.map +1 -1
- package/dist/entity-manager/relations-orderer.mjs +30 -16
- package/dist/entity-manager/relations-orderer.mjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/query/query-builder.d.ts +3 -1
- package/dist/query/query-builder.d.ts.map +1 -1
- package/dist/query/query-builder.js +14 -0
- package/dist/query/query-builder.js.map +1 -1
- package/dist/query/query-builder.mjs +14 -0
- package/dist/query/query-builder.mjs.map +1 -1
- package/package.json +5 -5
package/dist/connection.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import knex from 'knex';
|
|
2
2
|
import type { Knex } from 'knex';
|
|
3
|
+
declare const clientMap: {
|
|
4
|
+
sqlite: string;
|
|
5
|
+
mysql: string;
|
|
6
|
+
postgres: string;
|
|
7
|
+
};
|
|
8
|
+
type ClientKind = keyof typeof clientMap;
|
|
9
|
+
export declare function isDatabaseClientKind(client: unknown): client is ClientKind;
|
|
3
10
|
export declare const createConnection: (userConfig: Knex.Config, strapiConfig?: Partial<Knex.Config>) => knex.Knex<any, unknown[]>;
|
|
11
|
+
export {};
|
|
4
12
|
//# sourceMappingURL=connection.d.ts.map
|
package/dist/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC,QAAA,MAAM,SAAS;;;;CAId,CAAC;AAEF,KAAK,UAAU,GAAG,MAAM,OAAO,SAAS,CAAC;AAEzC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,UAAU,CAE1E;AAED,eAAO,MAAM,gBAAgB,GAAI,YAAY,IAAI,CAAC,MAAM,EAAE,eAAe,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,8BA8B5F,CAAC"}
|
package/dist/connection.js
CHANGED
|
@@ -11,11 +11,11 @@ const clientMap = {
|
|
|
11
11
|
mysql: 'mysql2',
|
|
12
12
|
postgres: 'pg'
|
|
13
13
|
};
|
|
14
|
-
function
|
|
15
|
-
return
|
|
14
|
+
function isDatabaseClientKind(client) {
|
|
15
|
+
return client in clientMap;
|
|
16
16
|
}
|
|
17
17
|
const createConnection = (userConfig, strapiConfig)=>{
|
|
18
|
-
if (!
|
|
18
|
+
if (!isDatabaseClientKind(userConfig.client)) {
|
|
19
19
|
throw new Error(`Unsupported database client ${userConfig.client}`);
|
|
20
20
|
}
|
|
21
21
|
const knexConfig = {
|
|
@@ -44,4 +44,5 @@ const createConnection = (userConfig, strapiConfig)=>{
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
exports.createConnection = createConnection;
|
|
47
|
+
exports.isDatabaseClientKind = isDatabaseClientKind;
|
|
47
48
|
//# sourceMappingURL=connection.js.map
|
package/dist/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sources":["../src/connection.ts"],"sourcesContent":["import knex from 'knex';\nimport type { Knex } from 'knex';\n\nconst clientMap = {\n sqlite: 'better-sqlite3',\n mysql: 'mysql2',\n postgres: 'pg',\n};\n\
|
|
1
|
+
{"version":3,"file":"connection.js","sources":["../src/connection.ts"],"sourcesContent":["import knex from 'knex';\nimport type { Knex } from 'knex';\n\nconst clientMap = {\n sqlite: 'better-sqlite3',\n mysql: 'mysql2',\n postgres: 'pg',\n};\n\ntype ClientKind = keyof typeof clientMap;\n\nexport function isDatabaseClientKind(client: unknown): client is ClientKind {\n return (client as string) in clientMap;\n}\n\nexport const createConnection = (userConfig: Knex.Config, strapiConfig?: Partial<Knex.Config>) => {\n if (!isDatabaseClientKind(userConfig.client)) {\n throw new Error(`Unsupported database client ${userConfig.client}`);\n }\n\n const knexConfig: Knex.Config = { ...userConfig, client: clientMap[userConfig.client] };\n\n // initialization code to run upon opening a new connection\n if (strapiConfig?.pool?.afterCreate) {\n knexConfig.pool = knexConfig.pool || {};\n // if the user has set their own afterCreate in config, we will replace it and call it\n const userAfterCreate = knexConfig.pool?.afterCreate;\n const strapiAfterCreate = strapiConfig.pool.afterCreate;\n knexConfig.pool.afterCreate = (\n conn: unknown,\n done: (err: Error | null | undefined, connection: any) => void\n ) => {\n strapiAfterCreate(conn, (err: Error | null | undefined, nativeConn: any) => {\n if (err) {\n return done(err, nativeConn);\n }\n if (userAfterCreate) {\n return userAfterCreate(nativeConn, done);\n }\n return done(null, nativeConn);\n });\n };\n }\n\n return knex(knexConfig);\n};\n"],"names":["clientMap","sqlite","mysql","postgres","isDatabaseClientKind","client","createConnection","userConfig","strapiConfig","Error","knexConfig","pool","afterCreate","userAfterCreate","strapiAfterCreate","conn","done","err","nativeConn","knex"],"mappings":";;;;;;;;AAGA,MAAMA,SAAAA,GAAY;IAChBC,MAAAA,EAAQ,gBAAA;IACRC,KAAAA,EAAO,QAAA;IACPC,QAAAA,EAAU;AACZ,CAAA;AAIO,SAASC,qBAAqBC,MAAe,EAAA;AAClD,IAAA,OAAO,MAACA,IAAqBL,SAAAA;AAC/B;AAEO,MAAMM,gBAAAA,GAAmB,CAACC,UAAAA,EAAyBC,YAAAA,GAAAA;AACxD,IAAA,IAAI,CAACJ,oBAAAA,CAAqBG,UAAAA,CAAWF,MAAM,CAAA,EAAG;AAC5C,QAAA,MAAM,IAAII,KAAAA,CAAM,CAAC,4BAA4B,EAAEF,UAAAA,CAAWF,MAAM,CAAA,CAAE,CAAA;AACpE,IAAA;AAEA,IAAA,MAAMK,UAAAA,GAA0B;AAAE,QAAA,GAAGH,UAAU;AAAEF,QAAAA,MAAAA,EAAQL,SAAS,CAACO,UAAAA,CAAWF,MAAM;AAAE,KAAA;;IAGtF,IAAIG,YAAAA,EAAcG,MAAMC,WAAAA,EAAa;AACnCF,QAAAA,UAAAA,CAAWC,IAAI,GAAGD,UAAAA,CAAWC,IAAI,IAAI,EAAC;;QAEtC,MAAME,eAAAA,GAAkBH,UAAAA,CAAWC,IAAI,EAAEC,WAAAA;AACzC,QAAA,MAAME,iBAAAA,GAAoBN,YAAAA,CAAaG,IAAI,CAACC,WAAW;AACvDF,QAAAA,UAAAA,CAAWC,IAAI,CAACC,WAAW,GAAG,CAC5BG,IAAAA,EACAC,IAAAA,GAAAA;YAEAF,iBAAAA,CAAkBC,IAAAA,EAAM,CAACE,GAAAA,EAA+BC,UAAAA,GAAAA;AACtD,gBAAA,IAAID,GAAAA,EAAK;AACP,oBAAA,OAAOD,KAAKC,GAAAA,EAAKC,UAAAA,CAAAA;AACnB,gBAAA;AACA,gBAAA,IAAIL,eAAAA,EAAiB;AACnB,oBAAA,OAAOA,gBAAgBK,UAAAA,EAAYF,IAAAA,CAAAA;AACrC,gBAAA;AACA,gBAAA,OAAOA,KAAK,IAAA,EAAME,UAAAA,CAAAA;AACpB,YAAA,CAAA,CAAA;AACF,QAAA,CAAA;AACF,IAAA;AAEA,IAAA,OAAOC,qBAAAA,CAAKT,UAAAA,CAAAA;AACd;;;;;"}
|
package/dist/connection.mjs
CHANGED
|
@@ -5,11 +5,11 @@ const clientMap = {
|
|
|
5
5
|
mysql: 'mysql2',
|
|
6
6
|
postgres: 'pg'
|
|
7
7
|
};
|
|
8
|
-
function
|
|
9
|
-
return
|
|
8
|
+
function isDatabaseClientKind(client) {
|
|
9
|
+
return client in clientMap;
|
|
10
10
|
}
|
|
11
11
|
const createConnection = (userConfig, strapiConfig)=>{
|
|
12
|
-
if (!
|
|
12
|
+
if (!isDatabaseClientKind(userConfig.client)) {
|
|
13
13
|
throw new Error(`Unsupported database client ${userConfig.client}`);
|
|
14
14
|
}
|
|
15
15
|
const knexConfig = {
|
|
@@ -37,5 +37,5 @@ const createConnection = (userConfig, strapiConfig)=>{
|
|
|
37
37
|
return knex(knexConfig);
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
export { createConnection };
|
|
40
|
+
export { createConnection, isDatabaseClientKind };
|
|
41
41
|
//# sourceMappingURL=connection.mjs.map
|
package/dist/connection.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.mjs","sources":["../src/connection.ts"],"sourcesContent":["import knex from 'knex';\nimport type { Knex } from 'knex';\n\nconst clientMap = {\n sqlite: 'better-sqlite3',\n mysql: 'mysql2',\n postgres: 'pg',\n};\n\
|
|
1
|
+
{"version":3,"file":"connection.mjs","sources":["../src/connection.ts"],"sourcesContent":["import knex from 'knex';\nimport type { Knex } from 'knex';\n\nconst clientMap = {\n sqlite: 'better-sqlite3',\n mysql: 'mysql2',\n postgres: 'pg',\n};\n\ntype ClientKind = keyof typeof clientMap;\n\nexport function isDatabaseClientKind(client: unknown): client is ClientKind {\n return (client as string) in clientMap;\n}\n\nexport const createConnection = (userConfig: Knex.Config, strapiConfig?: Partial<Knex.Config>) => {\n if (!isDatabaseClientKind(userConfig.client)) {\n throw new Error(`Unsupported database client ${userConfig.client}`);\n }\n\n const knexConfig: Knex.Config = { ...userConfig, client: clientMap[userConfig.client] };\n\n // initialization code to run upon opening a new connection\n if (strapiConfig?.pool?.afterCreate) {\n knexConfig.pool = knexConfig.pool || {};\n // if the user has set their own afterCreate in config, we will replace it and call it\n const userAfterCreate = knexConfig.pool?.afterCreate;\n const strapiAfterCreate = strapiConfig.pool.afterCreate;\n knexConfig.pool.afterCreate = (\n conn: unknown,\n done: (err: Error | null | undefined, connection: any) => void\n ) => {\n strapiAfterCreate(conn, (err: Error | null | undefined, nativeConn: any) => {\n if (err) {\n return done(err, nativeConn);\n }\n if (userAfterCreate) {\n return userAfterCreate(nativeConn, done);\n }\n return done(null, nativeConn);\n });\n };\n }\n\n return knex(knexConfig);\n};\n"],"names":["clientMap","sqlite","mysql","postgres","isDatabaseClientKind","client","createConnection","userConfig","strapiConfig","Error","knexConfig","pool","afterCreate","userAfterCreate","strapiAfterCreate","conn","done","err","nativeConn","knex"],"mappings":";;AAGA,MAAMA,SAAAA,GAAY;IAChBC,MAAAA,EAAQ,gBAAA;IACRC,KAAAA,EAAO,QAAA;IACPC,QAAAA,EAAU;AACZ,CAAA;AAIO,SAASC,qBAAqBC,MAAe,EAAA;AAClD,IAAA,OAAO,MAACA,IAAqBL,SAAAA;AAC/B;AAEO,MAAMM,gBAAAA,GAAmB,CAACC,UAAAA,EAAyBC,YAAAA,GAAAA;AACxD,IAAA,IAAI,CAACJ,oBAAAA,CAAqBG,UAAAA,CAAWF,MAAM,CAAA,EAAG;AAC5C,QAAA,MAAM,IAAII,KAAAA,CAAM,CAAC,4BAA4B,EAAEF,UAAAA,CAAWF,MAAM,CAAA,CAAE,CAAA;AACpE,IAAA;AAEA,IAAA,MAAMK,UAAAA,GAA0B;AAAE,QAAA,GAAGH,UAAU;AAAEF,QAAAA,MAAAA,EAAQL,SAAS,CAACO,UAAAA,CAAWF,MAAM;AAAE,KAAA;;IAGtF,IAAIG,YAAAA,EAAcG,MAAMC,WAAAA,EAAa;AACnCF,QAAAA,UAAAA,CAAWC,IAAI,GAAGD,UAAAA,CAAWC,IAAI,IAAI,EAAC;;QAEtC,MAAME,eAAAA,GAAkBH,UAAAA,CAAWC,IAAI,EAAEC,WAAAA;AACzC,QAAA,MAAME,iBAAAA,GAAoBN,YAAAA,CAAaG,IAAI,CAACC,WAAW;AACvDF,QAAAA,UAAAA,CAAWC,IAAI,CAACC,WAAW,GAAG,CAC5BG,IAAAA,EACAC,IAAAA,GAAAA;YAEAF,iBAAAA,CAAkBC,IAAAA,EAAM,CAACE,GAAAA,EAA+BC,UAAAA,GAAAA;AACtD,gBAAA,IAAID,GAAAA,EAAK;AACP,oBAAA,OAAOD,KAAKC,GAAAA,EAAKC,UAAAA,CAAAA;AACnB,gBAAA;AACA,gBAAA,IAAIL,eAAAA,EAAiB;AACnB,oBAAA,OAAOA,gBAAgBK,UAAAA,EAAYF,IAAAA,CAAAA;AACrC,gBAAA;AACA,gBAAA,OAAOA,KAAK,IAAA,EAAME,UAAAA,CAAAA;AACpB,YAAA,CAAA,CAAA;AACF,QAAA,CAAA;AACF,IAAA;AAEA,IAAA,OAAOC,IAAAA,CAAKT,UAAAA,CAAAA;AACd;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
1
2
|
import Dialect from '../dialect';
|
|
2
3
|
import MysqlSchemaInspector from './schema-inspector';
|
|
3
4
|
import MysqlDatabaseInspector from './database-inspector';
|
|
@@ -8,7 +9,7 @@ export default class MysqlDialect extends Dialect {
|
|
|
8
9
|
databaseInspector: MysqlDatabaseInspector;
|
|
9
10
|
info: Information | null;
|
|
10
11
|
constructor(db: Database);
|
|
11
|
-
configure(): void;
|
|
12
|
+
configure(conn?: Knex.MySqlConnectionConfig): void;
|
|
12
13
|
initialize(nativeConnection: unknown): Promise<void>;
|
|
13
14
|
startSchemaUpdate(): Promise<void>;
|
|
14
15
|
endSchemaUpdate(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialects/mysql/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialects/mysql/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,oBAAoB,MAAM,oBAAoB,CAAC;AACtD,OAAO,sBAAsB,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,OAAO;IAC/C,eAAe,EAAE,oBAAoB,CAAC;IAEtC,iBAAiB,EAAE,sBAAsB,CAAC;IAE1C,IAAI,EAAE,WAAW,GAAG,IAAI,CAAQ;gBAEpB,EAAE,EAAE,QAAQ;IAOxB,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,qBAAqB;IA+BrC,UAAU,CAAC,gBAAgB,EAAE,OAAO;IAoBpC,iBAAiB;IASjB,eAAe;IAIrB,gBAAgB;IAIhB,eAAe;IAIf,eAAe,CAAC,KAAK,EAAE,KAAK;CAG7B"}
|
|
@@ -5,8 +5,8 @@ var schemaInspector = require('./schema-inspector.js');
|
|
|
5
5
|
var databaseInspector = require('./database-inspector.js');
|
|
6
6
|
|
|
7
7
|
class MysqlDialect extends dialect {
|
|
8
|
-
configure() {
|
|
9
|
-
const connection = this.db.config.connection.connection;
|
|
8
|
+
configure(conn) {
|
|
9
|
+
const connection = conn || this.db.config.connection.connection;
|
|
10
10
|
connection.supportBigNumbers = true;
|
|
11
11
|
// Only allow bigNumberStrings option set to be true if no connection option passed
|
|
12
12
|
// Otherwise bigNumberStrings option should be allowed to used from DB config
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/dialects/mysql/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport Dialect from '../dialect';\nimport MysqlSchemaInspector from './schema-inspector';\nimport MysqlDatabaseInspector from './database-inspector';\nimport type { Database } from '../..';\n\nimport type { Information } from './database-inspector';\n\nexport default class MysqlDialect extends Dialect {\n schemaInspector: MysqlSchemaInspector;\n\n databaseInspector: MysqlDatabaseInspector;\n\n info: Information | null = null;\n\n constructor(db: Database) {\n super(db, 'mysql');\n\n this.schemaInspector = new MysqlSchemaInspector(db);\n this.databaseInspector = new MysqlDatabaseInspector(db);\n }\n\n configure() {\n const connection = this.db.config.connection.connection as Knex.MySqlConnectionConfig;\n\n connection.supportBigNumbers = true;\n // Only allow bigNumberStrings option set to be true if no connection option passed\n // Otherwise bigNumberStrings option should be allowed to used from DB config\n if (connection.bigNumberStrings === undefined) {\n connection.bigNumberStrings = true;\n }\n connection.typeCast = (\n field: { type: string; string: () => string; length: number },\n next: () => void\n ) => {\n if (field.type === 'DECIMAL' || field.type === 'NEWDECIMAL') {\n const value = field.string();\n return value === null ? null : Number(value);\n }\n\n if (field.type === 'TINY' && field.length === 1) {\n const value = field.string();\n return value ? value === '1' : null;\n }\n\n if (field.type === 'DATE') {\n return field.string();\n }\n\n return next();\n };\n }\n\n async initialize(nativeConnection: unknown) {\n try {\n await this.db.connection\n .raw(`set session sql_require_primary_key = 0;`)\n .connection(nativeConnection);\n } catch (err) {\n // Ignore error due to lack of session permissions\n }\n\n // We only need to get info on the first connection in the pool\n /**\n * Note: There is a race condition here where if two connections are opened at the same time, both will retrieve\n * db info, but it doesn't cause issues, it's just one wasted query one time, so we can safely leave it to avoid\n * adding extra complexity\n * */\n if (!this.info) {\n this.info = await this.databaseInspector.getInformation(nativeConnection);\n }\n }\n\n async startSchemaUpdate() {\n try {\n await this.db.connection.raw(`set foreign_key_checks = 0;`);\n await this.db.connection.raw(`set session sql_require_primary_key = 0;`);\n } catch (err) {\n // Ignore error due to lack of session permissions\n }\n }\n\n async endSchemaUpdate() {\n await this.db.connection.raw(`set foreign_key_checks = 1;`);\n }\n\n supportsUnsigned() {\n return true;\n }\n\n usesForeignKeys() {\n return true;\n }\n\n transformErrors(error: Error) {\n super.transformErrors(error);\n }\n}\n"],"names":["MysqlDialect","Dialect","configure","connection","db","config","supportBigNumbers","bigNumberStrings","undefined","typeCast","field","next","type","value","string","Number","length","initialize","nativeConnection","raw","err","info","databaseInspector","getInformation","startSchemaUpdate","endSchemaUpdate","supportsUnsigned","usesForeignKeys","transformErrors","error","schemaInspector","MysqlSchemaInspector","MysqlDatabaseInspector"],"mappings":";;;;;;AASe,MAAMA,YAAAA,SAAqBC,OAAAA,CAAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/dialects/mysql/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport Dialect from '../dialect';\nimport MysqlSchemaInspector from './schema-inspector';\nimport MysqlDatabaseInspector from './database-inspector';\nimport type { Database } from '../..';\n\nimport type { Information } from './database-inspector';\n\nexport default class MysqlDialect extends Dialect {\n schemaInspector: MysqlSchemaInspector;\n\n databaseInspector: MysqlDatabaseInspector;\n\n info: Information | null = null;\n\n constructor(db: Database) {\n super(db, 'mysql');\n\n this.schemaInspector = new MysqlSchemaInspector(db);\n this.databaseInspector = new MysqlDatabaseInspector(db);\n }\n\n configure(conn?: Knex.MySqlConnectionConfig) {\n const connection = conn || (this.db.config.connection.connection as Knex.MySqlConnectionConfig);\n\n connection.supportBigNumbers = true;\n // Only allow bigNumberStrings option set to be true if no connection option passed\n // Otherwise bigNumberStrings option should be allowed to used from DB config\n if (connection.bigNumberStrings === undefined) {\n connection.bigNumberStrings = true;\n }\n connection.typeCast = (\n field: { type: string; string: () => string; length: number },\n next: () => void\n ) => {\n if (field.type === 'DECIMAL' || field.type === 'NEWDECIMAL') {\n const value = field.string();\n return value === null ? null : Number(value);\n }\n\n if (field.type === 'TINY' && field.length === 1) {\n const value = field.string();\n return value ? value === '1' : null;\n }\n\n if (field.type === 'DATE') {\n return field.string();\n }\n\n return next();\n };\n }\n\n async initialize(nativeConnection: unknown) {\n try {\n await this.db.connection\n .raw(`set session sql_require_primary_key = 0;`)\n .connection(nativeConnection);\n } catch (err) {\n // Ignore error due to lack of session permissions\n }\n\n // We only need to get info on the first connection in the pool\n /**\n * Note: There is a race condition here where if two connections are opened at the same time, both will retrieve\n * db info, but it doesn't cause issues, it's just one wasted query one time, so we can safely leave it to avoid\n * adding extra complexity\n * */\n if (!this.info) {\n this.info = await this.databaseInspector.getInformation(nativeConnection);\n }\n }\n\n async startSchemaUpdate() {\n try {\n await this.db.connection.raw(`set foreign_key_checks = 0;`);\n await this.db.connection.raw(`set session sql_require_primary_key = 0;`);\n } catch (err) {\n // Ignore error due to lack of session permissions\n }\n }\n\n async endSchemaUpdate() {\n await this.db.connection.raw(`set foreign_key_checks = 1;`);\n }\n\n supportsUnsigned() {\n return true;\n }\n\n usesForeignKeys() {\n return true;\n }\n\n transformErrors(error: Error) {\n super.transformErrors(error);\n }\n}\n"],"names":["MysqlDialect","Dialect","configure","conn","connection","db","config","supportBigNumbers","bigNumberStrings","undefined","typeCast","field","next","type","value","string","Number","length","initialize","nativeConnection","raw","err","info","databaseInspector","getInformation","startSchemaUpdate","endSchemaUpdate","supportsUnsigned","usesForeignKeys","transformErrors","error","schemaInspector","MysqlSchemaInspector","MysqlDatabaseInspector"],"mappings":";;;;;;AASe,MAAMA,YAAAA,SAAqBC,OAAAA,CAAAA;AAcxCC,IAAAA,SAAAA,CAAUC,IAAiC,EAAE;Q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,CAACA,IAAI,GAAG,MAAM,IAAI,CAACC,iBAAiB,CAACC,cAAc,CAACL,gBAAAA,CAAAA;AAC1D,QAAA;AACF,IAAA;AAEA,IAAA,MAAMM,iBAAAA,GAAoB;QACxB,IAAI;YACF,MAAM,IAAI,CAACpB,EAAE,CAACD,UAAU,CAACgB,GAAG,CAAC,CAAC,2BAA2B,CAAC,CAAA;YAC1D,MAAM,IAAI,CAACf,EAAE,CAACD,UAAU,CAACgB,GAAG,CAAC,CAAC,wCAAwC,CAAC,CAAA;AACzE,QAAA,CAAA,CAAE,OAAOC,GAAAA,EAAK;;AAEd,QAAA;AACF,IAAA;AAEA,IAAA,MAAMK,eAAAA,GAAkB;QACtB,MAAM,IAAI,CAACrB,EAAE,CAACD,UAAU,CAACgB,GAAG,CAAC,CAAC,2BAA2B,CAAC,CAAA;AAC5D,IAAA;IAEAO,gBAAAA,GAAmB;QACjB,OAAO,IAAA;AACT,IAAA;IAEAC,eAAAA,GAAkB;QAChB,OAAO,IAAA;AACT,IAAA;AAEAC,IAAAA,eAAAA,CAAgBC,KAAY,EAAE;AAC5B,QAAA,KAAK,CAACD,eAAAA,CAAgBC,KAAAA,CAAAA;AACxB,IAAA;AAjFA,IAAA,WAAA,CAAYzB,EAAY,CAAE;QACxB,KAAK,CAACA,EAAAA,EAAI,OAAA,CAAA,EAAA,IAAA,CAHZiB,IAAAA,GAA2B,IAAA;AAKzB,QAAA,IAAI,CAACS,eAAe,GAAG,IAAIC,eAAAA,CAAqB3B,EAAAA,CAAAA;AAChD,QAAA,IAAI,CAACkB,iBAAiB,GAAG,IAAIU,iBAAAA,CAAuB5B,EAAAA,CAAAA;AACtD,IAAA;AA6EF;;;;"}
|
|
@@ -3,8 +3,8 @@ import MysqlSchemaInspector from './schema-inspector.mjs';
|
|
|
3
3
|
import MysqlDatabaseInspector from './database-inspector.mjs';
|
|
4
4
|
|
|
5
5
|
class MysqlDialect extends Dialect {
|
|
6
|
-
configure() {
|
|
7
|
-
const connection = this.db.config.connection.connection;
|
|
6
|
+
configure(conn) {
|
|
7
|
+
const connection = conn || this.db.config.connection.connection;
|
|
8
8
|
connection.supportBigNumbers = true;
|
|
9
9
|
// Only allow bigNumberStrings option set to be true if no connection option passed
|
|
10
10
|
// Otherwise bigNumberStrings option should be allowed to used from DB config
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/dialects/mysql/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport Dialect from '../dialect';\nimport MysqlSchemaInspector from './schema-inspector';\nimport MysqlDatabaseInspector from './database-inspector';\nimport type { Database } from '../..';\n\nimport type { Information } from './database-inspector';\n\nexport default class MysqlDialect extends Dialect {\n schemaInspector: MysqlSchemaInspector;\n\n databaseInspector: MysqlDatabaseInspector;\n\n info: Information | null = null;\n\n constructor(db: Database) {\n super(db, 'mysql');\n\n this.schemaInspector = new MysqlSchemaInspector(db);\n this.databaseInspector = new MysqlDatabaseInspector(db);\n }\n\n configure() {\n const connection = this.db.config.connection.connection as Knex.MySqlConnectionConfig;\n\n connection.supportBigNumbers = true;\n // Only allow bigNumberStrings option set to be true if no connection option passed\n // Otherwise bigNumberStrings option should be allowed to used from DB config\n if (connection.bigNumberStrings === undefined) {\n connection.bigNumberStrings = true;\n }\n connection.typeCast = (\n field: { type: string; string: () => string; length: number },\n next: () => void\n ) => {\n if (field.type === 'DECIMAL' || field.type === 'NEWDECIMAL') {\n const value = field.string();\n return value === null ? null : Number(value);\n }\n\n if (field.type === 'TINY' && field.length === 1) {\n const value = field.string();\n return value ? value === '1' : null;\n }\n\n if (field.type === 'DATE') {\n return field.string();\n }\n\n return next();\n };\n }\n\n async initialize(nativeConnection: unknown) {\n try {\n await this.db.connection\n .raw(`set session sql_require_primary_key = 0;`)\n .connection(nativeConnection);\n } catch (err) {\n // Ignore error due to lack of session permissions\n }\n\n // We only need to get info on the first connection in the pool\n /**\n * Note: There is a race condition here where if two connections are opened at the same time, both will retrieve\n * db info, but it doesn't cause issues, it's just one wasted query one time, so we can safely leave it to avoid\n * adding extra complexity\n * */\n if (!this.info) {\n this.info = await this.databaseInspector.getInformation(nativeConnection);\n }\n }\n\n async startSchemaUpdate() {\n try {\n await this.db.connection.raw(`set foreign_key_checks = 0;`);\n await this.db.connection.raw(`set session sql_require_primary_key = 0;`);\n } catch (err) {\n // Ignore error due to lack of session permissions\n }\n }\n\n async endSchemaUpdate() {\n await this.db.connection.raw(`set foreign_key_checks = 1;`);\n }\n\n supportsUnsigned() {\n return true;\n }\n\n usesForeignKeys() {\n return true;\n }\n\n transformErrors(error: Error) {\n super.transformErrors(error);\n }\n}\n"],"names":["MysqlDialect","Dialect","configure","connection","db","config","supportBigNumbers","bigNumberStrings","undefined","typeCast","field","next","type","value","string","Number","length","initialize","nativeConnection","raw","err","info","databaseInspector","getInformation","startSchemaUpdate","endSchemaUpdate","supportsUnsigned","usesForeignKeys","transformErrors","error","schemaInspector","MysqlSchemaInspector","MysqlDatabaseInspector"],"mappings":";;;;AASe,MAAMA,YAAAA,SAAqBC,OAAAA,CAAAA;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/dialects/mysql/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport Dialect from '../dialect';\nimport MysqlSchemaInspector from './schema-inspector';\nimport MysqlDatabaseInspector from './database-inspector';\nimport type { Database } from '../..';\n\nimport type { Information } from './database-inspector';\n\nexport default class MysqlDialect extends Dialect {\n schemaInspector: MysqlSchemaInspector;\n\n databaseInspector: MysqlDatabaseInspector;\n\n info: Information | null = null;\n\n constructor(db: Database) {\n super(db, 'mysql');\n\n this.schemaInspector = new MysqlSchemaInspector(db);\n this.databaseInspector = new MysqlDatabaseInspector(db);\n }\n\n configure(conn?: Knex.MySqlConnectionConfig) {\n const connection = conn || (this.db.config.connection.connection as Knex.MySqlConnectionConfig);\n\n connection.supportBigNumbers = true;\n // Only allow bigNumberStrings option set to be true if no connection option passed\n // Otherwise bigNumberStrings option should be allowed to used from DB config\n if (connection.bigNumberStrings === undefined) {\n connection.bigNumberStrings = true;\n }\n connection.typeCast = (\n field: { type: string; string: () => string; length: number },\n next: () => void\n ) => {\n if (field.type === 'DECIMAL' || field.type === 'NEWDECIMAL') {\n const value = field.string();\n return value === null ? null : Number(value);\n }\n\n if (field.type === 'TINY' && field.length === 1) {\n const value = field.string();\n return value ? value === '1' : null;\n }\n\n if (field.type === 'DATE') {\n return field.string();\n }\n\n return next();\n };\n }\n\n async initialize(nativeConnection: unknown) {\n try {\n await this.db.connection\n .raw(`set session sql_require_primary_key = 0;`)\n .connection(nativeConnection);\n } catch (err) {\n // Ignore error due to lack of session permissions\n }\n\n // We only need to get info on the first connection in the pool\n /**\n * Note: There is a race condition here where if two connections are opened at the same time, both will retrieve\n * db info, but it doesn't cause issues, it's just one wasted query one time, so we can safely leave it to avoid\n * adding extra complexity\n * */\n if (!this.info) {\n this.info = await this.databaseInspector.getInformation(nativeConnection);\n }\n }\n\n async startSchemaUpdate() {\n try {\n await this.db.connection.raw(`set foreign_key_checks = 0;`);\n await this.db.connection.raw(`set session sql_require_primary_key = 0;`);\n } catch (err) {\n // Ignore error due to lack of session permissions\n }\n }\n\n async endSchemaUpdate() {\n await this.db.connection.raw(`set foreign_key_checks = 1;`);\n }\n\n supportsUnsigned() {\n return true;\n }\n\n usesForeignKeys() {\n return true;\n }\n\n transformErrors(error: Error) {\n super.transformErrors(error);\n }\n}\n"],"names":["MysqlDialect","Dialect","configure","conn","connection","db","config","supportBigNumbers","bigNumberStrings","undefined","typeCast","field","next","type","value","string","Number","length","initialize","nativeConnection","raw","err","info","databaseInspector","getInformation","startSchemaUpdate","endSchemaUpdate","supportsUnsigned","usesForeignKeys","transformErrors","error","schemaInspector","MysqlSchemaInspector","MysqlDatabaseInspector"],"mappings":";;;;AASe,MAAMA,YAAAA,SAAqBC,OAAAA,CAAAA;AAcxCC,IAAAA,SAAAA,CAAUC,IAAiC,EAAE;QAC3C,MAAMC,UAAAA,GAAaD,IAAAA,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cAAc,SAAS,CAAC;AA4OxB,eAAO,MAAM,mBAAmB,GAAI,IAAI,QAAQ,KAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entity-manager/index.ts"],"names":[],"mappings":"AA8CA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAGnC,OAAO,EAAE,aAAa,EAAsB,MAAM,SAAS,CAAC;AAE5D,cAAc,SAAS,CAAC;AA4OxB,eAAO,MAAM,mBAAmB,GAAI,IAAI,QAAQ,KAAG,aA4+ClD,CAAC"}
|
|
@@ -767,6 +767,12 @@ const createEntityManager = (db)=>{
|
|
|
767
767
|
$in: _.compact(cleanRelationData.connect?.map((r)=>r.position?.after || r.position?.before))
|
|
768
768
|
}
|
|
769
769
|
},
|
|
770
|
+
{
|
|
771
|
+
[joinColumn.name]: id,
|
|
772
|
+
order: this.createQueryBuilder(joinTable.name).min('order').where({
|
|
773
|
+
[joinColumn.name]: id
|
|
774
|
+
}).where(joinTable.on || {}).transacting(trx).getKnexQuery()
|
|
775
|
+
},
|
|
770
776
|
{
|
|
771
777
|
[joinColumn.name]: id,
|
|
772
778
|
order: this.createQueryBuilder(joinTable.name).max('order').where({
|
|
@@ -774,7 +780,7 @@ const createEntityManager = (db)=>{
|
|
|
774
780
|
}).where(joinTable.on || {}).transacting(trx).getKnexQuery()
|
|
775
781
|
}
|
|
776
782
|
]
|
|
777
|
-
}).where(joinTable.on || {}).transacting(trx).execute();
|
|
783
|
+
}).where(joinTable.on || {}).orderBy('order').transacting(trx).execute();
|
|
778
784
|
if (!_.isEmpty(idsToDelete)) {
|
|
779
785
|
const where = {
|
|
780
786
|
$or: idsToDelete.map((item)=>{
|
|
@@ -1061,6 +1067,12 @@ const createEntityManager = (db)=>{
|
|
|
1061
1067
|
$in: _.compact(resolvedConnect.map((r)=>r.position?.after || r.position?.before))
|
|
1062
1068
|
}
|
|
1063
1069
|
},
|
|
1070
|
+
{
|
|
1071
|
+
[joinColumn.name]: id,
|
|
1072
|
+
[orderColumnName]: this.createQueryBuilder(joinTable.name).min(orderColumnName).where({
|
|
1073
|
+
[joinColumn.name]: id
|
|
1074
|
+
}).where(joinTable.on || {}).transacting(trx).getKnexQuery()
|
|
1075
|
+
},
|
|
1064
1076
|
{
|
|
1065
1077
|
[joinColumn.name]: id,
|
|
1066
1078
|
[orderColumnName]: this.createQueryBuilder(joinTable.name).max(orderColumnName).where({
|
|
@@ -1068,7 +1080,7 @@ const createEntityManager = (db)=>{
|
|
|
1068
1080
|
}).where(joinTable.on || {}).transacting(trx).getKnexQuery()
|
|
1069
1081
|
}
|
|
1070
1082
|
]
|
|
1071
|
-
}).where(joinTable.on || {}).transacting(trx).execute();
|
|
1083
|
+
}).where(joinTable.on || {}).orderBy(orderColumnName).transacting(trx).execute();
|
|
1072
1084
|
const orderMap = relationsOrderer.relationsOrderer(adjacentRelations, inverseJoinColumn.name, joinTable.orderColumnName, cleanRelationData.options?.strict).connect(resolvedConnect).getOrderMap();
|
|
1073
1085
|
insert.forEach((row)=>{
|
|
1074
1086
|
row[orderColumnName] = orderMap[row[inverseJoinColumn.name]];
|