drizzle-orm 0.39.2-aaa57ff → 0.39.2-dc3b366
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/alias.cjs.map +1 -1
- package/alias.d.cts +3 -3
- package/alias.d.ts +3 -3
- package/alias.js.map +1 -1
- package/aws-data-api/pg/driver.cjs +5 -19
- package/aws-data-api/pg/driver.cjs.map +1 -1
- package/aws-data-api/pg/driver.d.cts +8 -9
- package/aws-data-api/pg/driver.d.ts +8 -9
- package/aws-data-api/pg/driver.js +8 -9
- package/aws-data-api/pg/driver.js.map +1 -1
- package/aws-data-api/pg/migrator.cjs.map +1 -1
- package/aws-data-api/pg/migrator.d.cts +1 -2
- package/aws-data-api/pg/migrator.d.ts +1 -2
- package/aws-data-api/pg/migrator.js.map +1 -1
- package/aws-data-api/pg/session.cjs +4 -67
- package/aws-data-api/pg/session.cjs.map +1 -1
- package/aws-data-api/pg/session.d.cts +8 -13
- package/aws-data-api/pg/session.d.ts +8 -13
- package/aws-data-api/pg/session.js +4 -67
- package/aws-data-api/pg/session.js.map +1 -1
- package/better-sqlite3/driver.cjs +5 -12
- package/better-sqlite3/driver.cjs.map +1 -1
- package/better-sqlite3/driver.d.cts +6 -7
- package/better-sqlite3/driver.d.ts +6 -7
- package/better-sqlite3/driver.js +8 -12
- package/better-sqlite3/driver.js.map +1 -1
- package/better-sqlite3/migrator.cjs.map +1 -1
- package/better-sqlite3/migrator.d.cts +1 -2
- package/better-sqlite3/migrator.d.ts +1 -2
- package/better-sqlite3/migrator.js.map +1 -1
- package/better-sqlite3/session.cjs +4 -49
- package/better-sqlite3/session.cjs.map +1 -1
- package/better-sqlite3/session.d.cts +8 -14
- package/better-sqlite3/session.d.ts +8 -14
- package/better-sqlite3/session.js +4 -49
- package/better-sqlite3/session.js.map +1 -1
- package/bun-sql/driver.cjs +5 -16
- package/bun-sql/driver.cjs.map +1 -1
- package/bun-sql/driver.d.cts +6 -7
- package/bun-sql/driver.d.ts +6 -7
- package/bun-sql/driver.js +8 -6
- package/bun-sql/driver.js.map +1 -1
- package/bun-sql/migrator.cjs.map +1 -1
- package/bun-sql/migrator.d.cts +1 -2
- package/bun-sql/migrator.d.ts +1 -2
- package/bun-sql/migrator.js.map +1 -1
- package/bun-sql/session.cjs +6 -50
- package/bun-sql/session.cjs.map +1 -1
- package/bun-sql/session.d.cts +9 -14
- package/bun-sql/session.d.ts +9 -14
- package/bun-sql/session.js +6 -50
- package/bun-sql/session.js.map +1 -1
- package/bun-sqlite/driver.cjs +5 -22
- package/bun-sqlite/driver.cjs.map +1 -1
- package/bun-sqlite/driver.d.cts +6 -7
- package/bun-sqlite/driver.d.ts +6 -7
- package/bun-sqlite/driver.js +8 -12
- package/bun-sqlite/driver.js.map +1 -1
- package/bun-sqlite/migrator.cjs.map +1 -1
- package/bun-sqlite/migrator.d.cts +1 -2
- package/bun-sqlite/migrator.d.ts +1 -2
- package/bun-sqlite/migrator.js.map +1 -1
- package/bun-sqlite/session.cjs +4 -49
- package/bun-sqlite/session.cjs.map +1 -1
- package/bun-sqlite/session.d.cts +8 -14
- package/bun-sqlite/session.d.ts +8 -14
- package/bun-sqlite/session.js +4 -49
- package/bun-sqlite/session.js.map +1 -1
- package/d1/driver.cjs +5 -22
- package/d1/driver.cjs.map +1 -1
- package/d1/driver.d.cts +2 -3
- package/d1/driver.d.ts +2 -3
- package/d1/driver.js +8 -12
- package/d1/driver.js.map +1 -1
- package/d1/migrator.cjs.map +1 -1
- package/d1/migrator.d.cts +1 -2
- package/d1/migrator.d.ts +1 -2
- package/d1/migrator.js.map +1 -1
- package/d1/session.cjs +8 -50
- package/d1/session.cjs.map +1 -1
- package/d1/session.d.cts +8 -15
- package/d1/session.d.ts +8 -15
- package/d1/session.js +8 -50
- package/d1/session.js.map +1 -1
- package/durable-sqlite/driver.cjs +5 -16
- package/durable-sqlite/driver.cjs.map +1 -1
- package/durable-sqlite/driver.d.cts +2 -3
- package/durable-sqlite/driver.d.ts +2 -3
- package/durable-sqlite/driver.js +8 -6
- package/durable-sqlite/driver.js.map +1 -1
- package/durable-sqlite/migrator.cjs.map +1 -1
- package/durable-sqlite/migrator.d.cts +1 -2
- package/durable-sqlite/migrator.d.ts +1 -2
- package/durable-sqlite/migrator.js.map +1 -1
- package/durable-sqlite/session.cjs +4 -46
- package/durable-sqlite/session.cjs.map +1 -1
- package/durable-sqlite/session.d.cts +8 -14
- package/durable-sqlite/session.d.ts +8 -14
- package/durable-sqlite/session.js +4 -46
- package/durable-sqlite/session.js.map +1 -1
- package/expo-sqlite/driver.cjs +5 -22
- package/expo-sqlite/driver.cjs.map +1 -1
- package/expo-sqlite/driver.d.cts +2 -3
- package/expo-sqlite/driver.d.ts +2 -3
- package/expo-sqlite/driver.js +8 -12
- package/expo-sqlite/driver.js.map +1 -1
- package/expo-sqlite/migrator.cjs.map +1 -1
- package/expo-sqlite/migrator.d.cts +2 -3
- package/expo-sqlite/migrator.d.ts +2 -3
- package/expo-sqlite/migrator.js.map +1 -1
- package/expo-sqlite/query.cjs +2 -13
- package/expo-sqlite/query.cjs.map +1 -1
- package/expo-sqlite/query.d.cts +1 -2
- package/expo-sqlite/query.d.ts +1 -2
- package/expo-sqlite/query.js +2 -3
- package/expo-sqlite/query.js.map +1 -1
- package/expo-sqlite/session.cjs +4 -47
- package/expo-sqlite/session.cjs.map +1 -1
- package/expo-sqlite/session.d.cts +8 -14
- package/expo-sqlite/session.d.ts +8 -14
- package/expo-sqlite/session.js +4 -47
- package/expo-sqlite/session.js.map +1 -1
- package/libsql/driver-core.cjs +5 -22
- package/libsql/driver-core.cjs.map +1 -1
- package/libsql/driver-core.d.cts +1 -2
- package/libsql/driver-core.d.ts +1 -2
- package/libsql/driver-core.js +8 -12
- package/libsql/driver-core.js.map +1 -1
- package/libsql/driver.cjs.map +1 -1
- package/libsql/driver.d.cts +5 -6
- package/libsql/driver.d.ts +5 -6
- package/libsql/driver.js.map +1 -1
- package/libsql/http/index.cjs.map +1 -1
- package/libsql/http/index.d.cts +5 -6
- package/libsql/http/index.d.ts +5 -6
- package/libsql/http/index.js.map +1 -1
- package/libsql/migrator.cjs.map +1 -1
- package/libsql/migrator.d.cts +1 -2
- package/libsql/migrator.d.ts +1 -2
- package/libsql/migrator.js.map +1 -1
- package/libsql/node/index.cjs.map +1 -1
- package/libsql/node/index.d.cts +5 -6
- package/libsql/node/index.d.ts +5 -6
- package/libsql/node/index.js.map +1 -1
- package/libsql/session.cjs +4 -56
- package/libsql/session.cjs.map +1 -1
- package/libsql/session.d.cts +9 -15
- package/libsql/session.d.ts +9 -15
- package/libsql/session.js +4 -56
- package/libsql/session.js.map +1 -1
- package/libsql/sqlite3/index.cjs.map +1 -1
- package/libsql/sqlite3/index.d.cts +5 -6
- package/libsql/sqlite3/index.d.ts +5 -6
- package/libsql/sqlite3/index.js.map +1 -1
- package/libsql/wasm/index.cjs.map +1 -1
- package/libsql/wasm/index.d.cts +5 -6
- package/libsql/wasm/index.d.ts +5 -6
- package/libsql/wasm/index.js.map +1 -1
- package/libsql/web/index.cjs.map +1 -1
- package/libsql/web/index.d.cts +5 -6
- package/libsql/web/index.d.ts +5 -6
- package/libsql/web/index.js.map +1 -1
- package/libsql/ws/index.cjs.map +1 -1
- package/libsql/ws/index.d.cts +5 -6
- package/libsql/ws/index.d.ts +5 -6
- package/libsql/ws/index.js.map +1 -1
- package/mysql-core/db.cjs +6 -30
- package/mysql-core/db.cjs.map +1 -1
- package/mysql-core/db.d.cts +8 -15
- package/mysql-core/db.d.ts +8 -15
- package/mysql-core/db.js +5 -29
- package/mysql-core/db.js.map +1 -1
- package/mysql-core/dialect.cjs +15 -197
- package/mysql-core/dialect.cjs.map +1 -1
- package/mysql-core/dialect.d.cts +13 -36
- package/mysql-core/dialect.d.ts +13 -36
- package/mysql-core/dialect.js +22 -196
- package/mysql-core/dialect.js.map +1 -1
- package/mysql-core/query-builders/count.cjs.map +1 -1
- package/mysql-core/query-builders/count.d.cts +1 -1
- package/mysql-core/query-builders/count.d.ts +1 -1
- package/mysql-core/query-builders/count.js.map +1 -1
- package/mysql-core/query-builders/query.cjs +31 -18
- package/mysql-core/query-builders/query.cjs.map +1 -1
- package/mysql-core/query-builders/query.d.cts +10 -8
- package/mysql-core/query-builders/query.d.ts +10 -8
- package/mysql-core/query-builders/query.js +31 -18
- package/mysql-core/query-builders/query.js.map +1 -1
- package/mysql-core/session.cjs +2 -3
- package/mysql-core/session.cjs.map +1 -1
- package/mysql-core/session.d.cts +7 -10
- package/mysql-core/session.d.ts +7 -10
- package/mysql-core/session.js +2 -3
- package/mysql-core/session.js.map +1 -1
- package/mysql-proxy/driver.cjs +5 -22
- package/mysql-proxy/driver.cjs.map +1 -1
- package/mysql-proxy/driver.d.cts +2 -3
- package/mysql-proxy/driver.d.ts +2 -3
- package/mysql-proxy/driver.js +8 -12
- package/mysql-proxy/driver.js.map +1 -1
- package/mysql-proxy/migrator.cjs.map +1 -1
- package/mysql-proxy/migrator.d.cts +1 -2
- package/mysql-proxy/migrator.d.ts +1 -2
- package/mysql-proxy/migrator.js.map +1 -1
- package/mysql-proxy/session.cjs +2 -27
- package/mysql-proxy/session.cjs.map +1 -1
- package/mysql-proxy/session.d.cts +8 -13
- package/mysql-proxy/session.d.ts +8 -13
- package/mysql-proxy/session.js +2 -27
- package/mysql-proxy/session.js.map +1 -1
- package/mysql2/driver.cjs +7 -24
- package/mysql2/driver.cjs.map +1 -1
- package/mysql2/driver.d.cts +9 -10
- package/mysql2/driver.d.ts +9 -10
- package/mysql2/driver.js +10 -14
- package/mysql2/driver.js.map +1 -1
- package/mysql2/migrator.cjs.map +1 -1
- package/mysql2/migrator.d.cts +1 -2
- package/mysql2/migrator.d.ts +1 -2
- package/mysql2/migrator.js.map +1 -1
- package/mysql2/session.cjs +2 -30
- package/mysql2/session.cjs.map +1 -1
- package/mysql2/session.d.cts +8 -13
- package/mysql2/session.d.ts +8 -13
- package/mysql2/session.js +2 -30
- package/mysql2/session.js.map +1 -1
- package/neon-http/driver.cjs +7 -21
- package/neon-http/driver.cjs.map +1 -1
- package/neon-http/driver.d.cts +9 -10
- package/neon-http/driver.d.ts +9 -10
- package/neon-http/driver.js +7 -11
- package/neon-http/driver.js.map +1 -1
- package/neon-http/migrator.cjs.map +1 -1
- package/neon-http/migrator.d.cts +1 -2
- package/neon-http/migrator.d.ts +1 -2
- package/neon-http/migrator.js.map +1 -1
- package/neon-http/session.cjs +2 -32
- package/neon-http/session.cjs.map +1 -1
- package/neon-http/session.d.cts +8 -13
- package/neon-http/session.d.ts +8 -13
- package/neon-http/session.js +2 -32
- package/neon-http/session.js.map +1 -1
- package/neon-serverless/driver.cjs +7 -18
- package/neon-serverless/driver.cjs.map +1 -1
- package/neon-serverless/driver.d.cts +8 -9
- package/neon-serverless/driver.d.ts +8 -9
- package/neon-serverless/driver.js +10 -8
- package/neon-serverless/driver.js.map +1 -1
- package/neon-serverless/migrator.cjs.map +1 -1
- package/neon-serverless/migrator.d.cts +1 -2
- package/neon-serverless/migrator.d.ts +1 -2
- package/neon-serverless/migrator.js.map +1 -1
- package/neon-serverless/session.cjs +5 -40
- package/neon-serverless/session.cjs.map +1 -1
- package/neon-serverless/session.d.cts +8 -13
- package/neon-serverless/session.d.ts +8 -13
- package/neon-serverless/session.js +5 -40
- package/neon-serverless/session.js.map +1 -1
- package/node-postgres/driver.cjs +7 -13
- package/node-postgres/driver.cjs.map +1 -1
- package/node-postgres/driver.d.cts +8 -9
- package/node-postgres/driver.d.ts +8 -9
- package/node-postgres/driver.js +10 -13
- package/node-postgres/driver.js.map +1 -1
- package/node-postgres/migrator.cjs.map +1 -1
- package/node-postgres/migrator.d.cts +1 -2
- package/node-postgres/migrator.d.ts +1 -2
- package/node-postgres/migrator.js.map +1 -1
- package/node-postgres/session.cjs +4 -45
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.d.cts +8 -13
- package/node-postgres/session.d.ts +8 -13
- package/node-postgres/session.js +4 -45
- package/node-postgres/session.js.map +1 -1
- package/op-sqlite/driver.cjs +5 -22
- package/op-sqlite/driver.cjs.map +1 -1
- package/op-sqlite/driver.d.cts +2 -3
- package/op-sqlite/driver.d.ts +2 -3
- package/op-sqlite/driver.js +8 -12
- package/op-sqlite/driver.js.map +1 -1
- package/op-sqlite/migrator.cjs.map +1 -1
- package/op-sqlite/migrator.d.cts +2 -3
- package/op-sqlite/migrator.d.ts +2 -3
- package/op-sqlite/migrator.js.map +1 -1
- package/op-sqlite/session.cjs +4 -47
- package/op-sqlite/session.cjs.map +1 -1
- package/op-sqlite/session.d.cts +8 -14
- package/op-sqlite/session.d.ts +8 -14
- package/op-sqlite/session.js +4 -47
- package/op-sqlite/session.js.map +1 -1
- package/package.json +51 -99
- package/pg-core/db.cjs +5 -32
- package/pg-core/db.cjs.map +1 -1
- package/pg-core/db.d.cts +9 -16
- package/pg-core/db.d.ts +9 -16
- package/pg-core/db.js +4 -31
- package/pg-core/db.js.map +1 -1
- package/pg-core/dialect.cjs +488 -173
- package/pg-core/dialect.cjs.map +1 -1
- package/pg-core/dialect.d.cts +8 -27
- package/pg-core/dialect.d.ts +8 -27
- package/pg-core/dialect.js +495 -172
- package/pg-core/dialect.js.map +1 -1
- package/pg-core/query-builders/count.cjs.map +1 -1
- package/pg-core/query-builders/count.d.cts +1 -1
- package/pg-core/query-builders/count.d.ts +1 -1
- package/pg-core/query-builders/count.js.map +1 -1
- package/pg-core/query-builders/query.cjs +18 -15
- package/pg-core/query-builders/query.cjs.map +1 -1
- package/pg-core/query-builders/query.d.cts +6 -6
- package/pg-core/query-builders/query.d.ts +6 -6
- package/pg-core/query-builders/query.js +18 -15
- package/pg-core/query-builders/query.js.map +1 -1
- package/pg-core/session.cjs +2 -3
- package/pg-core/session.cjs.map +1 -1
- package/pg-core/session.d.cts +6 -9
- package/pg-core/session.d.ts +6 -9
- package/pg-core/session.js +2 -3
- package/pg-core/session.js.map +1 -1
- package/pg-proxy/driver.cjs +5 -21
- package/pg-proxy/driver.cjs.map +1 -1
- package/pg-proxy/driver.d.cts +2 -3
- package/pg-proxy/driver.d.ts +2 -3
- package/pg-proxy/driver.js +8 -11
- package/pg-proxy/driver.js.map +1 -1
- package/pg-proxy/migrator.cjs.map +1 -1
- package/pg-proxy/migrator.d.cts +1 -2
- package/pg-proxy/migrator.d.ts +1 -2
- package/pg-proxy/migrator.js.map +1 -1
- package/pg-proxy/session.cjs +2 -37
- package/pg-proxy/session.cjs.map +1 -1
- package/pg-proxy/session.d.cts +8 -13
- package/pg-proxy/session.d.ts +8 -13
- package/pg-proxy/session.js +2 -37
- package/pg-proxy/session.js.map +1 -1
- package/pglite/driver.cjs +7 -23
- package/pglite/driver.cjs.map +1 -1
- package/pglite/driver.d.cts +8 -9
- package/pglite/driver.d.ts +8 -9
- package/pglite/driver.js +10 -13
- package/pglite/driver.js.map +1 -1
- package/pglite/migrator.cjs.map +1 -1
- package/pglite/migrator.d.cts +1 -2
- package/pglite/migrator.d.ts +1 -2
- package/pglite/migrator.js.map +1 -1
- package/pglite/session.cjs +3 -34
- package/pglite/session.cjs.map +1 -1
- package/pglite/session.d.cts +8 -13
- package/pglite/session.d.ts +8 -13
- package/pglite/session.js +3 -34
- package/pglite/session.js.map +1 -1
- package/planetscale-serverless/driver.cjs +5 -22
- package/planetscale-serverless/driver.cjs.map +1 -1
- package/planetscale-serverless/driver.d.cts +6 -7
- package/planetscale-serverless/driver.d.ts +6 -7
- package/planetscale-serverless/driver.js +8 -12
- package/planetscale-serverless/driver.js.map +1 -1
- package/planetscale-serverless/migrator.cjs.map +1 -1
- package/planetscale-serverless/migrator.d.cts +1 -2
- package/planetscale-serverless/migrator.d.ts +1 -2
- package/planetscale-serverless/migrator.js.map +1 -1
- package/planetscale-serverless/session.cjs +5 -45
- package/planetscale-serverless/session.cjs.map +1 -1
- package/planetscale-serverless/session.d.cts +9 -14
- package/planetscale-serverless/session.d.ts +9 -14
- package/planetscale-serverless/session.js +5 -45
- package/planetscale-serverless/session.js.map +1 -1
- package/postgres-js/driver.cjs +5 -6
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.d.cts +6 -7
- package/postgres-js/driver.d.ts +6 -7
- package/postgres-js/driver.js +8 -6
- package/postgres-js/driver.js.map +1 -1
- package/postgres-js/migrator.cjs.map +1 -1
- package/postgres-js/migrator.d.cts +1 -2
- package/postgres-js/migrator.d.ts +1 -2
- package/postgres-js/migrator.js.map +1 -1
- package/postgres-js/session.cjs +6 -51
- package/postgres-js/session.cjs.map +1 -1
- package/postgres-js/session.d.cts +9 -15
- package/postgres-js/session.d.ts +9 -15
- package/postgres-js/session.js +6 -51
- package/postgres-js/session.js.map +1 -1
- package/prisma/mysql/driver.cjs +1 -1
- package/prisma/mysql/driver.cjs.map +1 -1
- package/prisma/mysql/driver.js +1 -1
- package/prisma/mysql/driver.js.map +1 -1
- package/prisma/mysql/session.cjs +0 -3
- package/prisma/mysql/session.cjs.map +1 -1
- package/prisma/mysql/session.d.cts +1 -3
- package/prisma/mysql/session.d.ts +1 -3
- package/prisma/mysql/session.js +0 -3
- package/prisma/mysql/session.js.map +1 -1
- package/prisma/pg/driver.cjs +1 -1
- package/prisma/pg/driver.cjs.map +1 -1
- package/prisma/pg/driver.js +1 -1
- package/prisma/pg/driver.js.map +1 -1
- package/prisma/pg/session.cjs +0 -3
- package/prisma/pg/session.cjs.map +1 -1
- package/prisma/pg/session.d.cts +1 -3
- package/prisma/pg/session.d.ts +1 -3
- package/prisma/pg/session.js +0 -3
- package/prisma/pg/session.js.map +1 -1
- package/prisma/sqlite/driver.cjs +1 -1
- package/prisma/sqlite/driver.cjs.map +1 -1
- package/prisma/sqlite/driver.js +1 -1
- package/prisma/sqlite/driver.js.map +1 -1
- package/prisma/sqlite/session.cjs +0 -3
- package/prisma/sqlite/session.cjs.map +1 -1
- package/prisma/sqlite/session.d.cts +2 -4
- package/prisma/sqlite/session.d.ts +2 -4
- package/prisma/sqlite/session.js +0 -3
- package/prisma/sqlite/session.js.map +1 -1
- package/relations.cjs +245 -596
- package/relations.cjs.map +1 -1
- package/relations.d.cts +140 -292
- package/relations.d.ts +140 -292
- package/relations.js +240 -589
- package/relations.js.map +1 -1
- package/singlestore/driver.cjs +1 -1
- package/singlestore/driver.cjs.map +1 -1
- package/singlestore/driver.d.cts +1 -1
- package/singlestore/driver.d.ts +1 -1
- package/singlestore/driver.js +3 -3
- package/singlestore/driver.js.map +1 -1
- package/singlestore/session.cjs.map +1 -1
- package/singlestore/session.d.cts +4 -4
- package/singlestore/session.d.ts +4 -4
- package/singlestore/session.js.map +1 -1
- package/singlestore-core/db.cjs.map +1 -1
- package/singlestore-core/db.d.cts +3 -3
- package/singlestore-core/db.d.ts +3 -3
- package/singlestore-core/db.js.map +1 -1
- package/singlestore-core/dialect.cjs +6 -16
- package/singlestore-core/dialect.cjs.map +1 -1
- package/singlestore-core/dialect.d.cts +6 -6
- package/singlestore-core/dialect.d.ts +6 -6
- package/singlestore-core/dialect.js +12 -6
- package/singlestore-core/dialect.js.map +1 -1
- package/singlestore-core/query-builders/query.cjs +2 -12
- package/singlestore-core/query-builders/query.cjs.map +1 -1
- package/singlestore-core/query-builders/query.d.cts +6 -6
- package/singlestore-core/query-builders/query.d.ts +6 -6
- package/singlestore-core/query-builders/query.js +4 -2
- package/singlestore-core/query-builders/query.js.map +1 -1
- package/singlestore-core/session.cjs.map +1 -1
- package/singlestore-core/session.d.cts +5 -5
- package/singlestore-core/session.d.ts +5 -5
- package/singlestore-core/session.js.map +1 -1
- package/singlestore-proxy/driver.cjs +1 -1
- package/singlestore-proxy/driver.cjs.map +1 -1
- package/singlestore-proxy/driver.js +3 -3
- package/singlestore-proxy/driver.js.map +1 -1
- package/singlestore-proxy/session.cjs.map +1 -1
- package/singlestore-proxy/session.d.cts +4 -4
- package/singlestore-proxy/session.d.ts +4 -4
- package/singlestore-proxy/session.js.map +1 -1
- package/sql/expressions/conditions.cjs.map +1 -1
- package/sql/expressions/conditions.d.cts +4 -4
- package/sql/expressions/conditions.d.ts +4 -4
- package/sql/expressions/conditions.js.map +1 -1
- package/sql/sql.cjs +0 -21
- package/sql/sql.cjs.map +1 -1
- package/sql/sql.d.cts +8 -8
- package/sql/sql.d.ts +8 -8
- package/sql/sql.js +1 -22
- package/sql/sql.js.map +1 -1
- package/sql-js/driver.cjs +5 -16
- package/sql-js/driver.cjs.map +1 -1
- package/sql-js/driver.d.cts +2 -3
- package/sql-js/driver.d.ts +2 -3
- package/sql-js/driver.js +8 -6
- package/sql-js/driver.js.map +1 -1
- package/sql-js/migrator.cjs.map +1 -1
- package/sql-js/migrator.d.cts +1 -2
- package/sql-js/migrator.d.ts +1 -2
- package/sql-js/migrator.js.map +1 -1
- package/sql-js/session.cjs +36 -71
- package/sql-js/session.cjs.map +1 -1
- package/sql-js/session.d.cts +13 -16
- package/sql-js/session.d.ts +13 -16
- package/sql-js/session.js +36 -71
- package/sql-js/session.js.map +1 -1
- package/sqlite-core/db.cjs +12 -39
- package/sqlite-core/db.cjs.map +1 -1
- package/sqlite-core/db.d.cts +8 -16
- package/sqlite-core/db.d.ts +8 -16
- package/sqlite-core/db.js +11 -38
- package/sqlite-core/db.js.map +1 -1
- package/sqlite-core/dialect.cjs +7 -186
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.d.cts +9 -31
- package/sqlite-core/dialect.d.ts +9 -31
- package/sqlite-core/dialect.js +14 -185
- package/sqlite-core/dialect.js.map +1 -1
- package/sqlite-core/query-builders/count.cjs.map +1 -1
- package/sqlite-core/query-builders/count.d.cts +1 -1
- package/sqlite-core/query-builders/count.d.ts +1 -1
- package/sqlite-core/query-builders/count.js.map +1 -1
- package/sqlite-core/query-builders/delete.cjs.map +1 -1
- package/sqlite-core/query-builders/delete.d.cts +1 -1
- package/sqlite-core/query-builders/delete.d.ts +1 -1
- package/sqlite-core/query-builders/delete.js.map +1 -1
- package/sqlite-core/query-builders/insert.cjs.map +1 -1
- package/sqlite-core/query-builders/insert.d.cts +3 -3
- package/sqlite-core/query-builders/insert.d.ts +3 -3
- package/sqlite-core/query-builders/insert.js.map +1 -1
- package/sqlite-core/query-builders/query.cjs +35 -56
- package/sqlite-core/query-builders/query.cjs.map +1 -1
- package/sqlite-core/query-builders/query.d.cts +17 -18
- package/sqlite-core/query-builders/query.d.ts +17 -18
- package/sqlite-core/query-builders/query.js +35 -56
- package/sqlite-core/query-builders/query.js.map +1 -1
- package/sqlite-core/query-builders/select.cjs.map +1 -1
- package/sqlite-core/query-builders/select.d.cts +3 -3
- package/sqlite-core/query-builders/select.d.ts +3 -3
- package/sqlite-core/query-builders/select.js.map +1 -1
- package/sqlite-core/query-builders/update.cjs.map +1 -1
- package/sqlite-core/query-builders/update.d.cts +3 -3
- package/sqlite-core/query-builders/update.d.ts +3 -3
- package/sqlite-core/query-builders/update.js.map +1 -1
- package/sqlite-core/session.cjs +2 -6
- package/sqlite-core/session.cjs.map +1 -1
- package/sqlite-core/session.d.cts +7 -15
- package/sqlite-core/session.d.ts +7 -15
- package/sqlite-core/session.js +2 -6
- package/sqlite-core/session.js.map +1 -1
- package/sqlite-proxy/driver.cjs +5 -23
- package/sqlite-proxy/driver.cjs.map +1 -1
- package/sqlite-proxy/driver.d.cts +3 -4
- package/sqlite-proxy/driver.d.ts +3 -4
- package/sqlite-proxy/driver.js +5 -13
- package/sqlite-proxy/driver.js.map +1 -1
- package/sqlite-proxy/migrator.cjs.map +1 -1
- package/sqlite-proxy/migrator.d.cts +1 -2
- package/sqlite-proxy/migrator.d.ts +1 -2
- package/sqlite-proxy/migrator.js.map +1 -1
- package/sqlite-proxy/session.cjs +6 -50
- package/sqlite-proxy/session.cjs.map +1 -1
- package/sqlite-proxy/session.d.cts +8 -14
- package/sqlite-proxy/session.d.ts +8 -14
- package/sqlite-proxy/session.js +6 -50
- package/sqlite-proxy/session.js.map +1 -1
- package/table.cjs.map +1 -1
- package/table.d.cts +2 -2
- package/table.d.ts +2 -2
- package/table.js.map +1 -1
- package/tidb-serverless/driver.cjs +5 -22
- package/tidb-serverless/driver.cjs.map +1 -1
- package/tidb-serverless/driver.d.cts +6 -7
- package/tidb-serverless/driver.d.ts +6 -7
- package/tidb-serverless/driver.js +8 -12
- package/tidb-serverless/driver.js.map +1 -1
- package/tidb-serverless/migrator.cjs.map +1 -1
- package/tidb-serverless/migrator.d.cts +1 -2
- package/tidb-serverless/migrator.d.ts +1 -2
- package/tidb-serverless/migrator.js.map +1 -1
- package/tidb-serverless/session.cjs +5 -62
- package/tidb-serverless/session.cjs.map +1 -1
- package/tidb-serverless/session.d.cts +9 -14
- package/tidb-serverless/session.d.ts +9 -14
- package/tidb-serverless/session.js +5 -62
- package/tidb-serverless/session.js.map +1 -1
- package/utils.cjs +2 -2
- package/utils.cjs.map +1 -1
- package/utils.d.cts +1 -3
- package/utils.d.ts +1 -3
- package/utils.js +2 -2
- package/utils.js.map +1 -1
- package/vercel-postgres/driver.cjs +7 -23
- package/vercel-postgres/driver.cjs.map +1 -1
- package/vercel-postgres/driver.d.cts +8 -9
- package/vercel-postgres/driver.d.ts +8 -9
- package/vercel-postgres/driver.js +10 -13
- package/vercel-postgres/driver.js.map +1 -1
- package/vercel-postgres/migrator.cjs.map +1 -1
- package/vercel-postgres/migrator.d.cts +1 -2
- package/vercel-postgres/migrator.d.ts +1 -2
- package/vercel-postgres/migrator.js.map +1 -1
- package/vercel-postgres/session.cjs +4 -34
- package/vercel-postgres/session.cjs.map +1 -1
- package/vercel-postgres/session.d.cts +8 -13
- package/vercel-postgres/session.d.ts +8 -13
- package/vercel-postgres/session.js +4 -34
- 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
- package/xata-http/driver.cjs +5 -17
- package/xata-http/driver.cjs.map +1 -1
- package/xata-http/driver.d.cts +4 -5
- package/xata-http/driver.d.ts +4 -5
- package/xata-http/driver.js +5 -7
- package/xata-http/driver.js.map +1 -1
- package/xata-http/migrator.cjs.map +1 -1
- package/xata-http/migrator.d.cts +1 -2
- package/xata-http/migrator.d.ts +1 -2
- package/xata-http/migrator.js.map +1 -1
- package/xata-http/session.cjs +2 -30
- package/xata-http/session.cjs.map +1 -1
- package/xata-http/session.d.cts +8 -13
- package/xata-http/session.d.ts +8 -13
- package/xata-http/session.js +2 -30
- package/xata-http/session.js.map +1 -1
- package/_relations.cjs +0 -328
- package/_relations.cjs.map +0 -1
- package/_relations.d.cts +0 -215
- package/_relations.d.ts +0 -215
- package/_relations.js +0 -316
- package/_relations.js.map +0 -1
- package/mysql-core/query-builders/_query.cjs +0 -149
- package/mysql-core/query-builders/_query.cjs.map +0 -1
- package/mysql-core/query-builders/_query.d.cts +0 -44
- package/mysql-core/query-builders/_query.d.ts +0 -44
- package/mysql-core/query-builders/_query.js +0 -114
- package/mysql-core/query-builders/_query.js.map +0 -1
- package/pg-core/query-builders/_query.cjs +0 -155
- package/pg-core/query-builders/_query.cjs.map +0 -1
- package/pg-core/query-builders/_query.d.cts +0 -47
- package/pg-core/query-builders/_query.d.ts +0 -47
- package/pg-core/query-builders/_query.js +0 -120
- package/pg-core/query-builders/_query.js.map +0 -1
- package/sqlite-core/query-builders/_query.cjs +0 -187
- package/sqlite-core/query-builders/_query.cjs.map +0 -1
- package/sqlite-core/query-builders/_query.d.cts +0 -55
- package/sqlite-core/query-builders/_query.d.ts +0 -55
- package/sqlite-core/query-builders/_query.js +0 -151
- package/sqlite-core/query-builders/_query.js.map +0 -1
package/mysql2/driver.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { type Connection as CallbackConnection, type Pool as CallbackPool, type PoolOptions } from 'mysql2';
|
|
2
2
|
import type { Connection, Pool } from 'mysql2/promise';
|
|
3
|
-
import * as V1 from "../_relations.js";
|
|
4
3
|
import { entityKind } from "../entity.js";
|
|
5
4
|
import type { Logger } from "../logger.js";
|
|
6
5
|
import { MySqlDatabase } from "../mysql-core/db.js";
|
|
7
6
|
import { MySqlDialect } from "../mysql-core/dialect.js";
|
|
8
7
|
import type { Mode } from "../mysql-core/session.js";
|
|
9
|
-
import
|
|
8
|
+
import { type RelationalSchemaConfig, type TablesRelationalConfig } from "../relations.js";
|
|
10
9
|
import { type DrizzleConfig } from "../utils.js";
|
|
11
10
|
import type { MySql2Client, MySql2PreparedQueryHKT, MySql2QueryResultHKT } from "./session.js";
|
|
12
11
|
import { MySql2Session } from "./session.js";
|
|
@@ -19,13 +18,13 @@ export declare class MySql2Driver {
|
|
|
19
18
|
private options;
|
|
20
19
|
static readonly [entityKind]: string;
|
|
21
20
|
constructor(client: MySql2Client, dialect: MySqlDialect, options?: MySqlDriverOptions);
|
|
22
|
-
createSession(
|
|
21
|
+
createSession(schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined, mode: Mode): MySql2Session<Record<string, unknown>, TablesRelationalConfig>;
|
|
23
22
|
}
|
|
24
23
|
export { MySqlDatabase } from "../mysql-core/db.js";
|
|
25
|
-
export declare class MySql2Database<TSchema extends Record<string, unknown> = Record<string, never
|
|
24
|
+
export declare class MySql2Database<TSchema extends Record<string, unknown> = Record<string, never>> extends MySqlDatabase<MySql2QueryResultHKT, MySql2PreparedQueryHKT, TSchema> {
|
|
26
25
|
static readonly [entityKind]: string;
|
|
27
26
|
}
|
|
28
|
-
export type MySql2DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never
|
|
27
|
+
export type MySql2DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> = Omit<DrizzleConfig<TSchema>, 'schema'> & ({
|
|
29
28
|
schema: TSchema;
|
|
30
29
|
mode: Mode;
|
|
31
30
|
} | {
|
|
@@ -33,22 +32,22 @@ export type MySql2DrizzleConfig<TSchema extends Record<string, unknown> = Record
|
|
|
33
32
|
mode?: Mode;
|
|
34
33
|
});
|
|
35
34
|
export type AnyMySql2Connection = Pool | Connection | CallbackPool | CallbackConnection;
|
|
36
|
-
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>,
|
|
35
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends AnyMySql2Connection = CallbackPool>(...params: [
|
|
37
36
|
TClient | string
|
|
38
37
|
] | [
|
|
39
38
|
TClient | string,
|
|
40
|
-
MySql2DrizzleConfig<TSchema
|
|
39
|
+
MySql2DrizzleConfig<TSchema>
|
|
41
40
|
] | [
|
|
42
|
-
(MySql2DrizzleConfig<TSchema
|
|
41
|
+
(MySql2DrizzleConfig<TSchema> & ({
|
|
43
42
|
connection: string | PoolOptions;
|
|
44
43
|
} | {
|
|
45
44
|
client: TClient;
|
|
46
45
|
}))
|
|
47
|
-
]): MySql2Database<TSchema
|
|
46
|
+
]): MySql2Database<TSchema> & {
|
|
48
47
|
$client: TClient;
|
|
49
48
|
};
|
|
50
49
|
export declare namespace drizzle {
|
|
51
|
-
function mock<TSchema extends Record<string, unknown> = Record<string, never
|
|
50
|
+
function mock<TSchema extends Record<string, unknown> = Record<string, never>>(config?: MySql2DrizzleConfig<TSchema>): MySql2Database<TSchema> & {
|
|
52
51
|
$client: '$client is not available on drizzle.mock()';
|
|
53
52
|
};
|
|
54
53
|
}
|
package/mysql2/driver.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createPool } from "mysql2";
|
|
2
|
-
import * as V1 from "../_relations.js";
|
|
3
2
|
import { entityKind } from "../entity.js";
|
|
4
3
|
import { DefaultLogger } from "../logger.js";
|
|
5
4
|
import { MySqlDatabase } from "../mysql-core/db.js";
|
|
6
5
|
import { MySqlDialect } from "../mysql-core/dialect.js";
|
|
6
|
+
import {
|
|
7
|
+
createTableRelationsHelpers,
|
|
8
|
+
extractTablesRelationalConfig
|
|
9
|
+
} from "../relations.js";
|
|
7
10
|
import { isConfig } from "../utils.js";
|
|
8
11
|
import { DrizzleError } from "../errors.js";
|
|
9
12
|
import { MySql2Session } from "./session.js";
|
|
@@ -14,8 +17,8 @@ class MySql2Driver {
|
|
|
14
17
|
this.options = options;
|
|
15
18
|
}
|
|
16
19
|
static [entityKind] = "MySql2Driver";
|
|
17
|
-
createSession(
|
|
18
|
-
return new MySql2Session(this.client, this.dialect,
|
|
20
|
+
createSession(schema, mode) {
|
|
21
|
+
return new MySql2Session(this.client, this.dialect, schema, { logger: this.options.logger, mode });
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
import { MySqlDatabase as MySqlDatabase2 } from "../mysql-core/db.js";
|
|
@@ -38,9 +41,9 @@ function construct(client, config = {}) {
|
|
|
38
41
|
message: 'You need to specify "mode": "planetscale" or "default" when providing a schema. Read more: https://orm.drizzle.team/docs/rqb#modes'
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
|
-
const tablesConfig =
|
|
44
|
+
const tablesConfig = extractTablesRelationalConfig(
|
|
42
45
|
config.schema,
|
|
43
|
-
|
|
46
|
+
createTableRelationsHelpers
|
|
44
47
|
);
|
|
45
48
|
schema = {
|
|
46
49
|
fullSchema: config.schema,
|
|
@@ -49,16 +52,9 @@ function construct(client, config = {}) {
|
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
const mode = config.mode ?? "default";
|
|
52
|
-
const relations = config.relations;
|
|
53
55
|
const driver = new MySql2Driver(clientForInstance, dialect, { logger });
|
|
54
|
-
const session = driver.createSession(
|
|
55
|
-
const db = new MySql2Database(
|
|
56
|
-
dialect,
|
|
57
|
-
session,
|
|
58
|
-
relations,
|
|
59
|
-
schema,
|
|
60
|
-
mode
|
|
61
|
-
);
|
|
56
|
+
const session = driver.createSession(schema, mode);
|
|
57
|
+
const db = new MySql2Database(dialect, session, schema, mode);
|
|
62
58
|
db.$client = client;
|
|
63
59
|
return db;
|
|
64
60
|
}
|
package/mysql2/driver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mysql2/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
|
|
1
|
+
{"version":3,"sources":["../../src/mysql2/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 { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport { MySqlDatabase } from '~/mysql-core/db.ts';\nimport { MySqlDialect } from '~/mysql-core/dialect.ts';\nimport type { Mode } from '~/mysql-core/session.ts';\nimport {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { type DrizzleConfig, isConfig } from '~/utils.ts';\nimport { DrizzleError } from '../errors.ts';\nimport type { MySql2Client, MySql2PreparedQueryHKT, MySql2QueryResultHKT } from './session.ts';\nimport { MySql2Session } from './session.ts';\n\nexport interface MySqlDriverOptions {\n\tlogger?: Logger;\n}\n\nexport class MySql2Driver {\n\tstatic readonly [entityKind]: string = 'MySql2Driver';\n\n\tconstructor(\n\t\tprivate client: MySql2Client,\n\t\tprivate dialect: MySqlDialect,\n\t\tprivate options: MySqlDriverOptions = {},\n\t) {\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t\tmode: Mode,\n\t): MySql2Session<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new MySql2Session(this.client, this.dialect, schema, { logger: this.options.logger, mode });\n\t}\n}\n\nexport { MySqlDatabase } from '~/mysql-core/db.ts';\n\nexport class MySql2Database<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends MySqlDatabase<MySql2QueryResultHKT, MySql2PreparedQueryHKT, TSchema> {\n\tstatic override readonly [entityKind]: string = 'MySql2Database';\n}\n\nexport type MySql2DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> =\n\t& Omit<DrizzleConfig<TSchema>, 'schema'>\n\t& ({ schema: TSchema; mode: Mode } | { schema?: undefined; mode?: Mode });\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: MySql2DrizzleConfig<TSchema> = {},\n): MySql2Database<TSchema> & {\n\t$client: TClient;\n} {\n\tconst dialect = new MySqlDialect({ 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\tif (config.mode === undefined) {\n\t\t\tthrow new DrizzleError({\n\t\t\t\tmessage:\n\t\t\t\t\t'You need to specify \"mode\": \"planetscale\" or \"default\" when providing a schema. Read more: https://orm.drizzle.team/docs/rqb#modes',\n\t\t\t});\n\t\t}\n\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 mode = config.mode ?? 'default';\n\n\tconst driver = new MySql2Driver(clientForInstance as MySql2Client, dialect, { logger });\n\tconst session = driver.createSession(schema, mode);\n\tconst db = new MySql2Database(dialect, session, schema as any, mode) as MySql2Database<TSchema>;\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n\ninterface CallbackClient {\n\tpromise(): MySql2Client;\n}\n\nfunction isCallbackClient(client: any): client is CallbackClient {\n\treturn typeof client.promise === 'function';\n}\n\nexport type AnyMySql2Connection = Pool | Connection | CallbackPool | CallbackConnection;\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends AnyMySql2Connection = CallbackPool,\n>(\n\t...params: [\n\t\tTClient | string,\n\t] | [\n\t\tTClient | string,\n\t\tMySql2DrizzleConfig<TSchema>,\n\t] | [\n\t\t(\n\t\t\t& MySql2DrizzleConfig<TSchema>\n\t\t\t& ({\n\t\t\t\tconnection: string | PoolOptions;\n\t\t\t} | {\n\t\t\t\tclient: TClient;\n\t\t\t})\n\t\t),\n\t]\n): MySql2Database<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& MySql2DrizzleConfig<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({\n\t\t\t\turi: connection,\n\t\t\t})\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 MySql2DrizzleConfig<TSchema> | undefined) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<TSchema extends Record<string, unknown> = Record<string, never>>(\n\t\tconfig?: MySql2DrizzleConfig<TSchema>,\n\t): MySql2Database<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,SAAS,kBAAkB;AAE3B,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAE7B;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP,SAA6B,gBAAgB;AAC7C,SAAS,oBAAoB;AAE7B,SAAS,qBAAqB;AAMvB,MAAM,aAAa;AAAA,EAGzB,YACS,QACA,SACA,UAA8B,CAAC,GACtC;AAHO;AACA;AACA;AAAA,EAET;AAAA,EAPA,QAAiB,UAAU,IAAY;AA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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;AAAA,MACZ,KAAK;AAAA,IACN,CAAC,IACC,WAAW,UAAW;AACzB,UAAM,KAAK,UAAU,UAAU,aAAa;AAE5C,WAAO;AAAA,EACR;AAEA,SAAO,UAAU,OAAO,CAAC,GAAc,OAAO,CAAC,CAA6C;AAC7F;AAAA,CAEO,CAAUC,aAAV;AACC,WAAS,KACf,QAGC;AACD,WAAO,UAAU,CAAC,GAAU,MAAM;AAAA,EACnC;AANO,EAAAA,SAAS;AAAA,GADA;","names":["MySqlDatabase","drizzle"]}
|
package/mysql2/migrator.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mysql2/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/mysql2/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type { MySql2Database } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: MySql2Database<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tawait db.dialect.migrate(migrations, db.session, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAmC;AAGnC,eAAsB,QACrB,IACA,QACC;AACD,QAAM,iBAAa,oCAAmB,MAAM;AAC5C,QAAM,GAAG,QAAQ,QAAQ,YAAY,GAAG,SAAS,MAAM;AACxD;","names":[]}
|
package/mysql2/migrator.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { MigrationConfig } from "../migrator.cjs";
|
|
2
|
-
import type { AnyRelations } from "../relations.cjs";
|
|
3
2
|
import type { MySql2Database } from "./driver.cjs";
|
|
4
|
-
export declare function migrate<TSchema extends Record<string, unknown
|
|
3
|
+
export declare function migrate<TSchema extends Record<string, unknown>>(db: MySql2Database<TSchema>, config: MigrationConfig): Promise<void>;
|
package/mysql2/migrator.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { MigrationConfig } from "../migrator.js";
|
|
2
|
-
import type { AnyRelations } from "../relations.js";
|
|
3
2
|
import type { MySql2Database } from "./driver.js";
|
|
4
|
-
export declare function migrate<TSchema extends Record<string, unknown
|
|
3
|
+
export declare function migrate<TSchema extends Record<string, unknown>>(db: MySql2Database<TSchema>, config: MigrationConfig): Promise<void>;
|
package/mysql2/migrator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mysql2/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/mysql2/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type { MySql2Database } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: MySql2Database<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tawait db.dialect.migrate(migrations, db.session, config);\n}\n"],"mappings":"AACA,SAAS,0BAA0B;AAGnC,eAAsB,QACrB,IACA,QACC;AACD,QAAM,aAAa,mBAAmB,MAAM;AAC5C,QAAM,GAAG,QAAQ,QAAQ,YAAY,GAAG,SAAS,MAAM;AACxD;","names":[]}
|
package/mysql2/session.cjs
CHANGED
|
@@ -31,7 +31,7 @@ var import_session = require("../mysql-core/session.cjs");
|
|
|
31
31
|
var import_sql = require("../sql/sql.cjs");
|
|
32
32
|
var import_utils = require("../utils.cjs");
|
|
33
33
|
class MySql2PreparedQuery extends import_session.MySqlPreparedQuery {
|
|
34
|
-
constructor(client, queryString, params, logger, fields, customResultMapper, generatedIds, returningIds
|
|
34
|
+
constructor(client, queryString, params, logger, fields, customResultMapper, generatedIds, returningIds) {
|
|
35
35
|
super();
|
|
36
36
|
this.client = client;
|
|
37
37
|
this.params = params;
|
|
@@ -40,7 +40,6 @@ class MySql2PreparedQuery extends import_session.MySqlPreparedQuery {
|
|
|
40
40
|
this.customResultMapper = customResultMapper;
|
|
41
41
|
this.generatedIds = generatedIds;
|
|
42
42
|
this.returningIds = returningIds;
|
|
43
|
-
this.isRqbV2Query = isRqbV2Query;
|
|
44
43
|
this.rawQuery = {
|
|
45
44
|
sql: queryString,
|
|
46
45
|
// rowsAsArray: true,
|
|
@@ -66,8 +65,6 @@ class MySql2PreparedQuery extends import_session.MySqlPreparedQuery {
|
|
|
66
65
|
rawQuery;
|
|
67
66
|
query;
|
|
68
67
|
async execute(placeholderValues = {}) {
|
|
69
|
-
if (this.isRqbV2Query)
|
|
70
|
-
return this.executeRqbV2(placeholderValues);
|
|
71
68
|
const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);
|
|
72
69
|
this.logger.logQuery(this.rawQuery.sql, params);
|
|
73
70
|
const { fields, client, rawQuery, query, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } = this;
|
|
@@ -103,14 +100,6 @@ class MySql2PreparedQuery extends import_session.MySqlPreparedQuery {
|
|
|
103
100
|
}
|
|
104
101
|
return rows.map((row) => (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap));
|
|
105
102
|
}
|
|
106
|
-
async executeRqbV2(placeholderValues = {}) {
|
|
107
|
-
const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);
|
|
108
|
-
this.logger.logQuery(this.rawQuery.sql, params);
|
|
109
|
-
const { client, rawQuery, customResultMapper } = this;
|
|
110
|
-
const res = await client.query(rawQuery, params);
|
|
111
|
-
const rows = res[0];
|
|
112
|
-
return customResultMapper(rows);
|
|
113
|
-
}
|
|
114
103
|
async *iterator(placeholderValues = {}) {
|
|
115
104
|
const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);
|
|
116
105
|
const conn = (isPool(this.client) ? await this.client.getConnection() : this.client).connection;
|
|
@@ -154,10 +143,9 @@ class MySql2PreparedQuery extends import_session.MySqlPreparedQuery {
|
|
|
154
143
|
}
|
|
155
144
|
}
|
|
156
145
|
class MySql2Session extends import_session.MySqlSession {
|
|
157
|
-
constructor(client, dialect,
|
|
146
|
+
constructor(client, dialect, schema, options) {
|
|
158
147
|
super(dialect);
|
|
159
148
|
this.client = client;
|
|
160
|
-
this.relations = relations;
|
|
161
149
|
this.schema = schema;
|
|
162
150
|
this.options = options;
|
|
163
151
|
this.logger = options.logger ?? new import_logger.NoopLogger();
|
|
@@ -178,19 +166,6 @@ class MySql2Session extends import_session.MySqlSession {
|
|
|
178
166
|
returningIds
|
|
179
167
|
);
|
|
180
168
|
}
|
|
181
|
-
prepareRelationalQuery(query, fields, customResultMapper, generatedIds, returningIds) {
|
|
182
|
-
return new MySql2PreparedQuery(
|
|
183
|
-
this.client,
|
|
184
|
-
query.sql,
|
|
185
|
-
query.params,
|
|
186
|
-
this.logger,
|
|
187
|
-
fields,
|
|
188
|
-
customResultMapper,
|
|
189
|
-
generatedIds,
|
|
190
|
-
returningIds,
|
|
191
|
-
true
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
169
|
/**
|
|
195
170
|
* @internal
|
|
196
171
|
* What is its purpose?
|
|
@@ -219,14 +194,12 @@ class MySql2Session extends import_session.MySqlSession {
|
|
|
219
194
|
const session = isPool(this.client) ? new MySql2Session(
|
|
220
195
|
await this.client.getConnection(),
|
|
221
196
|
this.dialect,
|
|
222
|
-
this.relations,
|
|
223
197
|
this.schema,
|
|
224
198
|
this.options
|
|
225
199
|
) : this;
|
|
226
200
|
const tx = new MySql2Transaction(
|
|
227
201
|
this.dialect,
|
|
228
202
|
session,
|
|
229
|
-
this.relations,
|
|
230
203
|
this.schema,
|
|
231
204
|
0,
|
|
232
205
|
this.mode
|
|
@@ -262,7 +235,6 @@ class MySql2Transaction extends import_session.MySqlTransaction {
|
|
|
262
235
|
const tx = new MySql2Transaction(
|
|
263
236
|
this.dialect,
|
|
264
237
|
this.session,
|
|
265
|
-
this.relations,
|
|
266
238
|
this.schema,
|
|
267
239
|
this.nestedIndex + 1,
|
|
268
240
|
this.mode
|
package/mysql2/session.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mysql2/session.ts"],"sourcesContent":["import type { Connection as CallbackConnection } from 'mysql2';\nimport type {\n\tConnection,\n\tFieldPacket,\n\tOkPacket,\n\tPool,\n\tPoolConnection,\n\tQueryOptions,\n\tResultSetHeader,\n\tRowDataPacket,\n} from 'mysql2/promise';\nimport { once } from 'node:events';\nimport type * as V1 from '~/_relations.ts';\nimport { Column } from '~/column.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport type { MySqlDialect } from '~/mysql-core/dialect.ts';\nimport type { SelectedFieldsOrdered } from '~/mysql-core/query-builders/select.types.ts';\nimport {\n\ttype Mode,\n\tMySqlPreparedQuery,\n\ttype MySqlPreparedQueryConfig,\n\ttype MySqlPreparedQueryHKT,\n\ttype MySqlQueryResultHKT,\n\tMySqlSession,\n\tMySqlTransaction,\n\ttype MySqlTransactionConfig,\n\ttype PreparedQueryKind,\n} from '~/mysql-core/session.ts';\nimport type { AnyRelations, TablesRelationalConfig } from '~/relations.ts';\nimport { fillPlaceholders, sql } from '~/sql/sql.ts';\nimport type { Query, SQL } from '~/sql/sql.ts';\nimport { type Assume, mapResultRow } from '~/utils.ts';\n\nexport type MySql2Client = Pool | Connection;\n\nexport type MySqlRawQueryResult = [ResultSetHeader, FieldPacket[]];\nexport type MySqlQueryResultType = RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader;\nexport type MySqlQueryResult<\n\tT = any,\n> = [T extends ResultSetHeader ? T : T[], FieldPacket[]];\n\nexport class MySql2PreparedQuery<T extends MySqlPreparedQueryConfig, TIsRqbV2 extends boolean = false>\n\textends MySqlPreparedQuery<T>\n{\n\tstatic override readonly [entityKind]: string = 'MySql2PreparedQuery';\n\n\tprivate rawQuery: QueryOptions;\n\tprivate query: QueryOptions;\n\n\tconstructor(\n\t\tprivate client: MySql2Client,\n\t\tqueryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tprivate customResultMapper?: (\n\t\t\trows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][],\n\t\t) => T['execute'],\n\t\t// Keys that were used in $default and the value that was generated for them\n\t\tprivate generatedIds?: Record<string, unknown>[],\n\t\t// Keys that should be returned, it has the column with all properries + key from object\n\t\tprivate returningIds?: SelectedFieldsOrdered,\n\t\tprivate isRqbV2Query?: TIsRqbV2,\n\t) {\n\t\tsuper();\n\t\tthis.rawQuery = {\n\t\t\tsql: queryString,\n\t\t\t// rowsAsArray: true,\n\t\t\ttypeCast: function(field: any, next: any) {\n\t\t\t\tif (field.type === 'TIMESTAMP' || field.type === 'DATETIME' || field.type === 'DATE') {\n\t\t\t\t\treturn field.string();\n\t\t\t\t}\n\t\t\t\treturn next();\n\t\t\t},\n\t\t};\n\t\tthis.query = {\n\t\t\tsql: queryString,\n\t\t\trowsAsArray: true,\n\t\t\ttypeCast: function(field: any, next: any) {\n\t\t\t\tif (field.type === 'TIMESTAMP' || field.type === 'DATETIME' || field.type === 'DATE') {\n\t\t\t\t\treturn field.string();\n\t\t\t\t}\n\t\t\t\treturn next();\n\t\t\t},\n\t\t};\n\t}\n\n\tasync execute(placeholderValues: Record<string, unknown> = {}): Promise<T['execute']> {\n\t\tif (this.isRqbV2Query) return this.executeRqbV2(placeholderValues);\n\n\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\n\t\tthis.logger.logQuery(this.rawQuery.sql, params);\n\n\t\tconst { fields, client, rawQuery, query, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } =\n\t\t\tthis;\n\t\tif (!fields && !customResultMapper) {\n\t\t\tconst res = await client.query<any>(rawQuery, params);\n\t\t\tconst insertId = res[0].insertId;\n\t\t\tconst affectedRows = res[0].affectedRows;\n\t\t\t// for each row, I need to check keys from\n\t\t\tif (returningIds) {\n\t\t\t\tconst returningResponse = [];\n\t\t\t\tlet j = 0;\n\t\t\t\tfor (let i = insertId; i < insertId + affectedRows; i++) {\n\t\t\t\t\tfor (const column of returningIds) {\n\t\t\t\t\t\tconst key = returningIds[0]!.path[0]!;\n\t\t\t\t\t\tif (is(column.field, Column)) {\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\tif (column.field.primary && column.field.autoIncrement) {\n\t\t\t\t\t\t\t\treturningResponse.push({ [key]: i });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (column.field.defaultFn && generatedIds) {\n\t\t\t\t\t\t\t\t// generatedIds[rowIdx][key]\n\t\t\t\t\t\t\t\treturningResponse.push({ [key]: generatedIds[j]![key] });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tj++;\n\t\t\t\t}\n\n\t\t\t\treturn returningResponse;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tconst result = await client.query<any[]>(query, params);\n\t\tconst rows = result[0];\n\n\t\tif (customResultMapper) {\n\t\t\treturn customResultMapper(rows);\n\t\t}\n\n\t\treturn rows.map((row) => mapResultRow<T['execute']>(fields!, row, joinsNotNullableMap));\n\t}\n\n\tprivate async executeRqbV2(placeholderValues: Record<string, unknown> = {}): Promise<T['execute']> {\n\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\n\t\tthis.logger.logQuery(this.rawQuery.sql, params);\n\n\t\tconst { client, rawQuery, customResultMapper } = this;\n\t\tconst res = await client.query<any>(rawQuery, params);\n\n\t\tconst rows = res[0];\n\n\t\treturn (customResultMapper as (rows: Record<string, unknown>[]) => T['execute'])(rows);\n\t}\n\n\tasync *iterator(\n\t\tplaceholderValues: Record<string, unknown> = {},\n\t): AsyncGenerator<T['execute'] extends any[] ? T['execute'][number] : T['execute']> {\n\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\t\tconst conn = ((isPool(this.client) ? await this.client.getConnection() : this.client) as {} as {\n\t\t\tconnection: CallbackConnection;\n\t\t}).connection;\n\n\t\tconst { fields, query, rawQuery, joinsNotNullableMap, client, customResultMapper } = this;\n\t\tconst hasRowsMapper = Boolean(fields || customResultMapper);\n\t\tconst driverQuery = hasRowsMapper ? conn.query(query, params) : conn.query(rawQuery, params);\n\n\t\tconst stream = driverQuery.stream();\n\n\t\tfunction dataListener() {\n\t\t\tstream.pause();\n\t\t}\n\n\t\tstream.on('data', dataListener);\n\n\t\ttry {\n\t\t\tconst onEnd = once(stream, 'end');\n\t\t\tconst onError = once(stream, 'error');\n\n\t\t\twhile (true) {\n\t\t\t\tstream.resume();\n\t\t\t\tconst row = await Promise.race([onEnd, onError, new Promise((resolve) => stream.once('data', resolve))]);\n\t\t\t\tif (row === undefined || (Array.isArray(row) && row.length === 0)) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else if (row instanceof Error) { // eslint-disable-line no-instanceof/no-instanceof\n\t\t\t\t\tthrow row;\n\t\t\t\t} else {\n\t\t\t\t\tif (hasRowsMapper) {\n\t\t\t\t\t\tif (customResultMapper) {\n\t\t\t\t\t\t\tconst mappedRow = (customResultMapper as (rows: unknown[][]) => T['execute'])([row as unknown[]]);\n\t\t\t\t\t\t\tyield (Array.isArray(mappedRow) ? mappedRow[0] : mappedRow);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tyield mapResultRow(fields!, row as unknown[], joinsNotNullableMap);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tyield row as T['execute'];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tstream.off('data', dataListener);\n\t\t\tif (isPool(client)) {\n\t\t\t\tconn.end();\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport interface MySql2SessionOptions {\n\tlogger?: Logger;\n\tmode: Mode;\n}\n\nexport class MySql2Session<\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends MySqlSession<MySqlQueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TRelations, TTablesConfig, TSchema> {\n\tstatic override readonly [entityKind]: string = 'MySql2Session';\n\n\tprivate logger: Logger;\n\tprivate mode: Mode;\n\n\tconstructor(\n\t\tprivate client: MySql2Client,\n\t\tdialect: MySqlDialect,\n\t\tprivate relations: AnyRelations | undefined,\n\t\tprivate schema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: MySql2SessionOptions,\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t\tthis.mode = options.mode;\n\t}\n\n\tprepareQuery<T extends MySqlPreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tcustomResultMapper?: (rows: unknown[][]) => T['execute'],\n\t\tgeneratedIds?: Record<string, unknown>[],\n\t\treturningIds?: SelectedFieldsOrdered,\n\t): PreparedQueryKind<MySql2PreparedQueryHKT, T> {\n\t\t// Add returningId fields\n\t\t// Each driver gets them from response from database\n\t\treturn new MySql2PreparedQuery(\n\t\t\tthis.client,\n\t\t\tquery.sql,\n\t\t\tquery.params,\n\t\t\tthis.logger,\n\t\t\tfields,\n\t\t\tcustomResultMapper,\n\t\t\tgeneratedIds,\n\t\t\treturningIds,\n\t\t) as PreparedQueryKind<MySql2PreparedQueryHKT, T>;\n\t}\n\n\tprepareRelationalQuery<T extends MySqlPreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tcustomResultMapper: (rows: Record<string, unknown>[]) => T['execute'],\n\t\tgeneratedIds?: Record<string, unknown>[],\n\t\treturningIds?: SelectedFieldsOrdered,\n\t): PreparedQueryKind<MySql2PreparedQueryHKT, T> {\n\t\t// Add returningId fields\n\t\t// Each driver gets them from response from database\n\t\treturn new MySql2PreparedQuery(\n\t\t\tthis.client,\n\t\t\tquery.sql,\n\t\t\tquery.params,\n\t\t\tthis.logger,\n\t\t\tfields,\n\t\t\tcustomResultMapper,\n\t\t\tgeneratedIds,\n\t\t\treturningIds,\n\t\t\ttrue,\n\t\t) as any;\n\t}\n\n\t/**\n\t * @internal\n\t * What is its purpose?\n\t */\n\tasync query(query: string, params: unknown[]): Promise<MySqlQueryResult> {\n\t\tthis.logger.logQuery(query, params);\n\t\tconst result = await this.client.query({\n\t\t\tsql: query,\n\t\t\tvalues: params,\n\t\t\trowsAsArray: true,\n\t\t\ttypeCast: function(field: any, next: any) {\n\t\t\t\tif (field.type === 'TIMESTAMP' || field.type === 'DATETIME' || field.type === 'DATE') {\n\t\t\t\t\treturn field.string();\n\t\t\t\t}\n\t\t\t\treturn next();\n\t\t\t},\n\t\t});\n\t\treturn result;\n\t}\n\n\toverride all<T = unknown>(query: SQL): Promise<T[]> {\n\t\tconst querySql = this.dialect.sqlToQuery(query);\n\t\tthis.logger.logQuery(querySql.sql, querySql.params);\n\t\treturn this.client.execute(querySql.sql, querySql.params).then((result) => result[0]) as Promise<T[]>;\n\t}\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: MySql2Transaction<TFullSchema, TRelations, TTablesConfig, TSchema>) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\tconst session = isPool(this.client)\n\t\t\t? new MySql2Session(\n\t\t\t\tawait this.client.getConnection(),\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.relations,\n\t\t\t\tthis.schema,\n\t\t\t\tthis.options,\n\t\t\t)\n\t\t\t: this;\n\t\tconst tx = new MySql2Transaction<TFullSchema, TRelations, TTablesConfig, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tsession as MySqlSession<any, any, any, any, any, any>,\n\t\t\tthis.relations,\n\t\t\tthis.schema,\n\t\t\t0,\n\t\t\tthis.mode,\n\t\t);\n\t\tif (config) {\n\t\t\tconst setTransactionConfigSql = this.getSetTransactionSQL(config);\n\t\t\tif (setTransactionConfigSql) {\n\t\t\t\tawait tx.execute(setTransactionConfigSql);\n\t\t\t}\n\t\t\tconst startTransactionSql = this.getStartTransactionSQL(config);\n\t\t\tawait (startTransactionSql ? tx.execute(startTransactionSql) : tx.execute(sql`begin`));\n\t\t} else {\n\t\t\tawait tx.execute(sql`begin`);\n\t\t}\n\t\ttry {\n\t\t\tconst result = await transaction(tx);\n\t\t\tawait tx.execute(sql`commit`);\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tawait tx.execute(sql`rollback`);\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\tif (isPool(this.client)) {\n\t\t\t\t(session.client as PoolConnection).release();\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class MySql2Transaction<\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends MySqlTransaction<\n\tMySql2QueryResultHKT,\n\tMySql2PreparedQueryHKT,\n\tTFullSchema,\n\tTRelations,\n\tTTablesConfig,\n\tTSchema\n> {\n\tstatic override readonly [entityKind]: string = 'MySql2Transaction';\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: MySql2Transaction<TFullSchema, TRelations, TTablesConfig, TSchema>) => Promise<T>,\n\t): Promise<T> {\n\t\tconst savepointName = `sp${this.nestedIndex + 1}`;\n\t\tconst tx = new MySql2Transaction<TFullSchema, TRelations, TTablesConfig, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis.relations,\n\t\t\tthis.schema,\n\t\t\tthis.nestedIndex + 1,\n\t\t\tthis.mode,\n\t\t);\n\t\tawait tx.execute(sql.raw(`savepoint ${savepointName}`));\n\t\ttry {\n\t\t\tconst result = await transaction(tx);\n\t\t\tawait tx.execute(sql.raw(`release savepoint ${savepointName}`));\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tawait tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n\nfunction isPool(client: MySql2Client): client is Pool {\n\treturn 'getConnection' in client;\n}\n\nexport interface MySql2QueryResultHKT extends MySqlQueryResultHKT {\n\ttype: MySqlRawQueryResult;\n}\n\nexport interface MySql2PreparedQueryHKT extends MySqlPreparedQueryHKT {\n\ttype: MySql2PreparedQuery<Assume<this['config'], MySqlPreparedQueryConfig>>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,yBAAqB;AAErB,oBAAuB;AACvB,oBAA+B;AAE/B,oBAA2B;AAG3B,qBAUO;AAEP,iBAAsC;AAEtC,mBAA0C;AAUnC,MAAM,4BACJ,kCACT;AAAA,EAMC,YACS,QACR,aACQ,QACA,QACA,QACA,oBAIA,cAEA,cACA,cACP;AACD,UAAM;AAdE;AAEA;AACA;AACA;AACA;AAIA;AAEA;AACA;AAGR,SAAK,WAAW;AAAA,MACf,KAAK;AAAA;AAAA,MAEL,UAAU,SAAS,OAAY,MAAW;AACzC,YAAI,MAAM,SAAS,eAAe,MAAM,SAAS,cAAc,MAAM,SAAS,QAAQ;AACrF,iBAAO,MAAM,OAAO;AAAA,QACrB;AACA,eAAO,KAAK;AAAA,MACb;AAAA,IACD;AACA,SAAK,QAAQ;AAAA,MACZ,KA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AM,GAAG,QAAQ,qBAAU;AAAA,IAC5B;AACA,QAAI;AACH,YAAM,SAAS,MAAM,YAAY,EAAE;AACnC,YAAM,GAAG,QAAQ,sBAAW;AAC5B,aAAO;AAAA,IACR,SAAS,KAAK;AACb,YAAM,GAAG,QAAQ,wBAAa;AAC9B,YAAM;AAAA,IACP,UAAE;AACD,UAAI,OAAO,KAAK,MAAM,GAAG;AACxB,QAAC,QAAQ,OAA0B,QAAQ;AAAA,MAC5C;AAAA,IACD;AAAA,EACD;AACD;AAEO,MAAM,0BAKH,gCAOR;AAAA,EACD,QAA0B,wBAAU,IAAY;AAAA,EAEhD,MAAe,YACd,aACa;AACb,UAAM,gBAAgB,KAAK,KAAK,cAAc,CAAC;AAC/C,UAAM,KAAK,IAAI;AAAA,MACd,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,cAAc;AAAA,MACnB,KAAK;AAAA,IACN;AACA,UAAM,GAAG,QAAQ,eAAI,IAAI,aAAa,aAAa,EAAE,CAAC;AACtD,QAAI;AACH,YAAM,SAAS,MAAM,YAAY,EAAE;AACnC,YAAM,GAAG,QAAQ,eAAI,IAAI,qBAAqB,aAAa,EAAE,CAAC;AAC9D,aAAO;AAAA,IACR,SAAS,KAAK;AACb,YAAM,GAAG,QAAQ,eAAI,IAAI,yBAAyB,aAAa,EAAE,CAAC;AAClE,YAAM;AAAA,IACP;AAAA,EACD;AACD;AAEA,SAAS,OAAO,QAAsC;AACrD,SAAO,mBAAmB;AAC3B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/mysql2/session.ts"],"sourcesContent":["import type { Connection as CallbackConnection } from 'mysql2';\nimport type {\n\tConnection,\n\tFieldPacket,\n\tOkPacket,\n\tPool,\n\tPoolConnection,\n\tQueryOptions,\n\tResultSetHeader,\n\tRowDataPacket,\n} from 'mysql2/promise';\nimport { once } from 'node:events';\nimport { Column } from '~/column.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport type { MySqlDialect } from '~/mysql-core/dialect.ts';\nimport type { SelectedFieldsOrdered } from '~/mysql-core/query-builders/select.types.ts';\nimport {\n\ttype Mode,\n\tMySqlPreparedQuery,\n\ttype MySqlPreparedQueryConfig,\n\ttype MySqlPreparedQueryHKT,\n\ttype MySqlQueryResultHKT,\n\tMySqlSession,\n\tMySqlTransaction,\n\ttype MySqlTransactionConfig,\n\ttype PreparedQueryKind,\n} from '~/mysql-core/session.ts';\nimport type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { fillPlaceholders, sql } from '~/sql/sql.ts';\nimport type { Query, SQL } from '~/sql/sql.ts';\nimport { type Assume, mapResultRow } from '~/utils.ts';\n\nexport type MySql2Client = Pool | Connection;\n\nexport type MySqlRawQueryResult = [ResultSetHeader, FieldPacket[]];\nexport type MySqlQueryResultType = RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader;\nexport type MySqlQueryResult<\n\tT = any,\n> = [T extends ResultSetHeader ? T : T[], FieldPacket[]];\n\nexport class MySql2PreparedQuery<T extends MySqlPreparedQueryConfig> extends MySqlPreparedQuery<T> {\n\tstatic override readonly [entityKind]: string = 'MySql2PreparedQuery';\n\n\tprivate rawQuery: QueryOptions;\n\tprivate query: QueryOptions;\n\n\tconstructor(\n\t\tprivate client: MySql2Client,\n\t\tqueryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tprivate customResultMapper?: (rows: unknown[][]) => T['execute'],\n\t\t// Keys that were used in $default and the value that was generated for them\n\t\tprivate generatedIds?: Record<string, unknown>[],\n\t\t// Keys that should be returned, it has the column with all properries + key from object\n\t\tprivate returningIds?: SelectedFieldsOrdered,\n\t) {\n\t\tsuper();\n\t\tthis.rawQuery = {\n\t\t\tsql: queryString,\n\t\t\t// rowsAsArray: true,\n\t\t\ttypeCast: function(field: any, next: any) {\n\t\t\t\tif (field.type === 'TIMESTAMP' || field.type === 'DATETIME' || field.type === 'DATE') {\n\t\t\t\t\treturn field.string();\n\t\t\t\t}\n\t\t\t\treturn next();\n\t\t\t},\n\t\t};\n\t\tthis.query = {\n\t\t\tsql: queryString,\n\t\t\trowsAsArray: true,\n\t\t\ttypeCast: function(field: any, next: any) {\n\t\t\t\tif (field.type === 'TIMESTAMP' || field.type === 'DATETIME' || field.type === 'DATE') {\n\t\t\t\t\treturn field.string();\n\t\t\t\t}\n\t\t\t\treturn next();\n\t\t\t},\n\t\t};\n\t}\n\n\tasync execute(placeholderValues: Record<string, unknown> = {}): Promise<T['execute']> {\n\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\n\t\tthis.logger.logQuery(this.rawQuery.sql, params);\n\n\t\tconst { fields, client, rawQuery, query, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } =\n\t\t\tthis;\n\t\tif (!fields && !customResultMapper) {\n\t\t\tconst res = await client.query<any>(rawQuery, params);\n\t\t\tconst insertId = res[0].insertId;\n\t\t\tconst affectedRows = res[0].affectedRows;\n\t\t\t// for each row, I need to check keys from\n\t\t\tif (returningIds) {\n\t\t\t\tconst returningResponse = [];\n\t\t\t\tlet j = 0;\n\t\t\t\tfor (let i = insertId; i < insertId + affectedRows; i++) {\n\t\t\t\t\tfor (const column of returningIds) {\n\t\t\t\t\t\tconst key = returningIds[0]!.path[0]!;\n\t\t\t\t\t\tif (is(column.field, Column)) {\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\tif (column.field.primary && column.field.autoIncrement) {\n\t\t\t\t\t\t\t\treturningResponse.push({ [key]: i });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (column.field.defaultFn && generatedIds) {\n\t\t\t\t\t\t\t\t// generatedIds[rowIdx][key]\n\t\t\t\t\t\t\t\treturningResponse.push({ [key]: generatedIds[j]![key] });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tj++;\n\t\t\t\t}\n\n\t\t\t\treturn returningResponse;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tconst result = await client.query<any[]>(query, params);\n\t\tconst rows = result[0];\n\n\t\tif (customResultMapper) {\n\t\t\treturn customResultMapper(rows);\n\t\t}\n\n\t\treturn rows.map((row) => mapResultRow<T['execute']>(fields!, row, joinsNotNullableMap));\n\t}\n\n\tasync *iterator(\n\t\tplaceholderValues: Record<string, unknown> = {},\n\t): AsyncGenerator<T['execute'] extends any[] ? T['execute'][number] : T['execute']> {\n\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\t\tconst conn = ((isPool(this.client) ? await this.client.getConnection() : this.client) as {} as {\n\t\t\tconnection: CallbackConnection;\n\t\t}).connection;\n\n\t\tconst { fields, query, rawQuery, joinsNotNullableMap, client, customResultMapper } = this;\n\t\tconst hasRowsMapper = Boolean(fields || customResultMapper);\n\t\tconst driverQuery = hasRowsMapper ? conn.query(query, params) : conn.query(rawQuery, params);\n\n\t\tconst stream = driverQuery.stream();\n\n\t\tfunction dataListener() {\n\t\t\tstream.pause();\n\t\t}\n\n\t\tstream.on('data', dataListener);\n\n\t\ttry {\n\t\t\tconst onEnd = once(stream, 'end');\n\t\t\tconst onError = once(stream, 'error');\n\n\t\t\twhile (true) {\n\t\t\t\tstream.resume();\n\t\t\t\tconst row = await Promise.race([onEnd, onError, new Promise((resolve) => stream.once('data', resolve))]);\n\t\t\t\tif (row === undefined || (Array.isArray(row) && row.length === 0)) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else if (row instanceof Error) { // eslint-disable-line no-instanceof/no-instanceof\n\t\t\t\t\tthrow row;\n\t\t\t\t} else {\n\t\t\t\t\tif (hasRowsMapper) {\n\t\t\t\t\t\tif (customResultMapper) {\n\t\t\t\t\t\t\tconst mappedRow = customResultMapper([row as unknown[]]);\n\t\t\t\t\t\t\tyield (Array.isArray(mappedRow) ? mappedRow[0] : mappedRow);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tyield mapResultRow(fields!, row as unknown[], joinsNotNullableMap);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tyield row as T['execute'];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tstream.off('data', dataListener);\n\t\t\tif (isPool(client)) {\n\t\t\t\tconn.end();\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport interface MySql2SessionOptions {\n\tlogger?: Logger;\n\tmode: Mode;\n}\n\nexport class MySql2Session<\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n> extends MySqlSession<MySqlQueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'MySql2Session';\n\n\tprivate logger: Logger;\n\tprivate mode: Mode;\n\n\tconstructor(\n\t\tprivate client: MySql2Client,\n\t\tdialect: MySqlDialect,\n\t\tprivate schema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: MySql2SessionOptions,\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t\tthis.mode = options.mode;\n\t}\n\n\tprepareQuery<T extends MySqlPreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tcustomResultMapper?: (rows: unknown[][]) => T['execute'],\n\t\tgeneratedIds?: Record<string, unknown>[],\n\t\treturningIds?: SelectedFieldsOrdered,\n\t): PreparedQueryKind<MySql2PreparedQueryHKT, T> {\n\t\t// Add returningId fields\n\t\t// Each driver gets them from response from database\n\t\treturn new MySql2PreparedQuery(\n\t\t\tthis.client,\n\t\t\tquery.sql,\n\t\t\tquery.params,\n\t\t\tthis.logger,\n\t\t\tfields,\n\t\t\tcustomResultMapper,\n\t\t\tgeneratedIds,\n\t\t\treturningIds,\n\t\t) as PreparedQueryKind<MySql2PreparedQueryHKT, T>;\n\t}\n\n\t/**\n\t * @internal\n\t * What is its purpose?\n\t */\n\tasync query(query: string, params: unknown[]): Promise<MySqlQueryResult> {\n\t\tthis.logger.logQuery(query, params);\n\t\tconst result = await this.client.query({\n\t\t\tsql: query,\n\t\t\tvalues: params,\n\t\t\trowsAsArray: true,\n\t\t\ttypeCast: function(field: any, next: any) {\n\t\t\t\tif (field.type === 'TIMESTAMP' || field.type === 'DATETIME' || field.type === 'DATE') {\n\t\t\t\t\treturn field.string();\n\t\t\t\t}\n\t\t\t\treturn next();\n\t\t\t},\n\t\t});\n\t\treturn result;\n\t}\n\n\toverride all<T = unknown>(query: SQL): Promise<T[]> {\n\t\tconst querySql = this.dialect.sqlToQuery(query);\n\t\tthis.logger.logQuery(querySql.sql, querySql.params);\n\t\treturn this.client.execute(querySql.sql, querySql.params).then((result) => result[0]) as Promise<T[]>;\n\t}\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\tconst session = isPool(this.client)\n\t\t\t? new MySql2Session(\n\t\t\t\tawait this.client.getConnection(),\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.schema,\n\t\t\t\tthis.options,\n\t\t\t)\n\t\t\t: this;\n\t\tconst tx = new MySql2Transaction<TFullSchema, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tsession as MySqlSession<any, any, any, any>,\n\t\t\tthis.schema,\n\t\t\t0,\n\t\t\tthis.mode,\n\t\t);\n\t\tif (config) {\n\t\t\tconst setTransactionConfigSql = this.getSetTransactionSQL(config);\n\t\t\tif (setTransactionConfigSql) {\n\t\t\t\tawait tx.execute(setTransactionConfigSql);\n\t\t\t}\n\t\t\tconst startTransactionSql = this.getStartTransactionSQL(config);\n\t\t\tawait (startTransactionSql ? tx.execute(startTransactionSql) : tx.execute(sql`begin`));\n\t\t} else {\n\t\t\tawait tx.execute(sql`begin`);\n\t\t}\n\t\ttry {\n\t\t\tconst result = await transaction(tx);\n\t\t\tawait tx.execute(sql`commit`);\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tawait tx.execute(sql`rollback`);\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\tif (isPool(this.client)) {\n\t\t\t\t(session.client as PoolConnection).release();\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class MySql2Transaction<\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n> extends MySqlTransaction<MySql2QueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'MySql2Transaction';\n\n\toverride async transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {\n\t\tconst savepointName = `sp${this.nestedIndex + 1}`;\n\t\tconst tx = new MySql2Transaction<TFullSchema, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis.schema,\n\t\t\tthis.nestedIndex + 1,\n\t\t\tthis.mode,\n\t\t);\n\t\tawait tx.execute(sql.raw(`savepoint ${savepointName}`));\n\t\ttry {\n\t\t\tconst result = await transaction(tx);\n\t\t\tawait tx.execute(sql.raw(`release savepoint ${savepointName}`));\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tawait tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n\nfunction isPool(client: MySql2Client): client is Pool {\n\treturn 'getConnection' in client;\n}\n\nexport interface MySql2QueryResultHKT extends MySqlQueryResultHKT {\n\ttype: MySqlRawQueryResult;\n}\n\nexport interface MySql2PreparedQueryHKT extends MySqlPreparedQueryHKT {\n\ttype: MySql2PreparedQuery<Assume<this['config'], MySqlPreparedQueryConfig>>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,yBAAqB;AACrB,oBAAuB;AACvB,oBAA+B;AAE/B,oBAA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AQ,wBAAa;AAC9B,YAAM;AAAA,IACP,UAAE;AACD,UAAI,OAAO,KAAK,MAAM,GAAG;AACxB,QAAC,QAAQ,OAA0B,QAAQ;AAAA,MAC5C;AAAA,IACD;AAAA,EACD;AACD;AAEO,MAAM,0BAGH,gCAAqF;AAAA,EAC9F,QAA0B,wBAAU,IAAY;AAAA,EAEhD,MAAe,YAAe,aAAsF;AACnH,UAAM,gBAAgB,KAAK,KAAK,cAAc,CAAC;AAC/C,UAAM,KAAK,IAAI;AAAA,MACd,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,cAAc;AAAA,MACnB,KAAK;AAAA,IACN;AACA,UAAM,GAAG,QAAQ,eAAI,IAAI,aAAa,aAAa,EAAE,CAAC;AACtD,QAAI;AACH,YAAM,SAAS,MAAM,YAAY,EAAE;AACnC,YAAM,GAAG,QAAQ,eAAI,IAAI,qBAAqB,aAAa,EAAE,CAAC;AAC9D,aAAO;AAAA,IACR,SAAS,KAAK;AACb,YAAM,GAAG,QAAQ,eAAI,IAAI,yBAAyB,aAAa,EAAE,CAAC;AAClE,YAAM;AAAA,IACP;AAAA,EACD;AACD;AAEA,SAAS,OAAO,QAAsC;AACrD,SAAO,mBAAmB;AAC3B;","names":[]}
|
package/mysql2/session.d.cts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type { Connection, FieldPacket, OkPacket, Pool, ResultSetHeader, RowDataPacket } from 'mysql2/promise';
|
|
2
|
-
import type * as V1 from "../_relations.cjs";
|
|
3
2
|
import { entityKind } from "../entity.cjs";
|
|
4
3
|
import type { Logger } from "../logger.cjs";
|
|
5
4
|
import type { MySqlDialect } from "../mysql-core/dialect.cjs";
|
|
6
5
|
import type { SelectedFieldsOrdered } from "../mysql-core/query-builders/select.types.cjs";
|
|
7
6
|
import { type Mode, MySqlPreparedQuery, type MySqlPreparedQueryConfig, type MySqlPreparedQueryHKT, type MySqlQueryResultHKT, MySqlSession, MySqlTransaction, type MySqlTransactionConfig, type PreparedQueryKind } from "../mysql-core/session.cjs";
|
|
8
|
-
import type {
|
|
7
|
+
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
|
|
9
8
|
import type { Query, SQL } from "../sql/sql.cjs";
|
|
10
9
|
import { type Assume } from "../utils.cjs";
|
|
11
10
|
export type MySql2Client = Pool | Connection;
|
|
12
11
|
export type MySqlRawQueryResult = [ResultSetHeader, FieldPacket[]];
|
|
13
12
|
export type MySqlQueryResultType = RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader;
|
|
14
13
|
export type MySqlQueryResult<T = any> = [T extends ResultSetHeader ? T : T[], FieldPacket[]];
|
|
15
|
-
export declare class MySql2PreparedQuery<T extends MySqlPreparedQueryConfig
|
|
14
|
+
export declare class MySql2PreparedQuery<T extends MySqlPreparedQueryConfig> extends MySqlPreparedQuery<T> {
|
|
16
15
|
private client;
|
|
17
16
|
private params;
|
|
18
17
|
private logger;
|
|
@@ -20,36 +19,32 @@ export declare class MySql2PreparedQuery<T extends MySqlPreparedQueryConfig, TIs
|
|
|
20
19
|
private customResultMapper?;
|
|
21
20
|
private generatedIds?;
|
|
22
21
|
private returningIds?;
|
|
23
|
-
private isRqbV2Query?;
|
|
24
22
|
static readonly [entityKind]: string;
|
|
25
23
|
private rawQuery;
|
|
26
24
|
private query;
|
|
27
|
-
constructor(client: MySql2Client, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, customResultMapper?: ((rows:
|
|
25
|
+
constructor(client: MySql2Client, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, customResultMapper?: ((rows: unknown[][]) => T["execute"]) | undefined, generatedIds?: Record<string, unknown>[] | undefined, returningIds?: SelectedFieldsOrdered | undefined);
|
|
28
26
|
execute(placeholderValues?: Record<string, unknown>): Promise<T['execute']>;
|
|
29
|
-
private executeRqbV2;
|
|
30
27
|
iterator(placeholderValues?: Record<string, unknown>): AsyncGenerator<T['execute'] extends any[] ? T['execute'][number] : T['execute']>;
|
|
31
28
|
}
|
|
32
29
|
export interface MySql2SessionOptions {
|
|
33
30
|
logger?: Logger;
|
|
34
31
|
mode: Mode;
|
|
35
32
|
}
|
|
36
|
-
export declare class MySql2Session<TFullSchema extends Record<string, unknown>,
|
|
33
|
+
export declare class MySql2Session<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends MySqlSession<MySqlQueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TSchema> {
|
|
37
34
|
private client;
|
|
38
|
-
private relations;
|
|
39
35
|
private schema;
|
|
40
36
|
private options;
|
|
41
37
|
static readonly [entityKind]: string;
|
|
42
38
|
private logger;
|
|
43
39
|
private mode;
|
|
44
|
-
constructor(client: MySql2Client, dialect: MySqlDialect,
|
|
40
|
+
constructor(client: MySql2Client, dialect: MySqlDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options: MySql2SessionOptions);
|
|
45
41
|
prepareQuery<T extends MySqlPreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, customResultMapper?: (rows: unknown[][]) => T['execute'], generatedIds?: Record<string, unknown>[], returningIds?: SelectedFieldsOrdered): PreparedQueryKind<MySql2PreparedQueryHKT, T>;
|
|
46
|
-
prepareRelationalQuery<T extends MySqlPreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, customResultMapper: (rows: Record<string, unknown>[]) => T['execute'], generatedIds?: Record<string, unknown>[], returningIds?: SelectedFieldsOrdered): PreparedQueryKind<MySql2PreparedQueryHKT, T>;
|
|
47
42
|
all<T = unknown>(query: SQL): Promise<T[]>;
|
|
48
|
-
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema,
|
|
43
|
+
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>, config?: MySqlTransactionConfig): Promise<T>;
|
|
49
44
|
}
|
|
50
|
-
export declare class MySql2Transaction<TFullSchema extends Record<string, unknown>,
|
|
45
|
+
export declare class MySql2Transaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends MySqlTransaction<MySql2QueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TSchema> {
|
|
51
46
|
static readonly [entityKind]: string;
|
|
52
|
-
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema,
|
|
47
|
+
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
|
53
48
|
}
|
|
54
49
|
export interface MySql2QueryResultHKT extends MySqlQueryResultHKT {
|
|
55
50
|
type: MySqlRawQueryResult;
|
package/mysql2/session.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type { Connection, FieldPacket, OkPacket, Pool, ResultSetHeader, RowDataPacket } from 'mysql2/promise';
|
|
2
|
-
import type * as V1 from "../_relations.js";
|
|
3
2
|
import { entityKind } from "../entity.js";
|
|
4
3
|
import type { Logger } from "../logger.js";
|
|
5
4
|
import type { MySqlDialect } from "../mysql-core/dialect.js";
|
|
6
5
|
import type { SelectedFieldsOrdered } from "../mysql-core/query-builders/select.types.js";
|
|
7
6
|
import { type Mode, MySqlPreparedQuery, type MySqlPreparedQueryConfig, type MySqlPreparedQueryHKT, type MySqlQueryResultHKT, MySqlSession, MySqlTransaction, type MySqlTransactionConfig, type PreparedQueryKind } from "../mysql-core/session.js";
|
|
8
|
-
import type {
|
|
7
|
+
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
|
|
9
8
|
import type { Query, SQL } from "../sql/sql.js";
|
|
10
9
|
import { type Assume } from "../utils.js";
|
|
11
10
|
export type MySql2Client = Pool | Connection;
|
|
12
11
|
export type MySqlRawQueryResult = [ResultSetHeader, FieldPacket[]];
|
|
13
12
|
export type MySqlQueryResultType = RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader;
|
|
14
13
|
export type MySqlQueryResult<T = any> = [T extends ResultSetHeader ? T : T[], FieldPacket[]];
|
|
15
|
-
export declare class MySql2PreparedQuery<T extends MySqlPreparedQueryConfig
|
|
14
|
+
export declare class MySql2PreparedQuery<T extends MySqlPreparedQueryConfig> extends MySqlPreparedQuery<T> {
|
|
16
15
|
private client;
|
|
17
16
|
private params;
|
|
18
17
|
private logger;
|
|
@@ -20,36 +19,32 @@ export declare class MySql2PreparedQuery<T extends MySqlPreparedQueryConfig, TIs
|
|
|
20
19
|
private customResultMapper?;
|
|
21
20
|
private generatedIds?;
|
|
22
21
|
private returningIds?;
|
|
23
|
-
private isRqbV2Query?;
|
|
24
22
|
static readonly [entityKind]: string;
|
|
25
23
|
private rawQuery;
|
|
26
24
|
private query;
|
|
27
|
-
constructor(client: MySql2Client, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, customResultMapper?: ((rows:
|
|
25
|
+
constructor(client: MySql2Client, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, customResultMapper?: ((rows: unknown[][]) => T["execute"]) | undefined, generatedIds?: Record<string, unknown>[] | undefined, returningIds?: SelectedFieldsOrdered | undefined);
|
|
28
26
|
execute(placeholderValues?: Record<string, unknown>): Promise<T['execute']>;
|
|
29
|
-
private executeRqbV2;
|
|
30
27
|
iterator(placeholderValues?: Record<string, unknown>): AsyncGenerator<T['execute'] extends any[] ? T['execute'][number] : T['execute']>;
|
|
31
28
|
}
|
|
32
29
|
export interface MySql2SessionOptions {
|
|
33
30
|
logger?: Logger;
|
|
34
31
|
mode: Mode;
|
|
35
32
|
}
|
|
36
|
-
export declare class MySql2Session<TFullSchema extends Record<string, unknown>,
|
|
33
|
+
export declare class MySql2Session<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends MySqlSession<MySqlQueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TSchema> {
|
|
37
34
|
private client;
|
|
38
|
-
private relations;
|
|
39
35
|
private schema;
|
|
40
36
|
private options;
|
|
41
37
|
static readonly [entityKind]: string;
|
|
42
38
|
private logger;
|
|
43
39
|
private mode;
|
|
44
|
-
constructor(client: MySql2Client, dialect: MySqlDialect,
|
|
40
|
+
constructor(client: MySql2Client, dialect: MySqlDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options: MySql2SessionOptions);
|
|
45
41
|
prepareQuery<T extends MySqlPreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, customResultMapper?: (rows: unknown[][]) => T['execute'], generatedIds?: Record<string, unknown>[], returningIds?: SelectedFieldsOrdered): PreparedQueryKind<MySql2PreparedQueryHKT, T>;
|
|
46
|
-
prepareRelationalQuery<T extends MySqlPreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, customResultMapper: (rows: Record<string, unknown>[]) => T['execute'], generatedIds?: Record<string, unknown>[], returningIds?: SelectedFieldsOrdered): PreparedQueryKind<MySql2PreparedQueryHKT, T>;
|
|
47
42
|
all<T = unknown>(query: SQL): Promise<T[]>;
|
|
48
|
-
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema,
|
|
43
|
+
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>, config?: MySqlTransactionConfig): Promise<T>;
|
|
49
44
|
}
|
|
50
|
-
export declare class MySql2Transaction<TFullSchema extends Record<string, unknown>,
|
|
45
|
+
export declare class MySql2Transaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends MySqlTransaction<MySql2QueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TSchema> {
|
|
51
46
|
static readonly [entityKind]: string;
|
|
52
|
-
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema,
|
|
47
|
+
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
|
53
48
|
}
|
|
54
49
|
export interface MySql2QueryResultHKT extends MySqlQueryResultHKT {
|
|
55
50
|
type: MySqlRawQueryResult;
|
package/mysql2/session.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import { fillPlaceholders, sql } from "../sql/sql.js";
|
|
11
11
|
import { mapResultRow } from "../utils.js";
|
|
12
12
|
class MySql2PreparedQuery extends MySqlPreparedQuery {
|
|
13
|
-
constructor(client, queryString, params, logger, fields, customResultMapper, generatedIds, returningIds
|
|
13
|
+
constructor(client, queryString, params, logger, fields, customResultMapper, generatedIds, returningIds) {
|
|
14
14
|
super();
|
|
15
15
|
this.client = client;
|
|
16
16
|
this.params = params;
|
|
@@ -19,7 +19,6 @@ class MySql2PreparedQuery extends MySqlPreparedQuery {
|
|
|
19
19
|
this.customResultMapper = customResultMapper;
|
|
20
20
|
this.generatedIds = generatedIds;
|
|
21
21
|
this.returningIds = returningIds;
|
|
22
|
-
this.isRqbV2Query = isRqbV2Query;
|
|
23
22
|
this.rawQuery = {
|
|
24
23
|
sql: queryString,
|
|
25
24
|
// rowsAsArray: true,
|
|
@@ -45,8 +44,6 @@ class MySql2PreparedQuery extends MySqlPreparedQuery {
|
|
|
45
44
|
rawQuery;
|
|
46
45
|
query;
|
|
47
46
|
async execute(placeholderValues = {}) {
|
|
48
|
-
if (this.isRqbV2Query)
|
|
49
|
-
return this.executeRqbV2(placeholderValues);
|
|
50
47
|
const params = fillPlaceholders(this.params, placeholderValues);
|
|
51
48
|
this.logger.logQuery(this.rawQuery.sql, params);
|
|
52
49
|
const { fields, client, rawQuery, query, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } = this;
|
|
@@ -82,14 +79,6 @@ class MySql2PreparedQuery extends MySqlPreparedQuery {
|
|
|
82
79
|
}
|
|
83
80
|
return rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
84
81
|
}
|
|
85
|
-
async executeRqbV2(placeholderValues = {}) {
|
|
86
|
-
const params = fillPlaceholders(this.params, placeholderValues);
|
|
87
|
-
this.logger.logQuery(this.rawQuery.sql, params);
|
|
88
|
-
const { client, rawQuery, customResultMapper } = this;
|
|
89
|
-
const res = await client.query(rawQuery, params);
|
|
90
|
-
const rows = res[0];
|
|
91
|
-
return customResultMapper(rows);
|
|
92
|
-
}
|
|
93
82
|
async *iterator(placeholderValues = {}) {
|
|
94
83
|
const params = fillPlaceholders(this.params, placeholderValues);
|
|
95
84
|
const conn = (isPool(this.client) ? await this.client.getConnection() : this.client).connection;
|
|
@@ -133,10 +122,9 @@ class MySql2PreparedQuery extends MySqlPreparedQuery {
|
|
|
133
122
|
}
|
|
134
123
|
}
|
|
135
124
|
class MySql2Session extends MySqlSession {
|
|
136
|
-
constructor(client, dialect,
|
|
125
|
+
constructor(client, dialect, schema, options) {
|
|
137
126
|
super(dialect);
|
|
138
127
|
this.client = client;
|
|
139
|
-
this.relations = relations;
|
|
140
128
|
this.schema = schema;
|
|
141
129
|
this.options = options;
|
|
142
130
|
this.logger = options.logger ?? new NoopLogger();
|
|
@@ -157,19 +145,6 @@ class MySql2Session extends MySqlSession {
|
|
|
157
145
|
returningIds
|
|
158
146
|
);
|
|
159
147
|
}
|
|
160
|
-
prepareRelationalQuery(query, fields, customResultMapper, generatedIds, returningIds) {
|
|
161
|
-
return new MySql2PreparedQuery(
|
|
162
|
-
this.client,
|
|
163
|
-
query.sql,
|
|
164
|
-
query.params,
|
|
165
|
-
this.logger,
|
|
166
|
-
fields,
|
|
167
|
-
customResultMapper,
|
|
168
|
-
generatedIds,
|
|
169
|
-
returningIds,
|
|
170
|
-
true
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
148
|
/**
|
|
174
149
|
* @internal
|
|
175
150
|
* What is its purpose?
|
|
@@ -198,14 +173,12 @@ class MySql2Session extends MySqlSession {
|
|
|
198
173
|
const session = isPool(this.client) ? new MySql2Session(
|
|
199
174
|
await this.client.getConnection(),
|
|
200
175
|
this.dialect,
|
|
201
|
-
this.relations,
|
|
202
176
|
this.schema,
|
|
203
177
|
this.options
|
|
204
178
|
) : this;
|
|
205
179
|
const tx = new MySql2Transaction(
|
|
206
180
|
this.dialect,
|
|
207
181
|
session,
|
|
208
|
-
this.relations,
|
|
209
182
|
this.schema,
|
|
210
183
|
0,
|
|
211
184
|
this.mode
|
|
@@ -241,7 +214,6 @@ class MySql2Transaction extends MySqlTransaction {
|
|
|
241
214
|
const tx = new MySql2Transaction(
|
|
242
215
|
this.dialect,
|
|
243
216
|
this.session,
|
|
244
|
-
this.relations,
|
|
245
217
|
this.schema,
|
|
246
218
|
this.nestedIndex + 1,
|
|
247
219
|
this.mode
|