Files
pole-book/server/node_modules/@strapi/database/dist/dialects/mysql/index.mjs.map

1 line
5.3 KiB
Plaintext

{"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","constructor","schemaInspector","MysqlSchemaInspector","MysqlDatabaseInspector"],"mappings":";;;;AASe,MAAMA,YAAqBC,SAAAA,OAAAA,CAAAA;IAcxCC,SAAY,GAAA;QACV,MAAMC,UAAAA,GAAa,IAAI,CAACC,EAAE,CAACC,MAAM,CAACF,UAAU,CAACA,UAAU;AAEvDA,QAAAA,UAAAA,CAAWG,iBAAiB,GAAG,IAAA;;;QAG/B,IAAIH,UAAAA,CAAWI,gBAAgB,KAAKC,SAAW,EAAA;AAC7CL,YAAAA,UAAAA,CAAWI,gBAAgB,GAAG,IAAA;AAChC;QACAJ,UAAWM,CAAAA,QAAQ,GAAG,CACpBC,KACAC,EAAAA,IAAAA,GAAAA;AAEA,YAAA,IAAID,MAAME,IAAI,KAAK,aAAaF,KAAME,CAAAA,IAAI,KAAK,YAAc,EAAA;gBAC3D,MAAMC,KAAAA,GAAQH,MAAMI,MAAM,EAAA;gBAC1B,OAAOD,KAAAA,KAAU,IAAO,GAAA,IAAA,GAAOE,MAAOF,CAAAA,KAAAA,CAAAA;AACxC;AAEA,YAAA,IAAIH,MAAME,IAAI,KAAK,UAAUF,KAAMM,CAAAA,MAAM,KAAK,CAAG,EAAA;gBAC/C,MAAMH,KAAAA,GAAQH,MAAMI,MAAM,EAAA;gBAC1B,OAAOD,KAAAA,GAA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