drizzle-orm 1.0.0-beta.1-e4b0766 → 1.0.0-beta.1-2e234ba
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/aws-data-api/pg/driver.cjs +1 -1
- package/aws-data-api/pg/driver.cjs.map +1 -1
- package/aws-data-api/pg/driver.js +1 -1
- package/aws-data-api/pg/driver.js.map +1 -1
- package/mysql-core/columns/decimal.cjs +86 -1
- package/mysql-core/columns/decimal.cjs.map +1 -1
- package/mysql-core/columns/decimal.d.cts +47 -3
- package/mysql-core/columns/decimal.d.ts +47 -3
- package/mysql-core/columns/decimal.js +82 -1
- package/mysql-core/columns/decimal.js.map +1 -1
- package/mysql-core/dialect.cjs +5 -2
- package/mysql-core/dialect.cjs.map +1 -1
- package/mysql-core/dialect.js +5 -2
- package/mysql-core/dialect.js.map +1 -1
- package/mysql2/driver.cjs +2 -1
- package/mysql2/driver.cjs.map +1 -1
- package/mysql2/driver.js +2 -1
- package/mysql2/driver.js.map +1 -1
- package/neon-http/driver.cjs +5 -0
- package/neon-http/driver.cjs.map +1 -1
- package/neon-http/driver.js +5 -0
- package/neon-http/driver.js.map +1 -1
- package/neon-serverless/session.cjs +6 -0
- package/neon-serverless/session.cjs.map +1 -1
- package/neon-serverless/session.js +6 -0
- package/neon-serverless/session.js.map +1 -1
- package/node-postgres/session.cjs +6 -0
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.js +6 -0
- package/node-postgres/session.js.map +1 -1
- package/package.json +25 -25
- package/pg-core/columns/numeric.cjs +86 -1
- package/pg-core/columns/numeric.cjs.map +1 -1
- package/pg-core/columns/numeric.d.cts +61 -6
- package/pg-core/columns/numeric.d.ts +61 -6
- package/pg-core/columns/numeric.js +82 -1
- package/pg-core/columns/numeric.js.map +1 -1
- package/pg-core/dialect.cjs +3 -1
- package/pg-core/dialect.cjs.map +1 -1
- package/pg-core/dialect.js +3 -1
- package/pg-core/dialect.js.map +1 -1
- package/pglite/session.cjs +8 -0
- package/pglite/session.cjs.map +1 -1
- package/pglite/session.js +8 -0
- package/pglite/session.js.map +1 -1
- package/postgres-js/driver.cjs +1 -1
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.js +1 -1
- package/postgres-js/driver.js.map +1 -1
- package/singlestore/driver.cjs +1 -3
- package/singlestore/driver.cjs.map +1 -1
- package/singlestore/driver.js +1 -3
- package/singlestore/driver.js.map +1 -1
- package/singlestore-core/columns/binary.cjs +11 -0
- package/singlestore-core/columns/binary.cjs.map +1 -1
- package/singlestore-core/columns/binary.d.cts +1 -0
- package/singlestore-core/columns/binary.d.ts +1 -0
- package/singlestore-core/columns/binary.js +11 -0
- package/singlestore-core/columns/binary.js.map +1 -1
- package/singlestore-core/columns/decimal.cjs +92 -5
- package/singlestore-core/columns/decimal.cjs.map +1 -1
- package/singlestore-core/columns/decimal.d.cts +50 -3
- package/singlestore-core/columns/decimal.d.ts +50 -3
- package/singlestore-core/columns/decimal.js +88 -5
- package/singlestore-core/columns/decimal.js.map +1 -1
- package/singlestore-core/columns/varbinary.cjs +11 -0
- package/singlestore-core/columns/varbinary.cjs.map +1 -1
- package/singlestore-core/columns/varbinary.d.cts +1 -0
- package/singlestore-core/columns/varbinary.d.ts +1 -0
- package/singlestore-core/columns/varbinary.js +11 -0
- package/singlestore-core/columns/varbinary.js.map +1 -1
- package/singlestore-core/columns/varchar.cjs.map +1 -1
- package/singlestore-core/columns/varchar.d.cts +1 -1
- package/singlestore-core/columns/varchar.d.ts +1 -1
- package/singlestore-core/columns/varchar.js.map +1 -1
- package/singlestore-core/dialect.cjs +2 -2
- package/singlestore-core/dialect.cjs.map +1 -1
- package/singlestore-core/dialect.js +2 -2
- package/singlestore-core/dialect.js.map +1 -1
- package/sqlite-core/columns/blob.cjs +4 -1
- package/sqlite-core/columns/blob.cjs.map +1 -1
- package/sqlite-core/columns/blob.d.cts +1 -1
- package/sqlite-core/columns/blob.d.ts +1 -1
- package/sqlite-core/columns/blob.js +4 -1
- package/sqlite-core/columns/blob.js.map +1 -1
- package/sqlite-core/columns/numeric.cjs +64 -2
- package/sqlite-core/columns/numeric.cjs.map +1 -1
- package/sqlite-core/columns/numeric.d.cts +43 -2
- package/sqlite-core/columns/numeric.d.ts +43 -2
- package/sqlite-core/columns/numeric.js +60 -2
- package/sqlite-core/columns/numeric.js.map +1 -1
- package/sqlite-core/dialect.cjs +20 -5
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.js +20 -5
- package/sqlite-core/dialect.js.map +1 -1
- package/vercel-postgres/session.cjs +6 -0
- package/vercel-postgres/session.cjs.map +1 -1
- package/vercel-postgres/session.js +6 -0
- package/vercel-postgres/session.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/singlestore/driver.ts"],"sourcesContent":["import { type Connection as CallbackConnection, createPool, type Pool as CallbackPool, type PoolOptions } from 'mysql2';\nimport type { Connection, Pool } from 'mysql2/promise';\nimport {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/_relations.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport { SingleStoreDatabase } from '~/singlestore-core/db.ts';\nimport { SingleStoreDialect } from '~/singlestore-core/dialect.ts';\nimport { type DrizzleConfig, type IfNotImported, type ImportTypeError, isConfig } from '~/utils.ts';\nimport type {\n\tSingleStoreDriverClient,\n\tSingleStoreDriverPreparedQueryHKT,\n\tSingleStoreDriverQueryResultHKT,\n} from './session.ts';\nimport { SingleStoreDriverSession } from './session.ts';\n\nexport interface SingleStoreDriverOptions {\n\tlogger?: Logger;\n}\n\nexport class SingleStoreDriverDriver {\n\tstatic readonly [entityKind]: string = 'SingleStoreDriverDriver';\n\n\tconstructor(\n\t\tprivate client: SingleStoreDriverClient,\n\t\tprivate dialect: SingleStoreDialect,\n\t\tprivate options: SingleStoreDriverOptions = {},\n\t) {\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t): SingleStoreDriverSession<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new SingleStoreDriverSession(this.client, this.dialect, schema, { logger: this.options.logger });\n\t}\n}\n\nexport { SingleStoreDatabase } from '~/singlestore-core/db.ts';\n\nexport class SingleStoreDriverDatabase<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends SingleStoreDatabase<SingleStoreDriverQueryResultHKT, SingleStoreDriverPreparedQueryHKT, TSchema> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreDriverDatabase';\n}\n\nexport type SingleStoreDriverDrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> =\n\t& Omit<DrizzleConfig<TSchema>, 'schema'>\n\t& ({ schema: TSchema } | { schema?: undefined });\n\nfunction construct<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends Pool | Connection | CallbackPool | CallbackConnection = CallbackPool,\n>(\n\tclient: TClient,\n\tconfig: SingleStoreDriverDrizzleConfig<TSchema> = {},\n): SingleStoreDriverDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tconst dialect = new SingleStoreDialect({ casing: config.casing });\n\tlet logger;\n\tif (config.logger === true) {\n\t\tlogger = new DefaultLogger();\n\t} else if (config.logger !== false) {\n\t\tlogger = config.logger;\n\t}\n\n\tconst clientForInstance = isCallbackClient(client) ? client.promise() : client;\n\n\tlet schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n\tif (config.schema) {\n\t\tconst tablesConfig = extractTablesRelationalConfig(\n\t\t\tconfig.schema,\n\t\t\tcreateTableRelationsHelpers,\n\t\t);\n\t\tschema = {\n\t\t\tfullSchema: config.schema,\n\t\t\tschema: tablesConfig.tables,\n\t\t\ttableNamesMap: tablesConfig.tableNamesMap,\n\t\t};\n\t}\n\n\tconst driver = new SingleStoreDriverDriver(clientForInstance as SingleStoreDriverClient, dialect, { logger });\n\tconst session = driver.createSession(schema);\n\tconst db = new SingleStoreDriverDatabase(dialect, session, schema as any) as SingleStoreDriverDatabase<TSchema>;\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n\ninterface CallbackClient {\n\tpromise(): SingleStoreDriverClient;\n}\n\nfunction isCallbackClient(client: any): client is CallbackClient {\n\treturn typeof client.promise === 'function';\n}\n\nexport type AnySingleStoreDriverConnection = Pool | Connection | CallbackPool | CallbackConnection;\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends AnySingleStoreDriverConnection = CallbackPool,\n>(\n\t...params: IfNotImported<\n\t\tCallbackPool,\n\t\t[ImportTypeError<'singlestore'>],\n\t\t[\n\t\t\tTClient | string,\n\t\t] | [\n\t\t\tTClient | string,\n\t\t\tSingleStoreDriverDrizzleConfig<TSchema>,\n\t\t] | [\n\t\t\t(\n\t\t\t\t& SingleStoreDriverDrizzleConfig<TSchema>\n\t\t\t\t& ({\n\t\t\t\t\tconnection: string | PoolOptions;\n\t\t\t\t} | {\n\t\t\t\t\tclient: TClient;\n\t\t\t\t})\n\t\t\t),\n\t\t]\n\t>\n): SingleStoreDriverDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tif (typeof params[0] === 'string') {\n\t\tconst connectionString = params[0]!;\n\t\tconst instance = createPool({\n\t\t\turi: connectionString,\n\t\t});\n\n\t\treturn construct(instance, params[1]) as any;\n\t}\n\n\tif (isConfig(params[0])) {\n\t\tconst { connection, client, ...drizzleConfig } = params[0] as\n\t\t\t& { connection?: PoolOptions | string; client?: TClient }\n\t\t\t& SingleStoreDriverDrizzleConfig<TSchema>;\n\n\t\tif (client) return construct(client, drizzleConfig) as any;\n\n\t\tconst instance = typeof connection === 'string'\n\t\t\t? createPool({
|
|
1
|
+
{"version":3,"sources":["../../src/singlestore/driver.ts"],"sourcesContent":["import { type Connection as CallbackConnection, createPool, type Pool as CallbackPool, type PoolOptions } from 'mysql2';\nimport type { Connection, Pool } from 'mysql2/promise';\nimport {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/_relations.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport { SingleStoreDatabase } from '~/singlestore-core/db.ts';\nimport { SingleStoreDialect } from '~/singlestore-core/dialect.ts';\nimport { type DrizzleConfig, type IfNotImported, type ImportTypeError, isConfig } from '~/utils.ts';\nimport type {\n\tSingleStoreDriverClient,\n\tSingleStoreDriverPreparedQueryHKT,\n\tSingleStoreDriverQueryResultHKT,\n} from './session.ts';\nimport { SingleStoreDriverSession } from './session.ts';\n\nexport interface SingleStoreDriverOptions {\n\tlogger?: Logger;\n}\n\nexport class SingleStoreDriverDriver {\n\tstatic readonly [entityKind]: string = 'SingleStoreDriverDriver';\n\n\tconstructor(\n\t\tprivate client: SingleStoreDriverClient,\n\t\tprivate dialect: SingleStoreDialect,\n\t\tprivate options: SingleStoreDriverOptions = {},\n\t) {\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t): SingleStoreDriverSession<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new SingleStoreDriverSession(this.client, this.dialect, schema, { logger: this.options.logger });\n\t}\n}\n\nexport { SingleStoreDatabase } from '~/singlestore-core/db.ts';\n\nexport class SingleStoreDriverDatabase<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends SingleStoreDatabase<SingleStoreDriverQueryResultHKT, SingleStoreDriverPreparedQueryHKT, TSchema> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreDriverDatabase';\n}\n\nexport type SingleStoreDriverDrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> =\n\t& Omit<DrizzleConfig<TSchema>, 'schema'>\n\t& ({ schema: TSchema } | { schema?: undefined });\n\nfunction construct<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends Pool | Connection | CallbackPool | CallbackConnection = CallbackPool,\n>(\n\tclient: TClient,\n\tconfig: SingleStoreDriverDrizzleConfig<TSchema> = {},\n): SingleStoreDriverDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tconst dialect = new SingleStoreDialect({ casing: config.casing });\n\tlet logger;\n\tif (config.logger === true) {\n\t\tlogger = new DefaultLogger();\n\t} else if (config.logger !== false) {\n\t\tlogger = config.logger;\n\t}\n\n\tconst clientForInstance = isCallbackClient(client) ? client.promise() : client;\n\n\tlet schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n\tif (config.schema) {\n\t\tconst tablesConfig = extractTablesRelationalConfig(\n\t\t\tconfig.schema,\n\t\t\tcreateTableRelationsHelpers,\n\t\t);\n\t\tschema = {\n\t\t\tfullSchema: config.schema,\n\t\t\tschema: tablesConfig.tables,\n\t\t\ttableNamesMap: tablesConfig.tableNamesMap,\n\t\t};\n\t}\n\n\tconst driver = new SingleStoreDriverDriver(clientForInstance as SingleStoreDriverClient, dialect, { logger });\n\tconst session = driver.createSession(schema);\n\tconst db = new SingleStoreDriverDatabase(dialect, session, schema as any) as SingleStoreDriverDatabase<TSchema>;\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n\ninterface CallbackClient {\n\tpromise(): SingleStoreDriverClient;\n}\n\nfunction isCallbackClient(client: any): client is CallbackClient {\n\treturn typeof client.promise === 'function';\n}\n\nexport type AnySingleStoreDriverConnection = Pool | Connection | CallbackPool | CallbackConnection;\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends AnySingleStoreDriverConnection = CallbackPool,\n>(\n\t...params: IfNotImported<\n\t\tCallbackPool,\n\t\t[ImportTypeError<'singlestore'>],\n\t\t[\n\t\t\tTClient | string,\n\t\t] | [\n\t\t\tTClient | string,\n\t\t\tSingleStoreDriverDrizzleConfig<TSchema>,\n\t\t] | [\n\t\t\t(\n\t\t\t\t& SingleStoreDriverDrizzleConfig<TSchema>\n\t\t\t\t& ({\n\t\t\t\t\tconnection: string | PoolOptions;\n\t\t\t\t} | {\n\t\t\t\t\tclient: TClient;\n\t\t\t\t})\n\t\t\t),\n\t\t]\n\t>\n): SingleStoreDriverDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tif (typeof params[0] === 'string') {\n\t\tconst connectionString = params[0]!;\n\t\tconst instance = createPool({\n\t\t\turi: connectionString,\n\t\t});\n\n\t\treturn construct(instance, params[1]) as any;\n\t}\n\n\tif (isConfig(params[0])) {\n\t\tconst { connection, client, ...drizzleConfig } = params[0] as\n\t\t\t& { connection?: PoolOptions | string; client?: TClient }\n\t\t\t& SingleStoreDriverDrizzleConfig<TSchema>;\n\n\t\tif (client) return construct(client, drizzleConfig) as any;\n\n\t\tconst instance = typeof connection === 'string'\n\t\t\t? createPool({ uri: connection, supportBigNumbers: true })\n\t\t\t: createPool(connection!);\n\t\tconst db = construct(instance, drizzleConfig);\n\n\t\treturn db as any;\n\t}\n\n\treturn construct(params[0] as TClient, params[1] as SingleStoreDriverDrizzleConfig<TSchema> | undefined) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<TSchema extends Record<string, unknown> = Record<string, never>>(\n\t\tconfig?: SingleStoreDriverDrizzleConfig<TSchema>,\n\t): SingleStoreDriverDatabase<TSchema> & {\n\t\t$client: '$client is not available on drizzle.mock()';\n\t} {\n\t\treturn construct({} as any, config) as any;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+G;AAE/G,uBAKO;AACP,oBAA2B;AAE3B,oBAA8B;AAC9B,gBAAoC;AACpC,qBAAmC;AACnC,mBAAuF;AAMvF,qBAAyC;AAuBzC,IAAAA,aAAoC;AAjB7B,MAAM,wBAAwB;AAAA,EAGpC,YACS,QACA,SACA,UAAoC,CAAC,GAC5C;AAHO;AACA;AACA;AAAA,EAET;AAAA,EAPA,QAAiB,wBAAU,IAAY;AAAA,EASvC,cACC,QAC4E;AAC5E,WAAO,IAAI,wCAAyB,KAAK,QAAQ,KAAK,SAAS,QAAQ,EAAE,QAAQ,KAAK,QAAQ,OAAO,CAAC;AAAA,EACvG;AACD;AAIO,MAAM,kCAEH,8BAAiG;AAAA,EAC1G,QAA0B,wBAAU,IAAY;AACjD;AAMA,SAAS,UAIR,QACA,SAAkD,CAAC,GAGlD;AACD,QAAM,UAAU,IAAI,kCAAmB,EAAE,QAAQ,OAAO,OAAO,CAAC;AAChE,MAAI;AACJ,MAAI,OAAO,WAAW,MAAM;AAC3B,aAAS,IAAI,4BAAc;AAAA,EAC5B,WAAW,OAAO,WAAW,OAAO;AACnC,aAAS,OAAO;AAAA,EACjB;AAEA,QAAM,oBAAoB,iBAAiB,MAAM,IAAI,OAAO,QAAQ,IAAI;AAExE,MAAI;AACJ,MAAI,OAAO,QAAQ;AAClB,UAAM,mBAAe;AAAA,MACpB,OAAO;AAAA,MACP;AAAA,IACD;AACA,aAAS;AAAA,MACR,YAAY,OAAO;AAAA,MACnB,QAAQ,aAAa;AAAA,MACrB,eAAe,aAAa;AAAA,IAC7B;AAAA,EACD;AAEA,QAAM,SAAS,IAAI,wBAAwB,mBAA8C,SAAS,EAAE,OAAO,CAAC;AAC5G,QAAM,UAAU,OAAO,cAAc,MAAM;AAC3C,QAAM,KAAK,IAAI,0BAA0B,SAAS,SAAS,MAAa;AACxE,EAAO,GAAI,UAAU;AAErB,SAAO;AACR;AAMA,SAAS,iBAAiB,QAAuC;AAChE,SAAO,OAAO,OAAO,YAAY;AAClC;AAIO,SAAS,WAIZ,QAqBF;AACD,MAAI,OAAO,OAAO,CAAC,MAAM,UAAU;AAClC,UAAM,mBAAmB,OAAO,CAAC;AACjC,UAAM,eAAW,0BAAW;AAAA,MAC3B,KAAK;AAAA,IACN,CAAC;AAED,WAAO,UAAU,UAAU,OAAO,CAAC,CAAC;AAAA,EACrC;AAEA,UAAI,uBAAS,OAAO,CAAC,CAAC,GAAG;AACxB,UAAM,EAAE,YAAY,QAAQ,GAAG,cAAc,IAAI,OAAO,CAAC;AAIzD,QAAI;AAAQ,aAAO,UAAU,QAAQ,aAAa;AAElD,UAAM,WAAW,OAAO,eAAe,eACpC,0BAAW,EAAE,KAAK,YAAY,mBAAmB,KAAK,CAAC,QACvD,0BAAW,UAAW;AACzB,UAAM,KAAK,UAAU,UAAU,aAAa;AAE5C,WAAO;AAAA,EACR;AAEA,SAAO,UAAU,OAAO,CAAC,GAAc,OAAO,CAAC,CAAwD;AACxG;AAAA,CAEO,CAAUC,aAAV;AACC,WAAS,KACf,QAGC;AACD,WAAO,UAAU,CAAC,GAAU,MAAM;AAAA,EACnC;AANO,EAAAA,SAAS;AAAA,GADA;","names":["import_db","drizzle"]}
|
package/singlestore/driver.js
CHANGED
|
@@ -66,9 +66,7 @@ function drizzle(...params) {
|
|
|
66
66
|
const { connection, client, ...drizzleConfig } = params[0];
|
|
67
67
|
if (client)
|
|
68
68
|
return construct(client, drizzleConfig);
|
|
69
|
-
const instance = typeof connection === "string" ? createPool({
|
|
70
|
-
uri: connection
|
|
71
|
-
}) : createPool(connection);
|
|
69
|
+
const instance = typeof connection === "string" ? createPool({ uri: connection, supportBigNumbers: true }) : createPool(connection);
|
|
72
70
|
const db = construct(instance, drizzleConfig);
|
|
73
71
|
return db;
|
|
74
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/singlestore/driver.ts"],"sourcesContent":["import { type Connection as CallbackConnection, createPool, type Pool as CallbackPool, type PoolOptions } from 'mysql2';\nimport type { Connection, Pool } from 'mysql2/promise';\nimport {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/_relations.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport { SingleStoreDatabase } from '~/singlestore-core/db.ts';\nimport { SingleStoreDialect } from '~/singlestore-core/dialect.ts';\nimport { type DrizzleConfig, type IfNotImported, type ImportTypeError, isConfig } from '~/utils.ts';\nimport type {\n\tSingleStoreDriverClient,\n\tSingleStoreDriverPreparedQueryHKT,\n\tSingleStoreDriverQueryResultHKT,\n} from './session.ts';\nimport { SingleStoreDriverSession } from './session.ts';\n\nexport interface SingleStoreDriverOptions {\n\tlogger?: Logger;\n}\n\nexport class SingleStoreDriverDriver {\n\tstatic readonly [entityKind]: string = 'SingleStoreDriverDriver';\n\n\tconstructor(\n\t\tprivate client: SingleStoreDriverClient,\n\t\tprivate dialect: SingleStoreDialect,\n\t\tprivate options: SingleStoreDriverOptions = {},\n\t) {\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t): SingleStoreDriverSession<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new SingleStoreDriverSession(this.client, this.dialect, schema, { logger: this.options.logger });\n\t}\n}\n\nexport { SingleStoreDatabase } from '~/singlestore-core/db.ts';\n\nexport class SingleStoreDriverDatabase<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends SingleStoreDatabase<SingleStoreDriverQueryResultHKT, SingleStoreDriverPreparedQueryHKT, TSchema> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreDriverDatabase';\n}\n\nexport type SingleStoreDriverDrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> =\n\t& Omit<DrizzleConfig<TSchema>, 'schema'>\n\t& ({ schema: TSchema } | { schema?: undefined });\n\nfunction construct<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends Pool | Connection | CallbackPool | CallbackConnection = CallbackPool,\n>(\n\tclient: TClient,\n\tconfig: SingleStoreDriverDrizzleConfig<TSchema> = {},\n): SingleStoreDriverDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tconst dialect = new SingleStoreDialect({ casing: config.casing });\n\tlet logger;\n\tif (config.logger === true) {\n\t\tlogger = new DefaultLogger();\n\t} else if (config.logger !== false) {\n\t\tlogger = config.logger;\n\t}\n\n\tconst clientForInstance = isCallbackClient(client) ? client.promise() : client;\n\n\tlet schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n\tif (config.schema) {\n\t\tconst tablesConfig = extractTablesRelationalConfig(\n\t\t\tconfig.schema,\n\t\t\tcreateTableRelationsHelpers,\n\t\t);\n\t\tschema = {\n\t\t\tfullSchema: config.schema,\n\t\t\tschema: tablesConfig.tables,\n\t\t\ttableNamesMap: tablesConfig.tableNamesMap,\n\t\t};\n\t}\n\n\tconst driver = new SingleStoreDriverDriver(clientForInstance as SingleStoreDriverClient, dialect, { logger });\n\tconst session = driver.createSession(schema);\n\tconst db = new SingleStoreDriverDatabase(dialect, session, schema as any) as SingleStoreDriverDatabase<TSchema>;\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n\ninterface CallbackClient {\n\tpromise(): SingleStoreDriverClient;\n}\n\nfunction isCallbackClient(client: any): client is CallbackClient {\n\treturn typeof client.promise === 'function';\n}\n\nexport type AnySingleStoreDriverConnection = Pool | Connection | CallbackPool | CallbackConnection;\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends AnySingleStoreDriverConnection = CallbackPool,\n>(\n\t...params: IfNotImported<\n\t\tCallbackPool,\n\t\t[ImportTypeError<'singlestore'>],\n\t\t[\n\t\t\tTClient | string,\n\t\t] | [\n\t\t\tTClient | string,\n\t\t\tSingleStoreDriverDrizzleConfig<TSchema>,\n\t\t] | [\n\t\t\t(\n\t\t\t\t& SingleStoreDriverDrizzleConfig<TSchema>\n\t\t\t\t& ({\n\t\t\t\t\tconnection: string | PoolOptions;\n\t\t\t\t} | {\n\t\t\t\t\tclient: TClient;\n\t\t\t\t})\n\t\t\t),\n\t\t]\n\t>\n): SingleStoreDriverDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tif (typeof params[0] === 'string') {\n\t\tconst connectionString = params[0]!;\n\t\tconst instance = createPool({\n\t\t\turi: connectionString,\n\t\t});\n\n\t\treturn construct(instance, params[1]) as any;\n\t}\n\n\tif (isConfig(params[0])) {\n\t\tconst { connection, client, ...drizzleConfig } = params[0] as\n\t\t\t& { connection?: PoolOptions | string; client?: TClient }\n\t\t\t& SingleStoreDriverDrizzleConfig<TSchema>;\n\n\t\tif (client) return construct(client, drizzleConfig) as any;\n\n\t\tconst instance = typeof connection === 'string'\n\t\t\t? createPool({
|
|
1
|
+
{"version":3,"sources":["../../src/singlestore/driver.ts"],"sourcesContent":["import { type Connection as CallbackConnection, createPool, type Pool as CallbackPool, type PoolOptions } from 'mysql2';\nimport type { Connection, Pool } from 'mysql2/promise';\nimport {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/_relations.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport { SingleStoreDatabase } from '~/singlestore-core/db.ts';\nimport { SingleStoreDialect } from '~/singlestore-core/dialect.ts';\nimport { type DrizzleConfig, type IfNotImported, type ImportTypeError, isConfig } from '~/utils.ts';\nimport type {\n\tSingleStoreDriverClient,\n\tSingleStoreDriverPreparedQueryHKT,\n\tSingleStoreDriverQueryResultHKT,\n} from './session.ts';\nimport { SingleStoreDriverSession } from './session.ts';\n\nexport interface SingleStoreDriverOptions {\n\tlogger?: Logger;\n}\n\nexport class SingleStoreDriverDriver {\n\tstatic readonly [entityKind]: string = 'SingleStoreDriverDriver';\n\n\tconstructor(\n\t\tprivate client: SingleStoreDriverClient,\n\t\tprivate dialect: SingleStoreDialect,\n\t\tprivate options: SingleStoreDriverOptions = {},\n\t) {\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t): SingleStoreDriverSession<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new SingleStoreDriverSession(this.client, this.dialect, schema, { logger: this.options.logger });\n\t}\n}\n\nexport { SingleStoreDatabase } from '~/singlestore-core/db.ts';\n\nexport class SingleStoreDriverDatabase<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends SingleStoreDatabase<SingleStoreDriverQueryResultHKT, SingleStoreDriverPreparedQueryHKT, TSchema> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreDriverDatabase';\n}\n\nexport type SingleStoreDriverDrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> =\n\t& Omit<DrizzleConfig<TSchema>, 'schema'>\n\t& ({ schema: TSchema } | { schema?: undefined });\n\nfunction construct<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends Pool | Connection | CallbackPool | CallbackConnection = CallbackPool,\n>(\n\tclient: TClient,\n\tconfig: SingleStoreDriverDrizzleConfig<TSchema> = {},\n): SingleStoreDriverDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tconst dialect = new SingleStoreDialect({ casing: config.casing });\n\tlet logger;\n\tif (config.logger === true) {\n\t\tlogger = new DefaultLogger();\n\t} else if (config.logger !== false) {\n\t\tlogger = config.logger;\n\t}\n\n\tconst clientForInstance = isCallbackClient(client) ? client.promise() : client;\n\n\tlet schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n\tif (config.schema) {\n\t\tconst tablesConfig = extractTablesRelationalConfig(\n\t\t\tconfig.schema,\n\t\t\tcreateTableRelationsHelpers,\n\t\t);\n\t\tschema = {\n\t\t\tfullSchema: config.schema,\n\t\t\tschema: tablesConfig.tables,\n\t\t\ttableNamesMap: tablesConfig.tableNamesMap,\n\t\t};\n\t}\n\n\tconst driver = new SingleStoreDriverDriver(clientForInstance as SingleStoreDriverClient, dialect, { logger });\n\tconst session = driver.createSession(schema);\n\tconst db = new SingleStoreDriverDatabase(dialect, session, schema as any) as SingleStoreDriverDatabase<TSchema>;\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n\ninterface CallbackClient {\n\tpromise(): SingleStoreDriverClient;\n}\n\nfunction isCallbackClient(client: any): client is CallbackClient {\n\treturn typeof client.promise === 'function';\n}\n\nexport type AnySingleStoreDriverConnection = Pool | Connection | CallbackPool | CallbackConnection;\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends AnySingleStoreDriverConnection = CallbackPool,\n>(\n\t...params: IfNotImported<\n\t\tCallbackPool,\n\t\t[ImportTypeError<'singlestore'>],\n\t\t[\n\t\t\tTClient | string,\n\t\t] | [\n\t\t\tTClient | string,\n\t\t\tSingleStoreDriverDrizzleConfig<TSchema>,\n\t\t] | [\n\t\t\t(\n\t\t\t\t& SingleStoreDriverDrizzleConfig<TSchema>\n\t\t\t\t& ({\n\t\t\t\t\tconnection: string | PoolOptions;\n\t\t\t\t} | {\n\t\t\t\t\tclient: TClient;\n\t\t\t\t})\n\t\t\t),\n\t\t]\n\t>\n): SingleStoreDriverDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tif (typeof params[0] === 'string') {\n\t\tconst connectionString = params[0]!;\n\t\tconst instance = createPool({\n\t\t\turi: connectionString,\n\t\t});\n\n\t\treturn construct(instance, params[1]) as any;\n\t}\n\n\tif (isConfig(params[0])) {\n\t\tconst { connection, client, ...drizzleConfig } = params[0] as\n\t\t\t& { connection?: PoolOptions | string; client?: TClient }\n\t\t\t& SingleStoreDriverDrizzleConfig<TSchema>;\n\n\t\tif (client) return construct(client, drizzleConfig) as any;\n\n\t\tconst instance = typeof connection === 'string'\n\t\t\t? createPool({ uri: connection, supportBigNumbers: true })\n\t\t\t: createPool(connection!);\n\t\tconst db = construct(instance, drizzleConfig);\n\n\t\treturn db as any;\n\t}\n\n\treturn construct(params[0] as TClient, params[1] as SingleStoreDriverDrizzleConfig<TSchema> | undefined) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<TSchema extends Record<string, unknown> = Record<string, never>>(\n\t\tconfig?: SingleStoreDriverDrizzleConfig<TSchema>,\n\t): SingleStoreDriverDatabase<TSchema> & {\n\t\t$client: '$client is not available on drizzle.mock()';\n\t} {\n\t\treturn construct({} as any, config) as any;\n\t}\n}\n"],"mappings":"AAAA,SAAgD,kBAA+D;AAE/G;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP,SAAS,kBAAkB;AAE3B,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAuE,gBAAgB;AAMvF,SAAS,gCAAgC;AAMlC,MAAM,wBAAwB;AAAA,EAGpC,YACS,QACA,SACA,UAAoC,CAAC,GAC5C;AAHO;AACA;AACA;AAAA,EAET;AAAA,EAPA,QAAiB,UAAU,IAAY;AAAA,EASvC,cACC,QAC4E;AAC5E,WAAO,IAAI,yBAAyB,KAAK,QAAQ,KAAK,SAAS,QAAQ,EAAE,QAAQ,KAAK,QAAQ,OAAO,CAAC;AAAA,EACvG;AACD;AAEA,SAAS,uBAAAA,4BAA2B;AAE7B,MAAM,kCAEH,oBAAiG;AAAA,EAC1G,QAA0B,UAAU,IAAY;AACjD;AAMA,SAAS,UAIR,QACA,SAAkD,CAAC,GAGlD;AACD,QAAM,UAAU,IAAI,mBAAmB,EAAE,QAAQ,OAAO,OAAO,CAAC;AAChE,MAAI;AACJ,MAAI,OAAO,WAAW,MAAM;AAC3B,aAAS,IAAI,cAAc;AAAA,EAC5B,WAAW,OAAO,WAAW,OAAO;AACnC,aAAS,OAAO;AAAA,EACjB;AAEA,QAAM,oBAAoB,iBAAiB,MAAM,IAAI,OAAO,QAAQ,IAAI;AAExE,MAAI;AACJ,MAAI,OAAO,QAAQ;AAClB,UAAM,eAAe;AAAA,MACpB,OAAO;AAAA,MACP;AAAA,IACD;AACA,aAAS;AAAA,MACR,YAAY,OAAO;AAAA,MACnB,QAAQ,aAAa;AAAA,MACrB,eAAe,aAAa;AAAA,IAC7B;AAAA,EACD;AAEA,QAAM,SAAS,IAAI,wBAAwB,mBAA8C,SAAS,EAAE,OAAO,CAAC;AAC5G,QAAM,UAAU,OAAO,cAAc,MAAM;AAC3C,QAAM,KAAK,IAAI,0BAA0B,SAAS,SAAS,MAAa;AACxE,EAAO,GAAI,UAAU;AAErB,SAAO;AACR;AAMA,SAAS,iBAAiB,QAAuC;AAChE,SAAO,OAAO,OAAO,YAAY;AAClC;AAIO,SAAS,WAIZ,QAqBF;AACD,MAAI,OAAO,OAAO,CAAC,MAAM,UAAU;AAClC,UAAM,mBAAmB,OAAO,CAAC;AACjC,UAAM,WAAW,WAAW;AAAA,MAC3B,KAAK;AAAA,IACN,CAAC;AAED,WAAO,UAAU,UAAU,OAAO,CAAC,CAAC;AAAA,EACrC;AAEA,MAAI,SAAS,OAAO,CAAC,CAAC,GAAG;AACxB,UAAM,EAAE,YAAY,QAAQ,GAAG,cAAc,IAAI,OAAO,CAAC;AAIzD,QAAI;AAAQ,aAAO,UAAU,QAAQ,aAAa;AAElD,UAAM,WAAW,OAAO,eAAe,WACpC,WAAW,EAAE,KAAK,YAAY,mBAAmB,KAAK,CAAC,IACvD,WAAW,UAAW;AACzB,UAAM,KAAK,UAAU,UAAU,aAAa;AAE5C,WAAO;AAAA,EACR;AAEA,SAAO,UAAU,OAAO,CAAC,GAAc,OAAO,CAAC,CAAwD;AACxG;AAAA,CAEO,CAAUC,aAAV;AACC,WAAS,KACf,QAGC;AACD,WAAO,UAAU,CAAC,GAAU,MAAM;AAAA,EACnC;AANO,EAAAA,SAAS;AAAA,GADA;","names":["SingleStoreDatabase","drizzle"]}
|
|
@@ -43,6 +43,17 @@ class SingleStoreBinaryBuilder extends import_common.SingleStoreColumnBuilder {
|
|
|
43
43
|
class SingleStoreBinary extends import_common.SingleStoreColumn {
|
|
44
44
|
static [import_entity.entityKind] = "SingleStoreBinary";
|
|
45
45
|
length = this.config.length;
|
|
46
|
+
mapFromDriverValue(value) {
|
|
47
|
+
if (typeof value === "string")
|
|
48
|
+
return value;
|
|
49
|
+
if (Buffer.isBuffer(value))
|
|
50
|
+
return value.toString();
|
|
51
|
+
const str = [];
|
|
52
|
+
for (const v of value) {
|
|
53
|
+
str.push(v === 49 ? "1" : "0");
|
|
54
|
+
}
|
|
55
|
+
return str.join("");
|
|
56
|
+
}
|
|
46
57
|
getSQLType() {
|
|
47
58
|
return this.length === void 0 ? `binary` : `binary(${this.length})`;
|
|
48
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/singlestore-core/columns/binary.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnySingleStoreTable } from '~/singlestore-core/table.ts';\nimport { getColumnNameAndConfig } from '~/utils.ts';\nimport { SingleStoreColumn, SingleStoreColumnBuilder } from './common.ts';\n\nexport type SingleStoreBinaryBuilderInitial<TName extends string> = SingleStoreBinaryBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'SingleStoreBinary';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n\tgenerated: undefined;\n}>;\n\nexport class SingleStoreBinaryBuilder<T extends ColumnBuilderBaseConfig<'string', 'SingleStoreBinary'>>\n\textends SingleStoreColumnBuilder<\n\t\tT,\n\t\tSingleStoreBinaryConfig\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'SingleStoreBinaryBuilder';\n\n\tconstructor(name: T['name'], length: number | undefined) {\n\t\tsuper(name, 'string', 'SingleStoreBinary');\n\t\tthis.config.length = length;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySingleStoreTable<{ name: TTableName }>,\n\t): SingleStoreBinary<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SingleStoreBinary<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SingleStoreBinary<T extends ColumnBaseConfig<'string', 'SingleStoreBinary'>> extends SingleStoreColumn<\n\tT,\n\tSingleStoreBinaryConfig\n> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreBinary';\n\n\tlength: number | undefined = this.config.length;\n\n\tgetSQLType(): string {\n\t\treturn this.length === undefined ? `binary` : `binary(${this.length})`;\n\t}\n}\n\nexport interface SingleStoreBinaryConfig {\n\tlength?: number;\n}\n\nexport function binary(): SingleStoreBinaryBuilderInitial<''>;\nexport function binary(\n\tconfig?: SingleStoreBinaryConfig,\n): SingleStoreBinaryBuilderInitial<''>;\nexport function binary<TName extends string>(\n\tname: TName,\n\tconfig?: SingleStoreBinaryConfig,\n): SingleStoreBinaryBuilderInitial<TName>;\nexport function binary(a?: string | SingleStoreBinaryConfig, b: SingleStoreBinaryConfig = {}) {\n\tconst { name, config } = getColumnNameAndConfig<SingleStoreBinaryConfig>(a, b);\n\treturn new SingleStoreBinaryBuilder(name, config.length);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAE3B,mBAAuC;AACvC,oBAA4D;AAYrD,MAAM,iCACJ,uCAIT;AAAA,EACC,QAA0B,wBAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,QAA4B;AACxD,UAAM,MAAM,UAAU,mBAAmB;AACzC,SAAK,OAAO,SAAS;AAAA,EACtB;AAAA;AAAA,EAGS,MACR,OACqD;AACrD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,0BAAqF,gCAGhG;AAAA,EACD,QAA0B,wBAAU,IAAY;AAAA,EAEhD,SAA6B,KAAK,OAAO;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../src/singlestore-core/columns/binary.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnySingleStoreTable } from '~/singlestore-core/table.ts';\nimport { getColumnNameAndConfig } from '~/utils.ts';\nimport { SingleStoreColumn, SingleStoreColumnBuilder } from './common.ts';\n\nexport type SingleStoreBinaryBuilderInitial<TName extends string> = SingleStoreBinaryBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'SingleStoreBinary';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n\tgenerated: undefined;\n}>;\n\nexport class SingleStoreBinaryBuilder<T extends ColumnBuilderBaseConfig<'string', 'SingleStoreBinary'>>\n\textends SingleStoreColumnBuilder<\n\t\tT,\n\t\tSingleStoreBinaryConfig\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'SingleStoreBinaryBuilder';\n\n\tconstructor(name: T['name'], length: number | undefined) {\n\t\tsuper(name, 'string', 'SingleStoreBinary');\n\t\tthis.config.length = length;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySingleStoreTable<{ name: TTableName }>,\n\t): SingleStoreBinary<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SingleStoreBinary<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SingleStoreBinary<T extends ColumnBaseConfig<'string', 'SingleStoreBinary'>> extends SingleStoreColumn<\n\tT,\n\tSingleStoreBinaryConfig\n> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreBinary';\n\n\tlength: number | undefined = this.config.length;\n\n\toverride mapFromDriverValue(value: string | Buffer | Uint8Array): string {\n\t\tif (typeof value === 'string') return value;\n\t\tif (Buffer.isBuffer(value)) return value.toString();\n\n\t\tconst str: string[] = [];\n\t\tfor (const v of value) {\n\t\t\tstr.push(v === 49 ? '1' : '0');\n\t\t}\n\n\t\treturn str.join('');\n\t}\n\n\tgetSQLType(): string {\n\t\treturn this.length === undefined ? `binary` : `binary(${this.length})`;\n\t}\n}\n\nexport interface SingleStoreBinaryConfig {\n\tlength?: number;\n}\n\nexport function binary(): SingleStoreBinaryBuilderInitial<''>;\nexport function binary(\n\tconfig?: SingleStoreBinaryConfig,\n): SingleStoreBinaryBuilderInitial<''>;\nexport function binary<TName extends string>(\n\tname: TName,\n\tconfig?: SingleStoreBinaryConfig,\n): SingleStoreBinaryBuilderInitial<TName>;\nexport function binary(a?: string | SingleStoreBinaryConfig, b: SingleStoreBinaryConfig = {}) {\n\tconst { name, config } = getColumnNameAndConfig<SingleStoreBinaryConfig>(a, b);\n\treturn new SingleStoreBinaryBuilder(name, config.length);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAE3B,mBAAuC;AACvC,oBAA4D;AAYrD,MAAM,iCACJ,uCAIT;AAAA,EACC,QAA0B,wBAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,QAA4B;AACxD,UAAM,MAAM,UAAU,mBAAmB;AACzC,SAAK,OAAO,SAAS;AAAA,EACtB;AAAA;AAAA,EAGS,MACR,OACqD;AACrD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,0BAAqF,gCAGhG;AAAA,EACD,QAA0B,wBAAU,IAAY;AAAA,EAEhD,SAA6B,KAAK,OAAO;AAAA,EAEhC,mBAAmB,OAA6C;AACxE,QAAI,OAAO,UAAU;AAAU,aAAO;AACtC,QAAI,OAAO,SAAS,KAAK;AAAG,aAAO,MAAM,SAAS;AAElD,UAAM,MAAgB,CAAC;AACvB,eAAW,KAAK,OAAO;AACtB,UAAI,KAAK,MAAM,KAAK,MAAM,GAAG;AAAA,IAC9B;AAEA,WAAO,IAAI,KAAK,EAAE;AAAA,EACnB;AAAA,EAEA,aAAqB;AACpB,WAAO,KAAK,WAAW,SAAY,WAAW,UAAU,KAAK,MAAM;AAAA,EACpE;AACD;AAcO,SAAS,OAAO,GAAsC,IAA6B,CAAC,GAAG;AAC7F,QAAM,EAAE,MAAM,OAAO,QAAI,qCAAgD,GAAG,CAAC;AAC7E,SAAO,IAAI,yBAAyB,MAAM,OAAO,MAAM;AACxD;","names":[]}
|
|
@@ -18,6 +18,7 @@ export declare class SingleStoreBinaryBuilder<T extends ColumnBuilderBaseConfig<
|
|
|
18
18
|
export declare class SingleStoreBinary<T extends ColumnBaseConfig<'string', 'SingleStoreBinary'>> extends SingleStoreColumn<T, SingleStoreBinaryConfig> {
|
|
19
19
|
static readonly [entityKind]: string;
|
|
20
20
|
length: number | undefined;
|
|
21
|
+
mapFromDriverValue(value: string | Buffer | Uint8Array): string;
|
|
21
22
|
getSQLType(): string;
|
|
22
23
|
}
|
|
23
24
|
export interface SingleStoreBinaryConfig {
|
|
@@ -18,6 +18,7 @@ export declare class SingleStoreBinaryBuilder<T extends ColumnBuilderBaseConfig<
|
|
|
18
18
|
export declare class SingleStoreBinary<T extends ColumnBaseConfig<'string', 'SingleStoreBinary'>> extends SingleStoreColumn<T, SingleStoreBinaryConfig> {
|
|
19
19
|
static readonly [entityKind]: string;
|
|
20
20
|
length: number | undefined;
|
|
21
|
+
mapFromDriverValue(value: string | Buffer | Uint8Array): string;
|
|
21
22
|
getSQLType(): string;
|
|
22
23
|
}
|
|
23
24
|
export interface SingleStoreBinaryConfig {
|
|
@@ -18,6 +18,17 @@ class SingleStoreBinaryBuilder extends SingleStoreColumnBuilder {
|
|
|
18
18
|
class SingleStoreBinary extends SingleStoreColumn {
|
|
19
19
|
static [entityKind] = "SingleStoreBinary";
|
|
20
20
|
length = this.config.length;
|
|
21
|
+
mapFromDriverValue(value) {
|
|
22
|
+
if (typeof value === "string")
|
|
23
|
+
return value;
|
|
24
|
+
if (Buffer.isBuffer(value))
|
|
25
|
+
return value.toString();
|
|
26
|
+
const str = [];
|
|
27
|
+
for (const v of value) {
|
|
28
|
+
str.push(v === 49 ? "1" : "0");
|
|
29
|
+
}
|
|
30
|
+
return str.join("");
|
|
31
|
+
}
|
|
21
32
|
getSQLType() {
|
|
22
33
|
return this.length === void 0 ? `binary` : `binary(${this.length})`;
|
|
23
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/singlestore-core/columns/binary.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnySingleStoreTable } from '~/singlestore-core/table.ts';\nimport { getColumnNameAndConfig } from '~/utils.ts';\nimport { SingleStoreColumn, SingleStoreColumnBuilder } from './common.ts';\n\nexport type SingleStoreBinaryBuilderInitial<TName extends string> = SingleStoreBinaryBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'SingleStoreBinary';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n\tgenerated: undefined;\n}>;\n\nexport class SingleStoreBinaryBuilder<T extends ColumnBuilderBaseConfig<'string', 'SingleStoreBinary'>>\n\textends SingleStoreColumnBuilder<\n\t\tT,\n\t\tSingleStoreBinaryConfig\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'SingleStoreBinaryBuilder';\n\n\tconstructor(name: T['name'], length: number | undefined) {\n\t\tsuper(name, 'string', 'SingleStoreBinary');\n\t\tthis.config.length = length;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySingleStoreTable<{ name: TTableName }>,\n\t): SingleStoreBinary<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SingleStoreBinary<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SingleStoreBinary<T extends ColumnBaseConfig<'string', 'SingleStoreBinary'>> extends SingleStoreColumn<\n\tT,\n\tSingleStoreBinaryConfig\n> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreBinary';\n\n\tlength: number | undefined = this.config.length;\n\n\tgetSQLType(): string {\n\t\treturn this.length === undefined ? `binary` : `binary(${this.length})`;\n\t}\n}\n\nexport interface SingleStoreBinaryConfig {\n\tlength?: number;\n}\n\nexport function binary(): SingleStoreBinaryBuilderInitial<''>;\nexport function binary(\n\tconfig?: SingleStoreBinaryConfig,\n): SingleStoreBinaryBuilderInitial<''>;\nexport function binary<TName extends string>(\n\tname: TName,\n\tconfig?: SingleStoreBinaryConfig,\n): SingleStoreBinaryBuilderInitial<TName>;\nexport function binary(a?: string | SingleStoreBinaryConfig, b: SingleStoreBinaryConfig = {}) {\n\tconst { name, config } = getColumnNameAndConfig<SingleStoreBinaryConfig>(a, b);\n\treturn new SingleStoreBinaryBuilder(name, config.length);\n}\n"],"mappings":"AAEA,SAAS,kBAAkB;AAE3B,SAAS,8BAA8B;AACvC,SAAS,mBAAmB,gCAAgC;AAYrD,MAAM,iCACJ,yBAIT;AAAA,EACC,QAA0B,UAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,QAA4B;AACxD,UAAM,MAAM,UAAU,mBAAmB;AACzC,SAAK,OAAO,SAAS;AAAA,EACtB;AAAA;AAAA,EAGS,MACR,OACqD;AACrD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,0BAAqF,kBAGhG;AAAA,EACD,QAA0B,UAAU,IAAY;AAAA,EAEhD,SAA6B,KAAK,OAAO;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../src/singlestore-core/columns/binary.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnySingleStoreTable } from '~/singlestore-core/table.ts';\nimport { getColumnNameAndConfig } from '~/utils.ts';\nimport { SingleStoreColumn, SingleStoreColumnBuilder } from './common.ts';\n\nexport type SingleStoreBinaryBuilderInitial<TName extends string> = SingleStoreBinaryBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'SingleStoreBinary';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n\tgenerated: undefined;\n}>;\n\nexport class SingleStoreBinaryBuilder<T extends ColumnBuilderBaseConfig<'string', 'SingleStoreBinary'>>\n\textends SingleStoreColumnBuilder<\n\t\tT,\n\t\tSingleStoreBinaryConfig\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'SingleStoreBinaryBuilder';\n\n\tconstructor(name: T['name'], length: number | undefined) {\n\t\tsuper(name, 'string', 'SingleStoreBinary');\n\t\tthis.config.length = length;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySingleStoreTable<{ name: TTableName }>,\n\t): SingleStoreBinary<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SingleStoreBinary<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SingleStoreBinary<T extends ColumnBaseConfig<'string', 'SingleStoreBinary'>> extends SingleStoreColumn<\n\tT,\n\tSingleStoreBinaryConfig\n> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreBinary';\n\n\tlength: number | undefined = this.config.length;\n\n\toverride mapFromDriverValue(value: string | Buffer | Uint8Array): string {\n\t\tif (typeof value === 'string') return value;\n\t\tif (Buffer.isBuffer(value)) return value.toString();\n\n\t\tconst str: string[] = [];\n\t\tfor (const v of value) {\n\t\t\tstr.push(v === 49 ? '1' : '0');\n\t\t}\n\n\t\treturn str.join('');\n\t}\n\n\tgetSQLType(): string {\n\t\treturn this.length === undefined ? `binary` : `binary(${this.length})`;\n\t}\n}\n\nexport interface SingleStoreBinaryConfig {\n\tlength?: number;\n}\n\nexport function binary(): SingleStoreBinaryBuilderInitial<''>;\nexport function binary(\n\tconfig?: SingleStoreBinaryConfig,\n): SingleStoreBinaryBuilderInitial<''>;\nexport function binary<TName extends string>(\n\tname: TName,\n\tconfig?: SingleStoreBinaryConfig,\n): SingleStoreBinaryBuilderInitial<TName>;\nexport function binary(a?: string | SingleStoreBinaryConfig, b: SingleStoreBinaryConfig = {}) {\n\tconst { name, config } = getColumnNameAndConfig<SingleStoreBinaryConfig>(a, b);\n\treturn new SingleStoreBinaryBuilder(name, config.length);\n}\n"],"mappings":"AAEA,SAAS,kBAAkB;AAE3B,SAAS,8BAA8B;AACvC,SAAS,mBAAmB,gCAAgC;AAYrD,MAAM,iCACJ,yBAIT;AAAA,EACC,QAA0B,UAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,QAA4B;AACxD,UAAM,MAAM,UAAU,mBAAmB;AACzC,SAAK,OAAO,SAAS;AAAA,EACtB;AAAA;AAAA,EAGS,MACR,OACqD;AACrD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,0BAAqF,kBAGhG;AAAA,EACD,QAA0B,UAAU,IAAY;AAAA,EAEhD,SAA6B,KAAK,OAAO;AAAA,EAEhC,mBAAmB,OAA6C;AACxE,QAAI,OAAO,UAAU;AAAU,aAAO;AACtC,QAAI,OAAO,SAAS,KAAK;AAAG,aAAO,MAAM,SAAS;AAElD,UAAM,MAAgB,CAAC;AACvB,eAAW,KAAK,OAAO;AACtB,UAAI,KAAK,MAAM,KAAK,MAAM,GAAG;AAAA,IAC9B;AAEA,WAAO,IAAI,KAAK,EAAE;AAAA,EACnB;AAAA,EAEA,aAAqB;AACpB,WAAO,KAAK,WAAW,SAAY,WAAW,UAAU,KAAK,MAAM;AAAA,EACpE;AACD;AAcO,SAAS,OAAO,GAAsC,IAA6B,CAAC,GAAG;AAC7F,QAAM,EAAE,MAAM,OAAO,IAAI,uBAAgD,GAAG,CAAC;AAC7E,SAAO,IAAI,yBAAyB,MAAM,OAAO,MAAM;AACxD;","names":[]}
|
|
@@ -19,7 +19,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var decimal_exports = {};
|
|
20
20
|
__export(decimal_exports, {
|
|
21
21
|
SingleStoreDecimal: () => SingleStoreDecimal,
|
|
22
|
+
SingleStoreDecimalBigInt: () => SingleStoreDecimalBigInt,
|
|
23
|
+
SingleStoreDecimalBigIntBuilder: () => SingleStoreDecimalBigIntBuilder,
|
|
22
24
|
SingleStoreDecimalBuilder: () => SingleStoreDecimalBuilder,
|
|
25
|
+
SingleStoreDecimalNumber: () => SingleStoreDecimalNumber,
|
|
26
|
+
SingleStoreDecimalNumberBuilder: () => SingleStoreDecimalNumberBuilder,
|
|
23
27
|
decimal: () => decimal
|
|
24
28
|
});
|
|
25
29
|
module.exports = __toCommonJS(decimal_exports);
|
|
@@ -47,6 +51,87 @@ class SingleStoreDecimal extends import_common.SingleStoreColumnWithAutoIncremen
|
|
|
47
51
|
precision = this.config.precision;
|
|
48
52
|
scale = this.config.scale;
|
|
49
53
|
unsigned = this.config.unsigned;
|
|
54
|
+
mapFromDriverValue(value) {
|
|
55
|
+
if (typeof value === "string")
|
|
56
|
+
return value;
|
|
57
|
+
return String(value);
|
|
58
|
+
}
|
|
59
|
+
getSQLType() {
|
|
60
|
+
let type = "";
|
|
61
|
+
if (this.precision !== void 0 && this.scale !== void 0) {
|
|
62
|
+
type += `decimal(${this.precision},${this.scale})`;
|
|
63
|
+
} else if (this.precision === void 0) {
|
|
64
|
+
type += "decimal";
|
|
65
|
+
} else {
|
|
66
|
+
type += `decimal(${this.precision})`;
|
|
67
|
+
}
|
|
68
|
+
type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
|
|
69
|
+
return this.unsigned ? `${type} unsigned` : type;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class SingleStoreDecimalNumberBuilder extends import_common.SingleStoreColumnBuilderWithAutoIncrement {
|
|
73
|
+
static [import_entity.entityKind] = "SingleStoreDecimalNumberBuilder";
|
|
74
|
+
constructor(name, config) {
|
|
75
|
+
super(name, "number", "SingleStoreDecimalNumber");
|
|
76
|
+
this.config.precision = config?.precision;
|
|
77
|
+
this.config.scale = config?.scale;
|
|
78
|
+
this.config.unsigned = config?.unsigned;
|
|
79
|
+
}
|
|
80
|
+
/** @internal */
|
|
81
|
+
build(table) {
|
|
82
|
+
return new SingleStoreDecimalNumber(
|
|
83
|
+
table,
|
|
84
|
+
this.config
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
class SingleStoreDecimalNumber extends import_common.SingleStoreColumnWithAutoIncrement {
|
|
89
|
+
static [import_entity.entityKind] = "SingleStoreDecimalNumber";
|
|
90
|
+
precision = this.config.precision;
|
|
91
|
+
scale = this.config.scale;
|
|
92
|
+
unsigned = this.config.unsigned;
|
|
93
|
+
mapFromDriverValue(value) {
|
|
94
|
+
if (typeof value === "number")
|
|
95
|
+
return value;
|
|
96
|
+
return Number(value);
|
|
97
|
+
}
|
|
98
|
+
mapToDriverValue = String;
|
|
99
|
+
getSQLType() {
|
|
100
|
+
let type = "";
|
|
101
|
+
if (this.precision !== void 0 && this.scale !== void 0) {
|
|
102
|
+
type += `decimal(${this.precision},${this.scale})`;
|
|
103
|
+
} else if (this.precision === void 0) {
|
|
104
|
+
type += "decimal";
|
|
105
|
+
} else {
|
|
106
|
+
type += `decimal(${this.precision})`;
|
|
107
|
+
}
|
|
108
|
+
type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
|
|
109
|
+
return this.unsigned ? `${type} unsigned` : type;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
class SingleStoreDecimalBigIntBuilder extends import_common.SingleStoreColumnBuilderWithAutoIncrement {
|
|
113
|
+
static [import_entity.entityKind] = "SingleStoreDecimalBigIntBuilder";
|
|
114
|
+
constructor(name, config) {
|
|
115
|
+
super(name, "bigint", "SingleStoreDecimalBigInt");
|
|
116
|
+
this.config.precision = config?.precision;
|
|
117
|
+
this.config.scale = config?.scale;
|
|
118
|
+
this.config.unsigned = config?.unsigned;
|
|
119
|
+
}
|
|
120
|
+
/** @internal */
|
|
121
|
+
build(table) {
|
|
122
|
+
return new SingleStoreDecimalBigInt(
|
|
123
|
+
table,
|
|
124
|
+
this.config
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
class SingleStoreDecimalBigInt extends import_common.SingleStoreColumnWithAutoIncrement {
|
|
129
|
+
static [import_entity.entityKind] = "SingleStoreDecimalBigInt";
|
|
130
|
+
precision = this.config.precision;
|
|
131
|
+
scale = this.config.scale;
|
|
132
|
+
unsigned = this.config.unsigned;
|
|
133
|
+
mapFromDriverValue = BigInt;
|
|
134
|
+
mapToDriverValue = String;
|
|
50
135
|
getSQLType() {
|
|
51
136
|
let type = "";
|
|
52
137
|
if (this.precision !== void 0 && this.scale !== void 0) {
|
|
@@ -61,16 +146,18 @@ class SingleStoreDecimal extends import_common.SingleStoreColumnWithAutoIncremen
|
|
|
61
146
|
}
|
|
62
147
|
}
|
|
63
148
|
function decimal(a, b = {}) {
|
|
64
|
-
const { name, config } = (0, import_utils.getColumnNameAndConfig)(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
68
|
-
return new SingleStoreDecimalBuilder(name, config);
|
|
149
|
+
const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
|
|
150
|
+
const mode = config?.mode;
|
|
151
|
+
return mode === "number" ? new SingleStoreDecimalNumberBuilder(name, config) : mode === "bigint" ? new SingleStoreDecimalBigIntBuilder(name, config) : new SingleStoreDecimalBuilder(name, config);
|
|
69
152
|
}
|
|
70
153
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
154
|
0 && (module.exports = {
|
|
72
155
|
SingleStoreDecimal,
|
|
156
|
+
SingleStoreDecimalBigInt,
|
|
157
|
+
SingleStoreDecimalBigIntBuilder,
|
|
73
158
|
SingleStoreDecimalBuilder,
|
|
159
|
+
SingleStoreDecimalNumber,
|
|
160
|
+
SingleStoreDecimalNumberBuilder,
|
|
74
161
|
decimal
|
|
75
162
|
});
|
|
76
163
|
//# sourceMappingURL=decimal.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/singlestore-core/columns/decimal.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnySingleStoreTable } from '~/singlestore-core/table.ts';\nimport { getColumnNameAndConfig } from '~/utils.ts';\nimport { SingleStoreColumnBuilderWithAutoIncrement, SingleStoreColumnWithAutoIncrement } from './common.ts';\n\nexport type SingleStoreDecimalBuilderInitial<TName extends string> = SingleStoreDecimalBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'SingleStoreDecimal';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n\tgenerated: undefined;\n}>;\n\nexport class SingleStoreDecimalBuilder<\n\tT extends ColumnBuilderBaseConfig<'string', 'SingleStoreDecimal'>,\n> extends SingleStoreColumnBuilderWithAutoIncrement<\n\tT,\n\tSingleStoreDecimalConfig\n> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreDecimalBuilder';\n\n\tconstructor(name: T['name'], config: SingleStoreDecimalConfig | undefined) {\n\t\tsuper(name, 'string', 'SingleStoreDecimal');\n\t\tthis.config.precision = config?.precision;\n\t\tthis.config.scale = config?.scale;\n\t\tthis.config.unsigned = config?.unsigned;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySingleStoreTable<{ name: TTableName }>,\n\t): SingleStoreDecimal<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SingleStoreDecimal<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SingleStoreDecimal<\n\tT extends ColumnBaseConfig<'string', 'SingleStoreDecimal'>,\n> extends SingleStoreColumnWithAutoIncrement<T, SingleStoreDecimalConfig> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreDecimal';\n\n\treadonly precision: number | undefined = this.config.precision;\n\treadonly scale: number | undefined = this.config.scale;\n\treadonly unsigned: boolean | undefined = this.config.unsigned;\n\n\tgetSQLType(): string {\n\t\tlet type = '';\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\ttype += `decimal(${this.precision},${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\ttype += 'decimal';\n\t\t} else {\n\t\t\ttype += `decimal(${this.precision})`;\n\t\t}\n\t\ttype = type === 'decimal(10,0)' || type === 'decimal(10)' ? 'decimal' : type;\n\t\treturn this.unsigned ? `${type} unsigned` : type;\n\t}\n}\n\nexport interface SingleStoreDecimalConfig {\n\tprecision?: number;\n\tscale?: number;\n\tunsigned?: boolean;\n}\n\nexport function decimal(): SingleStoreDecimalBuilderInitial<''>;\nexport function decimal(\n\tconfig: SingleStoreDecimalConfig,\n): SingleStoreDecimalBuilderInitial<''>;\nexport function decimal<TName extends string>(\n\tname: TName,\n\tconfig?: SingleStoreDecimalConfig,\n): SingleStoreDecimalBuilderInitial<TName>;\nexport function decimal(\n\ta?: string | SingleStoreDecimalConfig,\n\tb: SingleStoreDecimalConfig = {},\n) {\n\tconst { name, config } = getColumnNameAndConfig<SingleStoreDecimalConfig>(\n\t\ta,\n\t\tb,\n\t);\n\treturn new SingleStoreDecimalBuilder(name, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAE3B,mBAAuC;AACvC,oBAA8F;AAYvF,MAAM,kCAEH,wDAGR;AAAA,EACD,QAA0B,wBAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,QAA8C;AAC1E,UAAM,MAAM,UAAU,oBAAoB;AAC1C,SAAK,OAAO,YAAY,QAAQ;AAChC,SAAK,OAAO,QAAQ,QAAQ;AAC5B,SAAK,OAAO,WAAW,QAAQ;AAAA,EAChC;AAAA;AAAA,EAGS,MACR,OACsD;AACtD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,2BAEH,iDAAgE;AAAA,EACzE,QAA0B,wBAAU,IAAY;AAAA,EAEvC,YAAgC,KAAK,OAAO;AAAA,EAC5C,QAA4B,KAAK,OAAO;AAAA,EACxC,WAAgC,KAAK,OAAO;AAAA,EAErD,aAAqB;AACpB,QAAI,OAAO;AACX,QAAI,KAAK,cAAc,UAAa,KAAK,UAAU,QAAW;AAC7D,cAAQ,WAAW,KAAK,SAAS,IAAI,KAAK,KAAK;AAAA,IAChD,WAAW,KAAK,cAAc,QAAW;AACxC,cAAQ;AAAA,IACT,OAAO;AACN,cAAQ,WAAW,KAAK,SAAS;AAAA,IAClC;AACA,WAAO,SAAS,mBAAmB,SAAS,gBAAgB,YAAY;AACxE,WAAO,KAAK,WAAW,GAAG,IAAI,cAAc;AAAA,EAC7C;AACD;AAgBO,SAAS,QACf,GACA,IAA8B,CAAC,GAC9B;AACD,QAAM,EAAE,MAAM,OAAO,QAAI;AAAA,IACxB;AAAA,IACA;AAAA,EACD;AACA,SAAO,IAAI,0BAA0B,MAAM,MAAM;AAClD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/singlestore-core/columns/decimal.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnySingleStoreTable } from '~/singlestore-core/table.ts';\nimport { type Equal, getColumnNameAndConfig } from '~/utils.ts';\nimport { SingleStoreColumnBuilderWithAutoIncrement, SingleStoreColumnWithAutoIncrement } from './common.ts';\n\nexport type SingleStoreDecimalBuilderInitial<TName extends string> = SingleStoreDecimalBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'SingleStoreDecimal';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n\tgenerated: undefined;\n}>;\n\nexport class SingleStoreDecimalBuilder<\n\tT extends ColumnBuilderBaseConfig<'string', 'SingleStoreDecimal'>,\n> extends SingleStoreColumnBuilderWithAutoIncrement<T, SingleStoreDecimalConfig> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreDecimalBuilder';\n\n\tconstructor(name: T['name'], config: SingleStoreDecimalConfig | undefined) {\n\t\tsuper(name, 'string', 'SingleStoreDecimal');\n\t\tthis.config.precision = config?.precision;\n\t\tthis.config.scale = config?.scale;\n\t\tthis.config.unsigned = config?.unsigned;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySingleStoreTable<{ name: TTableName }>,\n\t): SingleStoreDecimal<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SingleStoreDecimal<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SingleStoreDecimal<T extends ColumnBaseConfig<'string', 'SingleStoreDecimal'>>\n\textends SingleStoreColumnWithAutoIncrement<T, SingleStoreDecimalConfig>\n{\n\tstatic override readonly [entityKind]: string = 'SingleStoreDecimal';\n\n\treadonly precision: number | undefined = this.config.precision;\n\treadonly scale: number | undefined = this.config.scale;\n\treadonly unsigned: boolean | undefined = this.config.unsigned;\n\n\toverride mapFromDriverValue(value: unknown): string {\n\t\t// For RQBv2\n\t\tif (typeof value === 'string') return value;\n\n\t\treturn String(value);\n\t}\n\n\tgetSQLType(): string {\n\t\tlet type = '';\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\ttype += `decimal(${this.precision},${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\ttype += 'decimal';\n\t\t} else {\n\t\t\ttype += `decimal(${this.precision})`;\n\t\t}\n\t\ttype = type === 'decimal(10,0)' || type === 'decimal(10)' ? 'decimal' : type;\n\t\treturn this.unsigned ? `${type} unsigned` : type;\n\t}\n}\n\nexport type SingleStoreDecimalNumberBuilderInitial<TName extends string> = SingleStoreDecimalNumberBuilder<{\n\tname: TName;\n\tdataType: 'number';\n\tcolumnType: 'SingleStoreDecimalNumber';\n\tdata: number;\n\tdriverParam: string;\n\tenumValues: undefined;\n\tgenerated: undefined;\n}>;\n\nexport class SingleStoreDecimalNumberBuilder<\n\tT extends ColumnBuilderBaseConfig<'number', 'SingleStoreDecimalNumber'>,\n> extends SingleStoreColumnBuilderWithAutoIncrement<T, SingleStoreDecimalConfig> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreDecimalNumberBuilder';\n\n\tconstructor(name: T['name'], config: SingleStoreDecimalConfig | undefined) {\n\t\tsuper(name, 'number', 'SingleStoreDecimalNumber');\n\t\tthis.config.precision = config?.precision;\n\t\tthis.config.scale = config?.scale;\n\t\tthis.config.unsigned = config?.unsigned;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySingleStoreTable<{ name: TTableName }>,\n\t): SingleStoreDecimalNumber<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SingleStoreDecimalNumber<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SingleStoreDecimalNumber<T extends ColumnBaseConfig<'number', 'SingleStoreDecimalNumber'>>\n\textends SingleStoreColumnWithAutoIncrement<T, SingleStoreDecimalConfig>\n{\n\tstatic override readonly [entityKind]: string = 'SingleStoreDecimalNumber';\n\n\treadonly precision: number | undefined = this.config.precision;\n\treadonly scale: number | undefined = this.config.scale;\n\treadonly unsigned: boolean | undefined = this.config.unsigned;\n\n\toverride mapFromDriverValue(value: unknown): number {\n\t\tif (typeof value === 'number') return value;\n\n\t\treturn Number(value);\n\t}\n\n\toverride mapToDriverValue = String;\n\n\tgetSQLType(): string {\n\t\tlet type = '';\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\ttype += `decimal(${this.precision},${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\ttype += 'decimal';\n\t\t} else {\n\t\t\ttype += `decimal(${this.precision})`;\n\t\t}\n\t\ttype = type === 'decimal(10,0)' || type === 'decimal(10)' ? 'decimal' : type;\n\t\treturn this.unsigned ? `${type} unsigned` : type;\n\t}\n}\n\nexport type SingleStoreDecimalBigIntBuilderInitial<TName extends string> = SingleStoreDecimalBigIntBuilder<{\n\tname: TName;\n\tdataType: 'bigint';\n\tcolumnType: 'SingleStoreDecimalBigInt';\n\tdata: bigint;\n\tdriverParam: string;\n\tenumValues: undefined;\n\tgenerated: undefined;\n}>;\n\nexport class SingleStoreDecimalBigIntBuilder<\n\tT extends ColumnBuilderBaseConfig<'bigint', 'SingleStoreDecimalBigInt'>,\n> extends SingleStoreColumnBuilderWithAutoIncrement<T, SingleStoreDecimalConfig> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreDecimalBigIntBuilder';\n\n\tconstructor(name: T['name'], config: SingleStoreDecimalConfig | undefined) {\n\t\tsuper(name, 'bigint', 'SingleStoreDecimalBigInt');\n\t\tthis.config.precision = config?.precision;\n\t\tthis.config.scale = config?.scale;\n\t\tthis.config.unsigned = config?.unsigned;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySingleStoreTable<{ name: TTableName }>,\n\t): SingleStoreDecimalBigInt<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SingleStoreDecimalBigInt<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SingleStoreDecimalBigInt<T extends ColumnBaseConfig<'bigint', 'SingleStoreDecimalBigInt'>>\n\textends SingleStoreColumnWithAutoIncrement<T, SingleStoreDecimalConfig>\n{\n\tstatic override readonly [entityKind]: string = 'SingleStoreDecimalBigInt';\n\n\treadonly precision: number | undefined = this.config.precision;\n\treadonly scale: number | undefined = this.config.scale;\n\treadonly unsigned: boolean | undefined = this.config.unsigned;\n\n\toverride mapFromDriverValue = BigInt;\n\n\toverride mapToDriverValue = String;\n\n\tgetSQLType(): string {\n\t\tlet type = '';\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\ttype += `decimal(${this.precision},${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\ttype += 'decimal';\n\t\t} else {\n\t\t\ttype += `decimal(${this.precision})`;\n\t\t}\n\t\ttype = type === 'decimal(10,0)' || type === 'decimal(10)' ? 'decimal' : type;\n\t\treturn this.unsigned ? `${type} unsigned` : type;\n\t}\n}\n\nexport interface SingleStoreDecimalConfig<T extends 'string' | 'number' | 'bigint' = 'string' | 'number' | 'bigint'> {\n\tprecision?: number;\n\tscale?: number;\n\tunsigned?: boolean;\n\tmode?: T;\n}\n\nexport function decimal(): SingleStoreDecimalBuilderInitial<''>;\nexport function decimal<TMode extends 'string' | 'number' | 'bigint'>(\n\tconfig: SingleStoreDecimalConfig<TMode>,\n): Equal<TMode, 'number'> extends true ? SingleStoreDecimalNumberBuilderInitial<''>\n\t: Equal<TMode, 'bigint'> extends true ? SingleStoreDecimalBigIntBuilderInitial<''>\n\t: SingleStoreDecimalBuilderInitial<''>;\nexport function decimal<TName extends string, TMode extends 'string' | 'number' | 'bigint'>(\n\tname: TName,\n\tconfig?: SingleStoreDecimalConfig<TMode>,\n): Equal<TMode, 'number'> extends true ? SingleStoreDecimalNumberBuilderInitial<TName>\n\t: Equal<TMode, 'bigint'> extends true ? SingleStoreDecimalBigIntBuilderInitial<TName>\n\t: SingleStoreDecimalBuilderInitial<TName>;\nexport function decimal(a?: string | SingleStoreDecimalConfig, b: SingleStoreDecimalConfig = {}) {\n\tconst { name, config } = getColumnNameAndConfig<SingleStoreDecimalConfig>(a, b);\n\tconst mode = config?.mode;\n\treturn mode === 'number'\n\t\t? new SingleStoreDecimalNumberBuilder(name, config)\n\t\t: mode === 'bigint'\n\t\t? new SingleStoreDecimalBigIntBuilder(name, config)\n\t\t: new SingleStoreDecimalBuilder(name, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAE3B,mBAAmD;AACnD,oBAA8F;AAYvF,MAAM,kCAEH,wDAAuE;AAAA,EAChF,QAA0B,wBAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,QAA8C;AAC1E,UAAM,MAAM,UAAU,oBAAoB;AAC1C,SAAK,OAAO,YAAY,QAAQ;AAChC,SAAK,OAAO,QAAQ,QAAQ;AAC5B,SAAK,OAAO,WAAW,QAAQ;AAAA,EAChC;AAAA;AAAA,EAGS,MACR,OACsD;AACtD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,2BACJ,iDACT;AAAA,EACC,QAA0B,wBAAU,IAAY;AAAA,EAEvC,YAAgC,KAAK,OAAO;AAAA,EAC5C,QAA4B,KAAK,OAAO;AAAA,EACxC,WAAgC,KAAK,OAAO;AAAA,EAE5C,mBAAmB,OAAwB;AAEnD,QAAI,OAAO,UAAU;AAAU,aAAO;AAEtC,WAAO,OAAO,KAAK;AAAA,EACpB;AAAA,EAEA,aAAqB;AACpB,QAAI,OAAO;AACX,QAAI,KAAK,cAAc,UAAa,KAAK,UAAU,QAAW;AAC7D,cAAQ,WAAW,KAAK,SAAS,IAAI,KAAK,KAAK;AAAA,IAChD,WAAW,KAAK,cAAc,QAAW;AACxC,cAAQ;AAAA,IACT,OAAO;AACN,cAAQ,WAAW,KAAK,SAAS;AAAA,IAClC;AACA,WAAO,SAAS,mBAAmB,SAAS,gBAAgB,YAAY;AACxE,WAAO,KAAK,WAAW,GAAG,IAAI,cAAc;AAAA,EAC7C;AACD;AAYO,MAAM,wCAEH,wDAAuE;AAAA,EAChF,QAA0B,wBAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,QAA8C;AAC1E,UAAM,MAAM,UAAU,0BAA0B;AAChD,SAAK,OAAO,YAAY,QAAQ;AAChC,SAAK,OAAO,QAAQ,QAAQ;AAC5B,SAAK,OAAO,WAAW,QAAQ;AAAA,EAChC;AAAA;AAAA,EAGS,MACR,OAC4D;AAC5D,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,iCACJ,iDACT;AAAA,EACC,QAA0B,wBAAU,IAAY;AAAA,EAEvC,YAAgC,KAAK,OAAO;AAAA,EAC5C,QAA4B,KAAK,OAAO;AAAA,EACxC,WAAgC,KAAK,OAAO;AAAA,EAE5C,mBAAmB,OAAwB;AACnD,QAAI,OAAO,UAAU;AAAU,aAAO;AAEtC,WAAO,OAAO,KAAK;AAAA,EACpB;AAAA,EAES,mBAAmB;AAAA,EAE5B,aAAqB;AACpB,QAAI,OAAO;AACX,QAAI,KAAK,cAAc,UAAa,KAAK,UAAU,QAAW;AAC7D,cAAQ,WAAW,KAAK,SAAS,IAAI,KAAK,KAAK;AAAA,IAChD,WAAW,KAAK,cAAc,QAAW;AACxC,cAAQ;AAAA,IACT,OAAO;AACN,cAAQ,WAAW,KAAK,SAAS;AAAA,IAClC;AACA,WAAO,SAAS,mBAAmB,SAAS,gBAAgB,YAAY;AACxE,WAAO,KAAK,WAAW,GAAG,IAAI,cAAc;AAAA,EAC7C;AACD;AAYO,MAAM,wCAEH,wDAAuE;AAAA,EAChF,QAA0B,wBAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,QAA8C;AAC1E,UAAM,MAAM,UAAU,0BAA0B;AAChD,SAAK,OAAO,YAAY,QAAQ;AAChC,SAAK,OAAO,QAAQ,QAAQ;AAC5B,SAAK,OAAO,WAAW,QAAQ;AAAA,EAChC;AAAA;AAAA,EAGS,MACR,OAC4D;AAC5D,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,iCACJ,iDACT;AAAA,EACC,QAA0B,wBAAU,IAAY;AAAA,EAEvC,YAAgC,KAAK,OAAO;AAAA,EAC5C,QAA4B,KAAK,OAAO;AAAA,EACxC,WAAgC,KAAK,OAAO;AAAA,EAE5C,qBAAqB;AAAA,EAErB,mBAAmB;AAAA,EAE5B,aAAqB;AACpB,QAAI,OAAO;AACX,QAAI,KAAK,cAAc,UAAa,KAAK,UAAU,QAAW;AAC7D,cAAQ,WAAW,KAAK,SAAS,IAAI,KAAK,KAAK;AAAA,IAChD,WAAW,KAAK,cAAc,QAAW;AACxC,cAAQ;AAAA,IACT,OAAO;AACN,cAAQ,WAAW,KAAK,SAAS;AAAA,IAClC;AACA,WAAO,SAAS,mBAAmB,SAAS,gBAAgB,YAAY;AACxE,WAAO,KAAK,WAAW,GAAG,IAAI,cAAc;AAAA,EAC7C;AACD;AAqBO,SAAS,QAAQ,GAAuC,IAA8B,CAAC,GAAG;AAChG,QAAM,EAAE,MAAM,OAAO,QAAI,qCAAiD,GAAG,CAAC;AAC9E,QAAM,OAAO,QAAQ;AACrB,SAAO,SAAS,WACb,IAAI,gCAAgC,MAAM,MAAM,IAChD,SAAS,WACT,IAAI,gCAAgC,MAAM,MAAM,IAChD,IAAI,0BAA0B,MAAM,MAAM;AAC9C;","names":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ColumnBuilderBaseConfig } from "../../column-builder.cjs";
|
|
2
2
|
import type { ColumnBaseConfig } from "../../column.cjs";
|
|
3
3
|
import { entityKind } from "../../entity.cjs";
|
|
4
|
+
import { type Equal } from "../../utils.cjs";
|
|
4
5
|
import { SingleStoreColumnBuilderWithAutoIncrement, SingleStoreColumnWithAutoIncrement } from "./common.cjs";
|
|
5
6
|
export type SingleStoreDecimalBuilderInitial<TName extends string> = SingleStoreDecimalBuilder<{
|
|
6
7
|
name: TName;
|
|
@@ -20,13 +21,59 @@ export declare class SingleStoreDecimal<T extends ColumnBaseConfig<'string', 'Si
|
|
|
20
21
|
readonly precision: number | undefined;
|
|
21
22
|
readonly scale: number | undefined;
|
|
22
23
|
readonly unsigned: boolean | undefined;
|
|
24
|
+
mapFromDriverValue(value: unknown): string;
|
|
23
25
|
getSQLType(): string;
|
|
24
26
|
}
|
|
25
|
-
export
|
|
27
|
+
export type SingleStoreDecimalNumberBuilderInitial<TName extends string> = SingleStoreDecimalNumberBuilder<{
|
|
28
|
+
name: TName;
|
|
29
|
+
dataType: 'number';
|
|
30
|
+
columnType: 'SingleStoreDecimalNumber';
|
|
31
|
+
data: number;
|
|
32
|
+
driverParam: string;
|
|
33
|
+
enumValues: undefined;
|
|
34
|
+
generated: undefined;
|
|
35
|
+
}>;
|
|
36
|
+
export declare class SingleStoreDecimalNumberBuilder<T extends ColumnBuilderBaseConfig<'number', 'SingleStoreDecimalNumber'>> extends SingleStoreColumnBuilderWithAutoIncrement<T, SingleStoreDecimalConfig> {
|
|
37
|
+
static readonly [entityKind]: string;
|
|
38
|
+
constructor(name: T['name'], config: SingleStoreDecimalConfig | undefined);
|
|
39
|
+
}
|
|
40
|
+
export declare class SingleStoreDecimalNumber<T extends ColumnBaseConfig<'number', 'SingleStoreDecimalNumber'>> extends SingleStoreColumnWithAutoIncrement<T, SingleStoreDecimalConfig> {
|
|
41
|
+
static readonly [entityKind]: string;
|
|
42
|
+
readonly precision: number | undefined;
|
|
43
|
+
readonly scale: number | undefined;
|
|
44
|
+
readonly unsigned: boolean | undefined;
|
|
45
|
+
mapFromDriverValue(value: unknown): number;
|
|
46
|
+
mapToDriverValue: StringConstructor;
|
|
47
|
+
getSQLType(): string;
|
|
48
|
+
}
|
|
49
|
+
export type SingleStoreDecimalBigIntBuilderInitial<TName extends string> = SingleStoreDecimalBigIntBuilder<{
|
|
50
|
+
name: TName;
|
|
51
|
+
dataType: 'bigint';
|
|
52
|
+
columnType: 'SingleStoreDecimalBigInt';
|
|
53
|
+
data: bigint;
|
|
54
|
+
driverParam: string;
|
|
55
|
+
enumValues: undefined;
|
|
56
|
+
generated: undefined;
|
|
57
|
+
}>;
|
|
58
|
+
export declare class SingleStoreDecimalBigIntBuilder<T extends ColumnBuilderBaseConfig<'bigint', 'SingleStoreDecimalBigInt'>> extends SingleStoreColumnBuilderWithAutoIncrement<T, SingleStoreDecimalConfig> {
|
|
59
|
+
static readonly [entityKind]: string;
|
|
60
|
+
constructor(name: T['name'], config: SingleStoreDecimalConfig | undefined);
|
|
61
|
+
}
|
|
62
|
+
export declare class SingleStoreDecimalBigInt<T extends ColumnBaseConfig<'bigint', 'SingleStoreDecimalBigInt'>> extends SingleStoreColumnWithAutoIncrement<T, SingleStoreDecimalConfig> {
|
|
63
|
+
static readonly [entityKind]: string;
|
|
64
|
+
readonly precision: number | undefined;
|
|
65
|
+
readonly scale: number | undefined;
|
|
66
|
+
readonly unsigned: boolean | undefined;
|
|
67
|
+
mapFromDriverValue: BigIntConstructor;
|
|
68
|
+
mapToDriverValue: StringConstructor;
|
|
69
|
+
getSQLType(): string;
|
|
70
|
+
}
|
|
71
|
+
export interface SingleStoreDecimalConfig<T extends 'string' | 'number' | 'bigint' = 'string' | 'number' | 'bigint'> {
|
|
26
72
|
precision?: number;
|
|
27
73
|
scale?: number;
|
|
28
74
|
unsigned?: boolean;
|
|
75
|
+
mode?: T;
|
|
29
76
|
}
|
|
30
77
|
export declare function decimal(): SingleStoreDecimalBuilderInitial<''>;
|
|
31
|
-
export declare function decimal(config: SingleStoreDecimalConfig): SingleStoreDecimalBuilderInitial<''>;
|
|
32
|
-
export declare function decimal<TName extends string>(name: TName, config?: SingleStoreDecimalConfig): SingleStoreDecimalBuilderInitial<TName>;
|
|
78
|
+
export declare function decimal<TMode extends 'string' | 'number' | 'bigint'>(config: SingleStoreDecimalConfig<TMode>): Equal<TMode, 'number'> extends true ? SingleStoreDecimalNumberBuilderInitial<''> : Equal<TMode, 'bigint'> extends true ? SingleStoreDecimalBigIntBuilderInitial<''> : SingleStoreDecimalBuilderInitial<''>;
|
|
79
|
+
export declare function decimal<TName extends string, TMode extends 'string' | 'number' | 'bigint'>(name: TName, config?: SingleStoreDecimalConfig<TMode>): Equal<TMode, 'number'> extends true ? SingleStoreDecimalNumberBuilderInitial<TName> : Equal<TMode, 'bigint'> extends true ? SingleStoreDecimalBigIntBuilderInitial<TName> : SingleStoreDecimalBuilderInitial<TName>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ColumnBuilderBaseConfig } from "../../column-builder.js";
|
|
2
2
|
import type { ColumnBaseConfig } from "../../column.js";
|
|
3
3
|
import { entityKind } from "../../entity.js";
|
|
4
|
+
import { type Equal } from "../../utils.js";
|
|
4
5
|
import { SingleStoreColumnBuilderWithAutoIncrement, SingleStoreColumnWithAutoIncrement } from "./common.js";
|
|
5
6
|
export type SingleStoreDecimalBuilderInitial<TName extends string> = SingleStoreDecimalBuilder<{
|
|
6
7
|
name: TName;
|
|
@@ -20,13 +21,59 @@ export declare class SingleStoreDecimal<T extends ColumnBaseConfig<'string', 'Si
|
|
|
20
21
|
readonly precision: number | undefined;
|
|
21
22
|
readonly scale: number | undefined;
|
|
22
23
|
readonly unsigned: boolean | undefined;
|
|
24
|
+
mapFromDriverValue(value: unknown): string;
|
|
23
25
|
getSQLType(): string;
|
|
24
26
|
}
|
|
25
|
-
export
|
|
27
|
+
export type SingleStoreDecimalNumberBuilderInitial<TName extends string> = SingleStoreDecimalNumberBuilder<{
|
|
28
|
+
name: TName;
|
|
29
|
+
dataType: 'number';
|
|
30
|
+
columnType: 'SingleStoreDecimalNumber';
|
|
31
|
+
data: number;
|
|
32
|
+
driverParam: string;
|
|
33
|
+
enumValues: undefined;
|
|
34
|
+
generated: undefined;
|
|
35
|
+
}>;
|
|
36
|
+
export declare class SingleStoreDecimalNumberBuilder<T extends ColumnBuilderBaseConfig<'number', 'SingleStoreDecimalNumber'>> extends SingleStoreColumnBuilderWithAutoIncrement<T, SingleStoreDecimalConfig> {
|
|
37
|
+
static readonly [entityKind]: string;
|
|
38
|
+
constructor(name: T['name'], config: SingleStoreDecimalConfig | undefined);
|
|
39
|
+
}
|
|
40
|
+
export declare class SingleStoreDecimalNumber<T extends ColumnBaseConfig<'number', 'SingleStoreDecimalNumber'>> extends SingleStoreColumnWithAutoIncrement<T, SingleStoreDecimalConfig> {
|
|
41
|
+
static readonly [entityKind]: string;
|
|
42
|
+
readonly precision: number | undefined;
|
|
43
|
+
readonly scale: number | undefined;
|
|
44
|
+
readonly unsigned: boolean | undefined;
|
|
45
|
+
mapFromDriverValue(value: unknown): number;
|
|
46
|
+
mapToDriverValue: StringConstructor;
|
|
47
|
+
getSQLType(): string;
|
|
48
|
+
}
|
|
49
|
+
export type SingleStoreDecimalBigIntBuilderInitial<TName extends string> = SingleStoreDecimalBigIntBuilder<{
|
|
50
|
+
name: TName;
|
|
51
|
+
dataType: 'bigint';
|
|
52
|
+
columnType: 'SingleStoreDecimalBigInt';
|
|
53
|
+
data: bigint;
|
|
54
|
+
driverParam: string;
|
|
55
|
+
enumValues: undefined;
|
|
56
|
+
generated: undefined;
|
|
57
|
+
}>;
|
|
58
|
+
export declare class SingleStoreDecimalBigIntBuilder<T extends ColumnBuilderBaseConfig<'bigint', 'SingleStoreDecimalBigInt'>> extends SingleStoreColumnBuilderWithAutoIncrement<T, SingleStoreDecimalConfig> {
|
|
59
|
+
static readonly [entityKind]: string;
|
|
60
|
+
constructor(name: T['name'], config: SingleStoreDecimalConfig | undefined);
|
|
61
|
+
}
|
|
62
|
+
export declare class SingleStoreDecimalBigInt<T extends ColumnBaseConfig<'bigint', 'SingleStoreDecimalBigInt'>> extends SingleStoreColumnWithAutoIncrement<T, SingleStoreDecimalConfig> {
|
|
63
|
+
static readonly [entityKind]: string;
|
|
64
|
+
readonly precision: number | undefined;
|
|
65
|
+
readonly scale: number | undefined;
|
|
66
|
+
readonly unsigned: boolean | undefined;
|
|
67
|
+
mapFromDriverValue: BigIntConstructor;
|
|
68
|
+
mapToDriverValue: StringConstructor;
|
|
69
|
+
getSQLType(): string;
|
|
70
|
+
}
|
|
71
|
+
export interface SingleStoreDecimalConfig<T extends 'string' | 'number' | 'bigint' = 'string' | 'number' | 'bigint'> {
|
|
26
72
|
precision?: number;
|
|
27
73
|
scale?: number;
|
|
28
74
|
unsigned?: boolean;
|
|
75
|
+
mode?: T;
|
|
29
76
|
}
|
|
30
77
|
export declare function decimal(): SingleStoreDecimalBuilderInitial<''>;
|
|
31
|
-
export declare function decimal(config: SingleStoreDecimalConfig): SingleStoreDecimalBuilderInitial<''>;
|
|
32
|
-
export declare function decimal<TName extends string>(name: TName, config?: SingleStoreDecimalConfig): SingleStoreDecimalBuilderInitial<TName>;
|
|
78
|
+
export declare function decimal<TMode extends 'string' | 'number' | 'bigint'>(config: SingleStoreDecimalConfig<TMode>): Equal<TMode, 'number'> extends true ? SingleStoreDecimalNumberBuilderInitial<''> : Equal<TMode, 'bigint'> extends true ? SingleStoreDecimalBigIntBuilderInitial<''> : SingleStoreDecimalBuilderInitial<''>;
|
|
79
|
+
export declare function decimal<TName extends string, TMode extends 'string' | 'number' | 'bigint'>(name: TName, config?: SingleStoreDecimalConfig<TMode>): Equal<TMode, 'number'> extends true ? SingleStoreDecimalNumberBuilderInitial<TName> : Equal<TMode, 'bigint'> extends true ? SingleStoreDecimalBigIntBuilderInitial<TName> : SingleStoreDecimalBuilderInitial<TName>;
|
|
@@ -22,6 +22,87 @@ class SingleStoreDecimal extends SingleStoreColumnWithAutoIncrement {
|
|
|
22
22
|
precision = this.config.precision;
|
|
23
23
|
scale = this.config.scale;
|
|
24
24
|
unsigned = this.config.unsigned;
|
|
25
|
+
mapFromDriverValue(value) {
|
|
26
|
+
if (typeof value === "string")
|
|
27
|
+
return value;
|
|
28
|
+
return String(value);
|
|
29
|
+
}
|
|
30
|
+
getSQLType() {
|
|
31
|
+
let type = "";
|
|
32
|
+
if (this.precision !== void 0 && this.scale !== void 0) {
|
|
33
|
+
type += `decimal(${this.precision},${this.scale})`;
|
|
34
|
+
} else if (this.precision === void 0) {
|
|
35
|
+
type += "decimal";
|
|
36
|
+
} else {
|
|
37
|
+
type += `decimal(${this.precision})`;
|
|
38
|
+
}
|
|
39
|
+
type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
|
|
40
|
+
return this.unsigned ? `${type} unsigned` : type;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
class SingleStoreDecimalNumberBuilder extends SingleStoreColumnBuilderWithAutoIncrement {
|
|
44
|
+
static [entityKind] = "SingleStoreDecimalNumberBuilder";
|
|
45
|
+
constructor(name, config) {
|
|
46
|
+
super(name, "number", "SingleStoreDecimalNumber");
|
|
47
|
+
this.config.precision = config?.precision;
|
|
48
|
+
this.config.scale = config?.scale;
|
|
49
|
+
this.config.unsigned = config?.unsigned;
|
|
50
|
+
}
|
|
51
|
+
/** @internal */
|
|
52
|
+
build(table) {
|
|
53
|
+
return new SingleStoreDecimalNumber(
|
|
54
|
+
table,
|
|
55
|
+
this.config
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class SingleStoreDecimalNumber extends SingleStoreColumnWithAutoIncrement {
|
|
60
|
+
static [entityKind] = "SingleStoreDecimalNumber";
|
|
61
|
+
precision = this.config.precision;
|
|
62
|
+
scale = this.config.scale;
|
|
63
|
+
unsigned = this.config.unsigned;
|
|
64
|
+
mapFromDriverValue(value) {
|
|
65
|
+
if (typeof value === "number")
|
|
66
|
+
return value;
|
|
67
|
+
return Number(value);
|
|
68
|
+
}
|
|
69
|
+
mapToDriverValue = String;
|
|
70
|
+
getSQLType() {
|
|
71
|
+
let type = "";
|
|
72
|
+
if (this.precision !== void 0 && this.scale !== void 0) {
|
|
73
|
+
type += `decimal(${this.precision},${this.scale})`;
|
|
74
|
+
} else if (this.precision === void 0) {
|
|
75
|
+
type += "decimal";
|
|
76
|
+
} else {
|
|
77
|
+
type += `decimal(${this.precision})`;
|
|
78
|
+
}
|
|
79
|
+
type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
|
|
80
|
+
return this.unsigned ? `${type} unsigned` : type;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
class SingleStoreDecimalBigIntBuilder extends SingleStoreColumnBuilderWithAutoIncrement {
|
|
84
|
+
static [entityKind] = "SingleStoreDecimalBigIntBuilder";
|
|
85
|
+
constructor(name, config) {
|
|
86
|
+
super(name, "bigint", "SingleStoreDecimalBigInt");
|
|
87
|
+
this.config.precision = config?.precision;
|
|
88
|
+
this.config.scale = config?.scale;
|
|
89
|
+
this.config.unsigned = config?.unsigned;
|
|
90
|
+
}
|
|
91
|
+
/** @internal */
|
|
92
|
+
build(table) {
|
|
93
|
+
return new SingleStoreDecimalBigInt(
|
|
94
|
+
table,
|
|
95
|
+
this.config
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class SingleStoreDecimalBigInt extends SingleStoreColumnWithAutoIncrement {
|
|
100
|
+
static [entityKind] = "SingleStoreDecimalBigInt";
|
|
101
|
+
precision = this.config.precision;
|
|
102
|
+
scale = this.config.scale;
|
|
103
|
+
unsigned = this.config.unsigned;
|
|
104
|
+
mapFromDriverValue = BigInt;
|
|
105
|
+
mapToDriverValue = String;
|
|
25
106
|
getSQLType() {
|
|
26
107
|
let type = "";
|
|
27
108
|
if (this.precision !== void 0 && this.scale !== void 0) {
|
|
@@ -36,15 +117,17 @@ class SingleStoreDecimal extends SingleStoreColumnWithAutoIncrement {
|
|
|
36
117
|
}
|
|
37
118
|
}
|
|
38
119
|
function decimal(a, b = {}) {
|
|
39
|
-
const { name, config } = getColumnNameAndConfig(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
);
|
|
43
|
-
return new SingleStoreDecimalBuilder(name, config);
|
|
120
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
121
|
+
const mode = config?.mode;
|
|
122
|
+
return mode === "number" ? new SingleStoreDecimalNumberBuilder(name, config) : mode === "bigint" ? new SingleStoreDecimalBigIntBuilder(name, config) : new SingleStoreDecimalBuilder(name, config);
|
|
44
123
|
}
|
|
45
124
|
export {
|
|
46
125
|
SingleStoreDecimal,
|
|
126
|
+
SingleStoreDecimalBigInt,
|
|
127
|
+
SingleStoreDecimalBigIntBuilder,
|
|
47
128
|
SingleStoreDecimalBuilder,
|
|
129
|
+
SingleStoreDecimalNumber,
|
|
130
|
+
SingleStoreDecimalNumberBuilder,
|
|
48
131
|
decimal
|
|
49
132
|
};
|
|
50
133
|
//# sourceMappingURL=decimal.js.map
|