drizzle-orm 0.40.0 → 1.0.0-beta.1-e30ede4
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/_relations.cjs +328 -0
- package/_relations.cjs.map +1 -0
- package/_relations.d.cts +215 -0
- package/_relations.d.ts +215 -0
- package/_relations.js +316 -0
- package/_relations.js.map +1 -0
- 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 +19 -5
- package/aws-data-api/pg/driver.cjs.map +1 -1
- package/aws-data-api/pg/driver.d.cts +9 -8
- package/aws-data-api/pg/driver.d.ts +9 -8
- package/aws-data-api/pg/driver.js +9 -8
- 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 +2 -1
- package/aws-data-api/pg/migrator.d.ts +2 -1
- package/aws-data-api/pg/migrator.js.map +1 -1
- package/aws-data-api/pg/session.cjs +67 -4
- package/aws-data-api/pg/session.cjs.map +1 -1
- package/aws-data-api/pg/session.d.cts +13 -8
- package/aws-data-api/pg/session.d.ts +13 -8
- package/aws-data-api/pg/session.js +67 -4
- package/aws-data-api/pg/session.js.map +1 -1
- package/better-sqlite3/driver.cjs +12 -5
- package/better-sqlite3/driver.cjs.map +1 -1
- package/better-sqlite3/driver.d.cts +7 -6
- package/better-sqlite3/driver.d.ts +7 -6
- package/better-sqlite3/driver.js +12 -8
- package/better-sqlite3/driver.js.map +1 -1
- package/better-sqlite3/migrator.cjs.map +1 -1
- package/better-sqlite3/migrator.d.cts +2 -1
- package/better-sqlite3/migrator.d.ts +2 -1
- package/better-sqlite3/migrator.js.map +1 -1
- package/better-sqlite3/session.cjs +49 -4
- package/better-sqlite3/session.cjs.map +1 -1
- package/better-sqlite3/session.d.cts +14 -8
- package/better-sqlite3/session.d.ts +14 -8
- package/better-sqlite3/session.js +49 -4
- package/better-sqlite3/session.js.map +1 -1
- package/bun-sql/driver.cjs +16 -5
- package/bun-sql/driver.cjs.map +1 -1
- package/bun-sql/driver.d.cts +7 -6
- package/bun-sql/driver.d.ts +7 -6
- package/bun-sql/driver.js +6 -8
- package/bun-sql/driver.js.map +1 -1
- package/bun-sql/migrator.cjs.map +1 -1
- package/bun-sql/migrator.d.cts +2 -1
- package/bun-sql/migrator.d.ts +2 -1
- package/bun-sql/migrator.js.map +1 -1
- package/bun-sql/session.cjs +50 -6
- package/bun-sql/session.cjs.map +1 -1
- package/bun-sql/session.d.cts +14 -9
- package/bun-sql/session.d.ts +14 -9
- package/bun-sql/session.js +50 -6
- package/bun-sql/session.js.map +1 -1
- package/bun-sqlite/driver.cjs +22 -5
- package/bun-sqlite/driver.cjs.map +1 -1
- package/bun-sqlite/driver.d.cts +7 -6
- package/bun-sqlite/driver.d.ts +7 -6
- package/bun-sqlite/driver.js +12 -8
- package/bun-sqlite/driver.js.map +1 -1
- package/bun-sqlite/migrator.cjs.map +1 -1
- package/bun-sqlite/migrator.d.cts +2 -1
- package/bun-sqlite/migrator.d.ts +2 -1
- package/bun-sqlite/migrator.js.map +1 -1
- package/bun-sqlite/session.cjs +49 -4
- package/bun-sqlite/session.cjs.map +1 -1
- package/bun-sqlite/session.d.cts +14 -8
- package/bun-sqlite/session.d.ts +14 -8
- package/bun-sqlite/session.js +49 -4
- package/bun-sqlite/session.js.map +1 -1
- package/casing.cjs +3 -0
- package/casing.cjs.map +1 -1
- package/casing.d.cts +1 -1
- package/casing.d.ts +1 -1
- package/casing.js +4 -1
- package/casing.js.map +1 -1
- package/d1/driver.cjs +22 -5
- package/d1/driver.cjs.map +1 -1
- package/d1/driver.d.cts +3 -2
- package/d1/driver.d.ts +3 -2
- package/d1/driver.js +12 -8
- package/d1/driver.js.map +1 -1
- package/d1/migrator.cjs.map +1 -1
- package/d1/migrator.d.cts +2 -1
- package/d1/migrator.d.ts +2 -1
- package/d1/migrator.js.map +1 -1
- package/d1/session.cjs +50 -8
- package/d1/session.cjs.map +1 -1
- package/d1/session.d.cts +15 -8
- package/d1/session.d.ts +15 -8
- package/d1/session.js +50 -8
- package/d1/session.js.map +1 -1
- package/durable-sqlite/driver.cjs +16 -5
- package/durable-sqlite/driver.cjs.map +1 -1
- package/durable-sqlite/driver.d.cts +3 -2
- package/durable-sqlite/driver.d.ts +3 -2
- package/durable-sqlite/driver.js +6 -8
- package/durable-sqlite/driver.js.map +1 -1
- package/durable-sqlite/migrator.cjs.map +1 -1
- package/durable-sqlite/migrator.d.cts +2 -1
- package/durable-sqlite/migrator.d.ts +2 -1
- package/durable-sqlite/migrator.js.map +1 -1
- package/durable-sqlite/session.cjs +46 -4
- package/durable-sqlite/session.cjs.map +1 -1
- package/durable-sqlite/session.d.cts +14 -8
- package/durable-sqlite/session.d.ts +14 -8
- package/durable-sqlite/session.js +46 -4
- package/durable-sqlite/session.js.map +1 -1
- package/expo-sqlite/driver.cjs +22 -5
- package/expo-sqlite/driver.cjs.map +1 -1
- package/expo-sqlite/driver.d.cts +3 -2
- package/expo-sqlite/driver.d.ts +3 -2
- package/expo-sqlite/driver.js +12 -8
- package/expo-sqlite/driver.js.map +1 -1
- package/expo-sqlite/migrator.cjs.map +1 -1
- package/expo-sqlite/migrator.d.cts +3 -2
- package/expo-sqlite/migrator.d.ts +3 -2
- package/expo-sqlite/migrator.js.map +1 -1
- package/expo-sqlite/query.cjs +13 -2
- package/expo-sqlite/query.cjs.map +1 -1
- package/expo-sqlite/query.d.cts +2 -1
- package/expo-sqlite/query.d.ts +2 -1
- package/expo-sqlite/query.js +3 -2
- package/expo-sqlite/query.js.map +1 -1
- package/expo-sqlite/session.cjs +47 -4
- package/expo-sqlite/session.cjs.map +1 -1
- package/expo-sqlite/session.d.cts +14 -8
- package/expo-sqlite/session.d.ts +14 -8
- package/expo-sqlite/session.js +47 -4
- package/expo-sqlite/session.js.map +1 -1
- package/gel/driver.cjs +17 -6
- package/gel/driver.cjs.map +1 -1
- package/gel/driver.d.cts +8 -7
- package/gel/driver.d.ts +8 -7
- package/gel/driver.js +7 -9
- package/gel/driver.js.map +1 -1
- package/gel/migrator.cjs.map +1 -1
- package/gel/migrator.d.cts +1 -1
- package/gel/migrator.d.ts +1 -1
- package/gel/migrator.js.map +1 -1
- package/gel/session.cjs +46 -4
- package/gel/session.cjs.map +1 -1
- package/gel/session.d.cts +13 -8
- package/gel/session.d.ts +13 -8
- package/gel/session.js +46 -4
- package/gel/session.js.map +1 -1
- package/gel-core/columns/timestamptz.cjs +5 -0
- package/gel-core/columns/timestamptz.cjs.map +1 -1
- package/gel-core/columns/timestamptz.d.cts +1 -0
- package/gel-core/columns/timestamptz.d.ts +1 -0
- package/gel-core/columns/timestamptz.js +5 -0
- package/gel-core/columns/timestamptz.js.map +1 -1
- package/gel-core/db.cjs +28 -4
- package/gel-core/db.cjs.map +1 -1
- package/gel-core/db.d.cts +16 -9
- package/gel-core/db.d.ts +16 -9
- package/gel-core/db.js +27 -3
- package/gel-core/db.js.map +1 -1
- package/gel-core/dialect.cjs +172 -488
- package/gel-core/dialect.cjs.map +1 -1
- package/gel-core/dialect.d.cts +26 -8
- package/gel-core/dialect.d.ts +26 -8
- package/gel-core/dialect.js +170 -495
- package/gel-core/dialect.js.map +1 -1
- package/gel-core/query-builders/_query.cjs +149 -0
- package/gel-core/query-builders/_query.cjs.map +1 -0
- package/gel-core/query-builders/_query.d.cts +46 -0
- package/gel-core/query-builders/_query.d.ts +46 -0
- package/gel-core/query-builders/_query.js +114 -0
- package/gel-core/query-builders/_query.js.map +1 -0
- package/gel-core/query-builders/query.cjs +27 -24
- package/gel-core/query-builders/query.cjs.map +1 -1
- package/gel-core/query-builders/query.d.cts +9 -8
- package/gel-core/query-builders/query.d.ts +9 -8
- package/gel-core/query-builders/query.js +26 -23
- package/gel-core/query-builders/query.js.map +1 -1
- package/gel-core/session.cjs +3 -2
- package/gel-core/session.cjs.map +1 -1
- package/gel-core/session.d.cts +9 -6
- package/gel-core/session.d.ts +9 -6
- package/gel-core/session.js +3 -2
- package/gel-core/session.js.map +1 -1
- package/libsql/driver-core.cjs +22 -5
- package/libsql/driver-core.cjs.map +1 -1
- package/libsql/driver-core.d.cts +2 -1
- package/libsql/driver-core.d.ts +2 -1
- package/libsql/driver-core.js +12 -8
- package/libsql/driver-core.js.map +1 -1
- package/libsql/driver.cjs.map +1 -1
- package/libsql/driver.d.cts +6 -5
- package/libsql/driver.d.ts +6 -5
- package/libsql/driver.js.map +1 -1
- package/libsql/http/index.cjs.map +1 -1
- package/libsql/http/index.d.cts +6 -5
- package/libsql/http/index.d.ts +6 -5
- package/libsql/http/index.js.map +1 -1
- package/libsql/migrator.cjs.map +1 -1
- package/libsql/migrator.d.cts +2 -1
- package/libsql/migrator.d.ts +2 -1
- package/libsql/migrator.js.map +1 -1
- package/libsql/node/index.cjs.map +1 -1
- package/libsql/node/index.d.cts +6 -5
- package/libsql/node/index.d.ts +6 -5
- package/libsql/node/index.js.map +1 -1
- package/libsql/session.cjs +56 -4
- package/libsql/session.cjs.map +1 -1
- package/libsql/session.d.cts +15 -9
- package/libsql/session.d.ts +15 -9
- package/libsql/session.js +56 -4
- package/libsql/session.js.map +1 -1
- package/libsql/sqlite3/index.cjs.map +1 -1
- package/libsql/sqlite3/index.d.cts +6 -5
- package/libsql/sqlite3/index.d.ts +6 -5
- package/libsql/sqlite3/index.js.map +1 -1
- package/libsql/wasm/index.cjs.map +1 -1
- package/libsql/wasm/index.d.cts +6 -5
- package/libsql/wasm/index.d.ts +6 -5
- package/libsql/wasm/index.js.map +1 -1
- package/libsql/web/index.cjs.map +1 -1
- package/libsql/web/index.d.cts +6 -5
- package/libsql/web/index.d.ts +6 -5
- package/libsql/web/index.js.map +1 -1
- package/libsql/ws/index.cjs.map +1 -1
- package/libsql/ws/index.d.cts +6 -5
- package/libsql/ws/index.d.ts +6 -5
- package/libsql/ws/index.js.map +1 -1
- package/mysql-core/columns/binary.cjs +11 -0
- package/mysql-core/columns/binary.cjs.map +1 -1
- package/mysql-core/columns/binary.d.cts +1 -0
- package/mysql-core/columns/binary.d.ts +1 -0
- package/mysql-core/columns/binary.js +11 -0
- package/mysql-core/columns/binary.js.map +1 -1
- package/mysql-core/columns/decimal.cjs +5 -0
- package/mysql-core/columns/decimal.cjs.map +1 -1
- package/mysql-core/columns/decimal.d.cts +1 -0
- package/mysql-core/columns/decimal.d.ts +1 -0
- package/mysql-core/columns/decimal.js +5 -0
- package/mysql-core/columns/decimal.js.map +1 -1
- package/mysql-core/columns/float.cjs +6 -0
- package/mysql-core/columns/float.cjs.map +1 -1
- package/mysql-core/columns/float.d.cts +1 -0
- package/mysql-core/columns/float.d.ts +1 -0
- package/mysql-core/columns/float.js +6 -0
- package/mysql-core/columns/float.js.map +1 -1
- package/mysql-core/columns/varbinary.cjs +11 -0
- package/mysql-core/columns/varbinary.cjs.map +1 -1
- package/mysql-core/columns/varbinary.d.cts +1 -0
- package/mysql-core/columns/varbinary.d.ts +1 -0
- package/mysql-core/columns/varbinary.js +11 -0
- package/mysql-core/columns/varbinary.js.map +1 -1
- package/mysql-core/columns/varchar.cjs.map +1 -1
- package/mysql-core/columns/varchar.d.cts +1 -1
- package/mysql-core/columns/varchar.d.ts +1 -1
- package/mysql-core/columns/varchar.js.map +1 -1
- package/mysql-core/db.cjs +30 -6
- package/mysql-core/db.cjs.map +1 -1
- package/mysql-core/db.d.cts +15 -8
- package/mysql-core/db.d.ts +15 -8
- package/mysql-core/db.js +29 -5
- package/mysql-core/db.js.map +1 -1
- package/mysql-core/dialect.cjs +208 -15
- package/mysql-core/dialect.cjs.map +1 -1
- package/mysql-core/dialect.d.cts +36 -13
- package/mysql-core/dialect.d.ts +36 -13
- package/mysql-core/dialect.js +206 -22
- package/mysql-core/dialect.js.map +1 -1
- package/mysql-core/query-builders/_query.cjs +149 -0
- package/mysql-core/query-builders/_query.cjs.map +1 -0
- package/mysql-core/query-builders/_query.d.cts +44 -0
- package/mysql-core/query-builders/_query.d.ts +44 -0
- package/mysql-core/query-builders/_query.js +114 -0
- package/mysql-core/query-builders/_query.js.map +1 -0
- 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 +18 -31
- package/mysql-core/query-builders/query.cjs.map +1 -1
- package/mysql-core/query-builders/query.d.cts +8 -10
- package/mysql-core/query-builders/query.d.ts +8 -10
- package/mysql-core/query-builders/query.js +18 -31
- package/mysql-core/query-builders/query.js.map +1 -1
- package/mysql-core/session.cjs +3 -2
- package/mysql-core/session.cjs.map +1 -1
- package/mysql-core/session.d.cts +10 -7
- package/mysql-core/session.d.ts +10 -7
- package/mysql-core/session.js +3 -2
- package/mysql-core/session.js.map +1 -1
- package/mysql-proxy/driver.cjs +22 -5
- package/mysql-proxy/driver.cjs.map +1 -1
- package/mysql-proxy/driver.d.cts +3 -2
- package/mysql-proxy/driver.d.ts +3 -2
- package/mysql-proxy/driver.js +12 -8
- package/mysql-proxy/driver.js.map +1 -1
- package/mysql-proxy/migrator.cjs.map +1 -1
- package/mysql-proxy/migrator.d.cts +2 -1
- package/mysql-proxy/migrator.d.ts +2 -1
- package/mysql-proxy/migrator.js.map +1 -1
- package/mysql-proxy/session.cjs +27 -2
- package/mysql-proxy/session.cjs.map +1 -1
- package/mysql-proxy/session.d.cts +13 -8
- package/mysql-proxy/session.d.ts +13 -8
- package/mysql-proxy/session.js +27 -2
- package/mysql-proxy/session.js.map +1 -1
- package/mysql2/driver.cjs +24 -7
- package/mysql2/driver.cjs.map +1 -1
- package/mysql2/driver.d.cts +10 -9
- package/mysql2/driver.d.ts +10 -9
- package/mysql2/driver.js +14 -10
- package/mysql2/driver.js.map +1 -1
- package/mysql2/migrator.cjs.map +1 -1
- package/mysql2/migrator.d.cts +2 -1
- package/mysql2/migrator.d.ts +2 -1
- package/mysql2/migrator.js.map +1 -1
- package/mysql2/session.cjs +30 -2
- package/mysql2/session.cjs.map +1 -1
- package/mysql2/session.d.cts +13 -8
- package/mysql2/session.d.ts +13 -8
- package/mysql2/session.js +30 -2
- package/mysql2/session.js.map +1 -1
- package/neon-http/driver.cjs +21 -7
- package/neon-http/driver.cjs.map +1 -1
- package/neon-http/driver.d.cts +10 -9
- package/neon-http/driver.d.ts +10 -9
- package/neon-http/driver.js +11 -7
- package/neon-http/driver.js.map +1 -1
- package/neon-http/migrator.cjs.map +1 -1
- package/neon-http/migrator.d.cts +2 -1
- package/neon-http/migrator.d.ts +2 -1
- package/neon-http/migrator.js.map +1 -1
- package/neon-http/session.cjs +32 -2
- package/neon-http/session.cjs.map +1 -1
- package/neon-http/session.d.cts +13 -8
- package/neon-http/session.d.ts +13 -8
- package/neon-http/session.js +32 -2
- package/neon-http/session.js.map +1 -1
- package/neon-serverless/driver.cjs +18 -7
- package/neon-serverless/driver.cjs.map +1 -1
- package/neon-serverless/driver.d.cts +9 -8
- package/neon-serverless/driver.d.ts +9 -8
- package/neon-serverless/driver.js +8 -10
- package/neon-serverless/driver.js.map +1 -1
- package/neon-serverless/migrator.cjs.map +1 -1
- package/neon-serverless/migrator.d.cts +2 -1
- package/neon-serverless/migrator.d.ts +2 -1
- package/neon-serverless/migrator.js.map +1 -1
- package/neon-serverless/session.cjs +64 -5
- package/neon-serverless/session.cjs.map +1 -1
- package/neon-serverless/session.d.cts +13 -8
- package/neon-serverless/session.d.ts +13 -8
- package/neon-serverless/session.js +64 -5
- package/neon-serverless/session.js.map +1 -1
- package/node-postgres/driver.cjs +13 -7
- package/node-postgres/driver.cjs.map +1 -1
- package/node-postgres/driver.d.cts +9 -8
- package/node-postgres/driver.d.ts +9 -8
- package/node-postgres/driver.js +13 -10
- package/node-postgres/driver.js.map +1 -1
- package/node-postgres/migrator.cjs.map +1 -1
- package/node-postgres/migrator.d.cts +2 -1
- package/node-postgres/migrator.d.ts +2 -1
- package/node-postgres/migrator.js.map +1 -1
- package/node-postgres/session.cjs +69 -4
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.d.cts +13 -8
- package/node-postgres/session.d.ts +13 -8
- package/node-postgres/session.js +69 -4
- package/node-postgres/session.js.map +1 -1
- package/op-sqlite/driver.cjs +22 -5
- package/op-sqlite/driver.cjs.map +1 -1
- package/op-sqlite/driver.d.cts +3 -2
- package/op-sqlite/driver.d.ts +3 -2
- package/op-sqlite/driver.js +12 -8
- package/op-sqlite/driver.js.map +1 -1
- package/op-sqlite/migrator.cjs.map +1 -1
- package/op-sqlite/migrator.d.cts +3 -2
- package/op-sqlite/migrator.d.ts +3 -2
- package/op-sqlite/migrator.js.map +1 -1
- package/op-sqlite/session.cjs +47 -4
- package/op-sqlite/session.cjs.map +1 -1
- package/op-sqlite/session.d.cts +14 -8
- package/op-sqlite/session.d.ts +14 -8
- package/op-sqlite/session.js +47 -4
- package/op-sqlite/session.js.map +1 -1
- package/package.json +63 -3
- package/pg-core/columns/numeric.cjs +5 -0
- package/pg-core/columns/numeric.cjs.map +1 -1
- package/pg-core/columns/numeric.d.cts +1 -0
- package/pg-core/columns/numeric.d.ts +1 -0
- package/pg-core/columns/numeric.js +5 -0
- package/pg-core/columns/numeric.js.map +1 -1
- package/pg-core/columns/postgis_extension/geometry.cjs +2 -0
- package/pg-core/columns/postgis_extension/geometry.cjs.map +1 -1
- package/pg-core/columns/postgis_extension/geometry.d.cts +1 -1
- package/pg-core/columns/postgis_extension/geometry.d.ts +1 -1
- package/pg-core/columns/postgis_extension/geometry.js +2 -0
- package/pg-core/columns/postgis_extension/geometry.js.map +1 -1
- package/pg-core/db.cjs +32 -5
- package/pg-core/db.cjs.map +1 -1
- package/pg-core/db.d.cts +16 -9
- package/pg-core/db.d.ts +16 -9
- package/pg-core/db.js +31 -4
- package/pg-core/db.js.map +1 -1
- package/pg-core/dialect.cjs +190 -488
- package/pg-core/dialect.cjs.map +1 -1
- package/pg-core/dialect.d.cts +27 -8
- package/pg-core/dialect.d.ts +27 -8
- package/pg-core/dialect.js +189 -495
- package/pg-core/dialect.js.map +1 -1
- package/pg-core/query-builders/_query.cjs +155 -0
- package/pg-core/query-builders/_query.cjs.map +1 -0
- package/pg-core/query-builders/_query.d.cts +47 -0
- package/pg-core/query-builders/_query.d.ts +47 -0
- package/pg-core/query-builders/_query.js +120 -0
- package/pg-core/query-builders/_query.js.map +1 -0
- 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 +15 -18
- 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 +15 -18
- package/pg-core/query-builders/query.js.map +1 -1
- package/pg-core/session.cjs +3 -2
- package/pg-core/session.cjs.map +1 -1
- package/pg-core/session.d.cts +9 -6
- package/pg-core/session.d.ts +9 -6
- package/pg-core/session.js +3 -2
- package/pg-core/session.js.map +1 -1
- package/pg-proxy/driver.cjs +21 -5
- package/pg-proxy/driver.cjs.map +1 -1
- package/pg-proxy/driver.d.cts +3 -2
- package/pg-proxy/driver.d.ts +3 -2
- package/pg-proxy/driver.js +11 -8
- package/pg-proxy/driver.js.map +1 -1
- package/pg-proxy/migrator.cjs.map +1 -1
- package/pg-proxy/migrator.d.cts +2 -1
- package/pg-proxy/migrator.d.ts +2 -1
- package/pg-proxy/migrator.js.map +1 -1
- package/pg-proxy/session.cjs +37 -2
- package/pg-proxy/session.cjs.map +1 -1
- package/pg-proxy/session.d.cts +13 -8
- package/pg-proxy/session.d.ts +13 -8
- package/pg-proxy/session.js +37 -2
- package/pg-proxy/session.js.map +1 -1
- package/pglite/driver.cjs +23 -7
- package/pglite/driver.cjs.map +1 -1
- package/pglite/driver.d.cts +9 -8
- package/pglite/driver.d.ts +9 -8
- package/pglite/driver.js +13 -10
- package/pglite/driver.js.map +1 -1
- package/pglite/migrator.cjs.map +1 -1
- package/pglite/migrator.d.cts +2 -1
- package/pglite/migrator.d.ts +2 -1
- package/pglite/migrator.js.map +1 -1
- package/pglite/session.cjs +48 -5
- package/pglite/session.cjs.map +1 -1
- package/pglite/session.d.cts +13 -8
- package/pglite/session.d.ts +13 -8
- package/pglite/session.js +48 -5
- package/pglite/session.js.map +1 -1
- package/planetscale-serverless/driver.cjs +22 -5
- package/planetscale-serverless/driver.cjs.map +1 -1
- package/planetscale-serverless/driver.d.cts +7 -6
- package/planetscale-serverless/driver.d.ts +7 -6
- package/planetscale-serverless/driver.js +12 -8
- package/planetscale-serverless/driver.js.map +1 -1
- package/planetscale-serverless/migrator.cjs.map +1 -1
- package/planetscale-serverless/migrator.d.cts +2 -1
- package/planetscale-serverless/migrator.d.ts +2 -1
- package/planetscale-serverless/migrator.js.map +1 -1
- package/planetscale-serverless/session.cjs +45 -5
- package/planetscale-serverless/session.cjs.map +1 -1
- package/planetscale-serverless/session.d.cts +14 -9
- package/planetscale-serverless/session.d.ts +14 -9
- package/planetscale-serverless/session.js +45 -5
- package/planetscale-serverless/session.js.map +1 -1
- package/postgres-js/driver.cjs +7 -6
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.d.cts +7 -6
- package/postgres-js/driver.d.ts +7 -6
- package/postgres-js/driver.js +7 -9
- package/postgres-js/driver.js.map +1 -1
- package/postgres-js/migrator.cjs.map +1 -1
- package/postgres-js/migrator.d.cts +2 -1
- package/postgres-js/migrator.d.ts +2 -1
- package/postgres-js/migrator.js.map +1 -1
- package/postgres-js/session.cjs +51 -6
- package/postgres-js/session.cjs.map +1 -1
- package/postgres-js/session.d.cts +15 -9
- package/postgres-js/session.d.ts +15 -9
- package/postgres-js/session.js +51 -6
- 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 +3 -0
- package/prisma/mysql/session.cjs.map +1 -1
- package/prisma/mysql/session.d.cts +3 -1
- package/prisma/mysql/session.d.ts +3 -1
- package/prisma/mysql/session.js +3 -0
- 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 +3 -0
- package/prisma/pg/session.cjs.map +1 -1
- package/prisma/pg/session.d.cts +3 -1
- package/prisma/pg/session.d.ts +3 -1
- package/prisma/pg/session.js +3 -0
- 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 +3 -0
- package/prisma/sqlite/session.cjs.map +1 -1
- package/prisma/sqlite/session.d.cts +4 -2
- package/prisma/sqlite/session.d.ts +4 -2
- package/prisma/sqlite/session.js +3 -0
- package/prisma/sqlite/session.js.map +1 -1
- package/relations.cjs +657 -245
- package/relations.cjs.map +1 -1
- package/relations.d.cts +339 -140
- package/relations.d.ts +339 -140
- package/relations.js +643 -240
- 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 +16 -6
- 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 +6 -12
- package/singlestore-core/dialect.js.map +1 -1
- package/singlestore-core/query-builders/query.cjs +12 -2
- 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 +2 -4
- 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 +21 -0
- 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 +22 -1
- package/sql/sql.js.map +1 -1
- package/sql-js/driver.cjs +16 -5
- package/sql-js/driver.cjs.map +1 -1
- package/sql-js/driver.d.cts +3 -2
- package/sql-js/driver.d.ts +3 -2
- package/sql-js/driver.js +6 -8
- package/sql-js/driver.js.map +1 -1
- package/sql-js/migrator.cjs.map +1 -1
- package/sql-js/migrator.d.cts +2 -1
- package/sql-js/migrator.d.ts +2 -1
- package/sql-js/migrator.js.map +1 -1
- package/sql-js/session.cjs +71 -36
- package/sql-js/session.cjs.map +1 -1
- package/sql-js/session.d.cts +16 -13
- package/sql-js/session.d.ts +16 -13
- package/sql-js/session.js +71 -36
- package/sql-js/session.js.map +1 -1
- package/sqlite-core/columns/blob.cjs +12 -0
- package/sqlite-core/columns/blob.cjs.map +1 -1
- package/sqlite-core/columns/blob.d.cts +2 -1
- package/sqlite-core/columns/blob.d.ts +2 -1
- package/sqlite-core/columns/blob.js +12 -0
- package/sqlite-core/columns/blob.js.map +1 -1
- package/sqlite-core/db.cjs +39 -12
- package/sqlite-core/db.cjs.map +1 -1
- package/sqlite-core/db.d.cts +16 -8
- package/sqlite-core/db.d.ts +16 -8
- package/sqlite-core/db.js +38 -11
- package/sqlite-core/db.js.map +1 -1
- package/sqlite-core/dialect.cjs +193 -7
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.d.cts +31 -9
- package/sqlite-core/dialect.d.ts +31 -9
- package/sqlite-core/dialect.js +191 -14
- package/sqlite-core/dialect.js.map +1 -1
- package/sqlite-core/query-builders/_query.cjs +187 -0
- package/sqlite-core/query-builders/_query.cjs.map +1 -0
- package/sqlite-core/query-builders/_query.d.cts +55 -0
- package/sqlite-core/query-builders/_query.d.ts +55 -0
- package/sqlite-core/query-builders/_query.js +151 -0
- package/sqlite-core/query-builders/_query.js.map +1 -0
- 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 +56 -35
- package/sqlite-core/query-builders/query.cjs.map +1 -1
- package/sqlite-core/query-builders/query.d.cts +18 -17
- package/sqlite-core/query-builders/query.d.ts +18 -17
- package/sqlite-core/query-builders/query.js +56 -35
- 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 +6 -2
- package/sqlite-core/session.cjs.map +1 -1
- package/sqlite-core/session.d.cts +15 -7
- package/sqlite-core/session.d.ts +15 -7
- package/sqlite-core/session.js +6 -2
- package/sqlite-core/session.js.map +1 -1
- package/sqlite-proxy/driver.cjs +23 -5
- package/sqlite-proxy/driver.cjs.map +1 -1
- package/sqlite-proxy/driver.d.cts +4 -3
- package/sqlite-proxy/driver.d.ts +4 -3
- package/sqlite-proxy/driver.js +13 -5
- package/sqlite-proxy/driver.js.map +1 -1
- package/sqlite-proxy/migrator.cjs.map +1 -1
- package/sqlite-proxy/migrator.d.cts +2 -1
- package/sqlite-proxy/migrator.d.ts +2 -1
- package/sqlite-proxy/migrator.js.map +1 -1
- package/sqlite-proxy/session.cjs +50 -6
- package/sqlite-proxy/session.cjs.map +1 -1
- package/sqlite-proxy/session.d.cts +14 -8
- package/sqlite-proxy/session.d.ts +14 -8
- package/sqlite-proxy/session.js +50 -6
- 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 +22 -5
- package/tidb-serverless/driver.cjs.map +1 -1
- package/tidb-serverless/driver.d.cts +7 -6
- package/tidb-serverless/driver.d.ts +7 -6
- package/tidb-serverless/driver.js +12 -8
- package/tidb-serverless/driver.js.map +1 -1
- package/tidb-serverless/migrator.cjs.map +1 -1
- package/tidb-serverless/migrator.d.cts +2 -1
- package/tidb-serverless/migrator.d.ts +2 -1
- package/tidb-serverless/migrator.js.map +1 -1
- package/tidb-serverless/session.cjs +62 -5
- package/tidb-serverless/session.cjs.map +1 -1
- package/tidb-serverless/session.d.cts +14 -9
- package/tidb-serverless/session.d.ts +14 -9
- package/tidb-serverless/session.js +62 -5
- package/tidb-serverless/session.js.map +1 -1
- package/utils.cjs +2 -2
- package/utils.cjs.map +1 -1
- package/utils.d.cts +3 -1
- package/utils.d.ts +3 -1
- package/utils.js +2 -2
- package/utils.js.map +1 -1
- package/vercel-postgres/driver.cjs +23 -7
- package/vercel-postgres/driver.cjs.map +1 -1
- package/vercel-postgres/driver.d.cts +9 -8
- package/vercel-postgres/driver.d.ts +9 -8
- package/vercel-postgres/driver.js +13 -10
- package/vercel-postgres/driver.js.map +1 -1
- package/vercel-postgres/migrator.cjs.map +1 -1
- package/vercel-postgres/migrator.d.cts +2 -1
- package/vercel-postgres/migrator.d.ts +2 -1
- package/vercel-postgres/migrator.js.map +1 -1
- package/vercel-postgres/session.cjs +58 -4
- package/vercel-postgres/session.cjs.map +1 -1
- package/vercel-postgres/session.d.cts +13 -8
- package/vercel-postgres/session.d.ts +13 -8
- package/vercel-postgres/session.js +58 -4
- package/vercel-postgres/session.js.map +1 -1
- package/version.cjs +2 -2
- package/version.cjs.map +1 -1
- package/version.d.cts +2 -2
- package/version.d.ts +2 -2
- package/version.js +2 -2
- package/version.js.map +1 -1
- package/xata-http/driver.cjs +17 -5
- package/xata-http/driver.cjs.map +1 -1
- package/xata-http/driver.d.cts +5 -4
- package/xata-http/driver.d.ts +5 -4
- package/xata-http/driver.js +7 -5
- package/xata-http/driver.js.map +1 -1
- package/xata-http/migrator.cjs.map +1 -1
- package/xata-http/migrator.d.cts +2 -1
- package/xata-http/migrator.d.ts +2 -1
- package/xata-http/migrator.js.map +1 -1
- package/xata-http/session.cjs +30 -2
- package/xata-http/session.cjs.map +1 -1
- package/xata-http/session.d.cts +13 -8
- package/xata-http/session.d.ts +13 -8
- package/xata-http/session.js +30 -2
- package/xata-http/session.js.map +1 -1
package/gel-core/dialect.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as V1 from "../_relations.js";
|
|
1
2
|
import { aliasedTable, aliasedTableColumn, mapColumnsInAliasedSQLToAlias, mapColumnsInSQLToAlias } from "../alias.js";
|
|
2
3
|
import { CasingCache } from "../casing.js";
|
|
3
4
|
import { Column } from "../column.js";
|
|
@@ -6,20 +7,21 @@ import { DrizzleError } from "../errors.js";
|
|
|
6
7
|
import { GelColumn, GelDecimal, GelJson, GelUUID } from "./columns/index.js";
|
|
7
8
|
import { GelTable } from "./table.js";
|
|
8
9
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
getTableAsAliasSQL,
|
|
11
|
+
One,
|
|
12
|
+
relationExtrasToSQL,
|
|
13
|
+
relationsFilterToSQL,
|
|
14
|
+
relationsOrderToSQL,
|
|
15
|
+
relationToSQL
|
|
14
16
|
} from "../relations.js";
|
|
15
|
-
import { and, eq, View } from "../sql/index.js";
|
|
17
|
+
import { and, eq, isSQLWrapper, View } from "../sql/index.js";
|
|
16
18
|
import {
|
|
17
19
|
Param,
|
|
18
20
|
SQL,
|
|
19
21
|
sql
|
|
20
22
|
} from "../sql/sql.js";
|
|
21
23
|
import { Subquery } from "../subquery.js";
|
|
22
|
-
import { getTableName, getTableUniqueName, Table } from "../table.js";
|
|
24
|
+
import { Columns, getTableName, getTableUniqueName, Table } from "../table.js";
|
|
23
25
|
import { orderSelectedFields } from "../utils.js";
|
|
24
26
|
import { ViewBaseConfig } from "../view-common.js";
|
|
25
27
|
import { GelTimestamp } from "./columns/timestamp.js";
|
|
@@ -420,488 +422,7 @@ class GelDialect {
|
|
|
420
422
|
invokeSource
|
|
421
423
|
});
|
|
422
424
|
}
|
|
423
|
-
|
|
424
|
-
// fullSchema,
|
|
425
|
-
// schema,
|
|
426
|
-
// tableNamesMap,
|
|
427
|
-
// table,
|
|
428
|
-
// tableConfig,
|
|
429
|
-
// queryConfig: config,
|
|
430
|
-
// tableAlias,
|
|
431
|
-
// isRoot = false,
|
|
432
|
-
// joinOn,
|
|
433
|
-
// }: {
|
|
434
|
-
// fullSchema: Record<string, unknown>;
|
|
435
|
-
// schema: TablesRelationalConfig;
|
|
436
|
-
// tableNamesMap: Record<string, string>;
|
|
437
|
-
// table: GelTable;
|
|
438
|
-
// tableConfig: TableRelationalConfig;
|
|
439
|
-
// queryConfig: true | DBQueryConfig<'many', true>;
|
|
440
|
-
// tableAlias: string;
|
|
441
|
-
// isRoot?: boolean;
|
|
442
|
-
// joinOn?: SQL;
|
|
443
|
-
// }): BuildRelationalQueryResult<GelTable, GelColumn> {
|
|
444
|
-
// // For { "<relation>": true }, return a table with selection of all columns
|
|
445
|
-
// if (config === true) {
|
|
446
|
-
// const selectionEntries = Object.entries(tableConfig.columns);
|
|
447
|
-
// const selection: BuildRelationalQueryResult<GelTable, GelColumn>['selection'] = selectionEntries.map((
|
|
448
|
-
// [key, value],
|
|
449
|
-
// ) => ({
|
|
450
|
-
// dbKey: value.name,
|
|
451
|
-
// tsKey: key,
|
|
452
|
-
// field: value as GelColumn,
|
|
453
|
-
// relationTableTsKey: undefined,
|
|
454
|
-
// isJson: false,
|
|
455
|
-
// selection: [],
|
|
456
|
-
// }));
|
|
457
|
-
// return {
|
|
458
|
-
// tableTsKey: tableConfig.tsName,
|
|
459
|
-
// sql: table,
|
|
460
|
-
// selection,
|
|
461
|
-
// };
|
|
462
|
-
// }
|
|
463
|
-
// // let selection: BuildRelationalQueryResult<GelTable, GelColumn>['selection'] = [];
|
|
464
|
-
// // let selectionForBuild = selection;
|
|
465
|
-
// const aliasedColumns = Object.fromEntries(
|
|
466
|
-
// Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]),
|
|
467
|
-
// );
|
|
468
|
-
// const aliasedRelations = Object.fromEntries(
|
|
469
|
-
// Object.entries(tableConfig.relations).map(([key, value]) => [key, aliasedRelation(value, tableAlias)]),
|
|
470
|
-
// );
|
|
471
|
-
// const aliasedFields = Object.assign({}, aliasedColumns, aliasedRelations);
|
|
472
|
-
// let where, hasUserDefinedWhere;
|
|
473
|
-
// if (config.where) {
|
|
474
|
-
// const whereSql = typeof config.where === 'function' ? config.where(aliasedFields, operators) : config.where;
|
|
475
|
-
// where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
|
|
476
|
-
// hasUserDefinedWhere = !!where;
|
|
477
|
-
// }
|
|
478
|
-
// where = and(joinOn, where);
|
|
479
|
-
// // const fieldsSelection: { tsKey: string; value: GelColumn | SQL.Aliased; isExtra?: boolean }[] = [];
|
|
480
|
-
// let joins: Join[] = [];
|
|
481
|
-
// let selectedColumns: string[] = [];
|
|
482
|
-
// // Figure out which columns to select
|
|
483
|
-
// if (config.columns) {
|
|
484
|
-
// let isIncludeMode = false;
|
|
485
|
-
// for (const [field, value] of Object.entries(config.columns)) {
|
|
486
|
-
// if (value === undefined) {
|
|
487
|
-
// continue;
|
|
488
|
-
// }
|
|
489
|
-
// if (field in tableConfig.columns) {
|
|
490
|
-
// if (!isIncludeMode && value === true) {
|
|
491
|
-
// isIncludeMode = true;
|
|
492
|
-
// }
|
|
493
|
-
// selectedColumns.push(field);
|
|
494
|
-
// }
|
|
495
|
-
// }
|
|
496
|
-
// if (selectedColumns.length > 0) {
|
|
497
|
-
// selectedColumns = isIncludeMode
|
|
498
|
-
// ? selectedColumns.filter((c) => config.columns?.[c] === true)
|
|
499
|
-
// : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
|
|
500
|
-
// }
|
|
501
|
-
// } else {
|
|
502
|
-
// // Select all columns if selection is not specified
|
|
503
|
-
// selectedColumns = Object.keys(tableConfig.columns);
|
|
504
|
-
// }
|
|
505
|
-
// // for (const field of selectedColumns) {
|
|
506
|
-
// // const column = tableConfig.columns[field]! as GelColumn;
|
|
507
|
-
// // fieldsSelection.push({ tsKey: field, value: column });
|
|
508
|
-
// // }
|
|
509
|
-
// let initiallySelectedRelations: {
|
|
510
|
-
// tsKey: string;
|
|
511
|
-
// queryConfig: true | DBQueryConfig<'many', false>;
|
|
512
|
-
// relation: Relation;
|
|
513
|
-
// }[] = [];
|
|
514
|
-
// // let selectedRelations: BuildRelationalQueryResult<GelTable, GelColumn>['selection'] = [];
|
|
515
|
-
// // Figure out which relations to select
|
|
516
|
-
// if (config.with) {
|
|
517
|
-
// initiallySelectedRelations = Object.entries(config.with)
|
|
518
|
-
// .filter((entry): entry is [typeof entry[0], NonNullable<typeof entry[1]>] => !!entry[1])
|
|
519
|
-
// .map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey]! }));
|
|
520
|
-
// }
|
|
521
|
-
// const manyRelations = initiallySelectedRelations.filter((r) =>
|
|
522
|
-
// is(r.relation, Many)
|
|
523
|
-
// && (schema[tableNamesMap[r.relation.referencedTable[Table.Symbol.Name]]!]?.primaryKey.length ?? 0) > 0
|
|
524
|
-
// );
|
|
525
|
-
// // If this is the last Many relation (or there are no Many relations), we are on the innermost subquery level
|
|
526
|
-
// const isInnermostQuery = manyRelations.length < 2;
|
|
527
|
-
// const selectedExtras: {
|
|
528
|
-
// tsKey: string;
|
|
529
|
-
// value: SQL.Aliased;
|
|
530
|
-
// }[] = [];
|
|
531
|
-
// // Figure out which extras to select
|
|
532
|
-
// if (isInnermostQuery && config.extras) {
|
|
533
|
-
// const extras = typeof config.extras === 'function'
|
|
534
|
-
// ? config.extras(aliasedFields, { sql })
|
|
535
|
-
// : config.extras;
|
|
536
|
-
// for (const [tsKey, value] of Object.entries(extras)) {
|
|
537
|
-
// selectedExtras.push({
|
|
538
|
-
// tsKey,
|
|
539
|
-
// value: mapColumnsInAliasedSQLToAlias(value, tableAlias),
|
|
540
|
-
// });
|
|
541
|
-
// }
|
|
542
|
-
// }
|
|
543
|
-
// // Transform `fieldsSelection` into `selection`
|
|
544
|
-
// // `fieldsSelection` shouldn't be used after this point
|
|
545
|
-
// // for (const { tsKey, value, isExtra } of fieldsSelection) {
|
|
546
|
-
// // selection.push({
|
|
547
|
-
// // dbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey]!.name,
|
|
548
|
-
// // tsKey,
|
|
549
|
-
// // field: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,
|
|
550
|
-
// // relationTableTsKey: undefined,
|
|
551
|
-
// // isJson: false,
|
|
552
|
-
// // isExtra,
|
|
553
|
-
// // selection: [],
|
|
554
|
-
// // });
|
|
555
|
-
// // }
|
|
556
|
-
// let orderByOrig = typeof config.orderBy === 'function'
|
|
557
|
-
// ? config.orderBy(aliasedFields, orderByOperators)
|
|
558
|
-
// : config.orderBy ?? [];
|
|
559
|
-
// if (!Array.isArray(orderByOrig)) {
|
|
560
|
-
// orderByOrig = [orderByOrig];
|
|
561
|
-
// }
|
|
562
|
-
// const orderBy = orderByOrig.map((orderByValue) => {
|
|
563
|
-
// if (is(orderByValue, Column)) {
|
|
564
|
-
// return aliasedTableColumn(orderByValue, tableAlias) as GelColumn;
|
|
565
|
-
// }
|
|
566
|
-
// return mapColumnsInSQLToAlias(orderByValue, tableAlias);
|
|
567
|
-
// });
|
|
568
|
-
// const limit = isInnermostQuery ? config.limit : undefined;
|
|
569
|
-
// const offset = isInnermostQuery ? config.offset : undefined;
|
|
570
|
-
// // For non-root queries without additional config except columns, return a table with selection
|
|
571
|
-
// if (
|
|
572
|
-
// !isRoot
|
|
573
|
-
// && initiallySelectedRelations.length === 0
|
|
574
|
-
// && selectedExtras.length === 0
|
|
575
|
-
// && !where
|
|
576
|
-
// && orderBy.length === 0
|
|
577
|
-
// && limit === undefined
|
|
578
|
-
// && offset === undefined
|
|
579
|
-
// ) {
|
|
580
|
-
// return {
|
|
581
|
-
// tableTsKey: tableConfig.tsName,
|
|
582
|
-
// sql: table,
|
|
583
|
-
// selection: selectedColumns.map((key) => ({
|
|
584
|
-
// dbKey: tableConfig.columns[key]!.name,
|
|
585
|
-
// tsKey: key,
|
|
586
|
-
// field: tableConfig.columns[key] as GelColumn,
|
|
587
|
-
// relationTableTsKey: undefined,
|
|
588
|
-
// isJson: false,
|
|
589
|
-
// selection: [],
|
|
590
|
-
// })),
|
|
591
|
-
// };
|
|
592
|
-
// }
|
|
593
|
-
// const selectedRelationsWithoutPK:
|
|
594
|
-
// // Process all relations without primary keys, because they need to be joined differently and will all be on the same query level
|
|
595
|
-
// for (
|
|
596
|
-
// const {
|
|
597
|
-
// tsKey: selectedRelationTsKey,
|
|
598
|
-
// queryConfig: selectedRelationConfigValue,
|
|
599
|
-
// relation,
|
|
600
|
-
// } of initiallySelectedRelations
|
|
601
|
-
// ) {
|
|
602
|
-
// const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
|
|
603
|
-
// const relationTableName = relation.referencedTable[Table.Symbol.Name];
|
|
604
|
-
// const relationTableTsName = tableNamesMap[relationTableName]!;
|
|
605
|
-
// const relationTable = schema[relationTableTsName]!;
|
|
606
|
-
// if (relationTable.primaryKey.length > 0) {
|
|
607
|
-
// continue;
|
|
608
|
-
// }
|
|
609
|
-
// const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
610
|
-
// const joinOn = and(
|
|
611
|
-
// ...normalizedRelation.fields.map((field, i) =>
|
|
612
|
-
// eq(
|
|
613
|
-
// aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
|
|
614
|
-
// aliasedTableColumn(field, tableAlias),
|
|
615
|
-
// )
|
|
616
|
-
// ),
|
|
617
|
-
// );
|
|
618
|
-
// const builtRelation = this.buildRelationalQueryWithoutPK({
|
|
619
|
-
// fullSchema,
|
|
620
|
-
// schema,
|
|
621
|
-
// tableNamesMap,
|
|
622
|
-
// table: fullSchema[relationTableTsName] as GelTable,
|
|
623
|
-
// tableConfig: schema[relationTableTsName]!,
|
|
624
|
-
// queryConfig: selectedRelationConfigValue,
|
|
625
|
-
// tableAlias: relationTableAlias,
|
|
626
|
-
// joinOn,
|
|
627
|
-
// nestedQueryRelation: relation,
|
|
628
|
-
// });
|
|
629
|
-
// const field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier('data')}`.as(selectedRelationTsKey);
|
|
630
|
-
// joins.push({
|
|
631
|
-
// on: sql`true`,
|
|
632
|
-
// table: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),
|
|
633
|
-
// alias: relationTableAlias,
|
|
634
|
-
// joinType: 'left',
|
|
635
|
-
// lateral: true,
|
|
636
|
-
// });
|
|
637
|
-
// selectedRelations.push({
|
|
638
|
-
// dbKey: selectedRelationTsKey,
|
|
639
|
-
// tsKey: selectedRelationTsKey,
|
|
640
|
-
// field,
|
|
641
|
-
// relationTableTsKey: relationTableTsName,
|
|
642
|
-
// isJson: true,
|
|
643
|
-
// selection: builtRelation.selection,
|
|
644
|
-
// });
|
|
645
|
-
// }
|
|
646
|
-
// const oneRelations = initiallySelectedRelations.filter((r): r is typeof r & { relation: One } =>
|
|
647
|
-
// is(r.relation, One)
|
|
648
|
-
// );
|
|
649
|
-
// // Process all One relations with PKs, because they can all be joined on the same level
|
|
650
|
-
// for (
|
|
651
|
-
// const {
|
|
652
|
-
// tsKey: selectedRelationTsKey,
|
|
653
|
-
// queryConfig: selectedRelationConfigValue,
|
|
654
|
-
// relation,
|
|
655
|
-
// } of oneRelations
|
|
656
|
-
// ) {
|
|
657
|
-
// const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
|
|
658
|
-
// const relationTableName = relation.referencedTable[Table.Symbol.Name];
|
|
659
|
-
// const relationTableTsName = tableNamesMap[relationTableName]!;
|
|
660
|
-
// const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
661
|
-
// const relationTable = schema[relationTableTsName]!;
|
|
662
|
-
// if (relationTable.primaryKey.length === 0) {
|
|
663
|
-
// continue;
|
|
664
|
-
// }
|
|
665
|
-
// const joinOn = and(
|
|
666
|
-
// ...normalizedRelation.fields.map((field, i) =>
|
|
667
|
-
// eq(
|
|
668
|
-
// aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
|
|
669
|
-
// aliasedTableColumn(field, tableAlias),
|
|
670
|
-
// )
|
|
671
|
-
// ),
|
|
672
|
-
// );
|
|
673
|
-
// const builtRelation = this.buildRelationalQueryWithPK({
|
|
674
|
-
// fullSchema,
|
|
675
|
-
// schema,
|
|
676
|
-
// tableNamesMap,
|
|
677
|
-
// table: fullSchema[relationTableTsName] as GelTable,
|
|
678
|
-
// tableConfig: schema[relationTableTsName]!,
|
|
679
|
-
// queryConfig: selectedRelationConfigValue,
|
|
680
|
-
// tableAlias: relationTableAlias,
|
|
681
|
-
// joinOn,
|
|
682
|
-
// });
|
|
683
|
-
// const field = sql`case when ${sql.identifier(relationTableAlias)} is null then null else json_build_array(${
|
|
684
|
-
// sql.join(
|
|
685
|
-
// builtRelation.selection.map(({ field }) =>
|
|
686
|
-
// is(field, SQL.Aliased)
|
|
687
|
-
// ? sql`${sql.identifier(relationTableAlias)}.${sql.identifier(field.fieldAlias)}`
|
|
688
|
-
// : is(field, Column)
|
|
689
|
-
// ? aliasedTableColumn(field, relationTableAlias)
|
|
690
|
-
// : field
|
|
691
|
-
// ),
|
|
692
|
-
// sql`, `,
|
|
693
|
-
// )
|
|
694
|
-
// }) end`.as(selectedRelationTsKey);
|
|
695
|
-
// const isLateralJoin = is(builtRelation.sql, SQL);
|
|
696
|
-
// joins.push({
|
|
697
|
-
// on: isLateralJoin ? sql`true` : joinOn,
|
|
698
|
-
// table: is(builtRelation.sql, SQL)
|
|
699
|
-
// ? new Subquery(builtRelation.sql, {}, relationTableAlias)
|
|
700
|
-
// : aliasedTable(builtRelation.sql, relationTableAlias),
|
|
701
|
-
// alias: relationTableAlias,
|
|
702
|
-
// joinType: 'left',
|
|
703
|
-
// lateral: is(builtRelation.sql, SQL),
|
|
704
|
-
// });
|
|
705
|
-
// selectedRelations.push({
|
|
706
|
-
// dbKey: selectedRelationTsKey,
|
|
707
|
-
// tsKey: selectedRelationTsKey,
|
|
708
|
-
// field,
|
|
709
|
-
// relationTableTsKey: relationTableTsName,
|
|
710
|
-
// isJson: true,
|
|
711
|
-
// selection: builtRelation.selection,
|
|
712
|
-
// });
|
|
713
|
-
// }
|
|
714
|
-
// let distinct: GelSelectConfig['distinct'];
|
|
715
|
-
// let tableFrom: GelTable | Subquery = table;
|
|
716
|
-
// // Process first Many relation - each one requires a nested subquery
|
|
717
|
-
// const manyRelation = manyRelations[0];
|
|
718
|
-
// if (manyRelation) {
|
|
719
|
-
// const {
|
|
720
|
-
// tsKey: selectedRelationTsKey,
|
|
721
|
-
// queryConfig: selectedRelationQueryConfig,
|
|
722
|
-
// relation,
|
|
723
|
-
// } = manyRelation;
|
|
724
|
-
// distinct = {
|
|
725
|
-
// on: tableConfig.primaryKey.map((c) => aliasedTableColumn(c as GelColumn, tableAlias)),
|
|
726
|
-
// };
|
|
727
|
-
// const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
|
|
728
|
-
// const relationTableName = relation.referencedTable[Table.Symbol.Name];
|
|
729
|
-
// const relationTableTsName = tableNamesMap[relationTableName]!;
|
|
730
|
-
// const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
731
|
-
// const joinOn = and(
|
|
732
|
-
// ...normalizedRelation.fields.map((field, i) =>
|
|
733
|
-
// eq(
|
|
734
|
-
// aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
|
|
735
|
-
// aliasedTableColumn(field, tableAlias),
|
|
736
|
-
// )
|
|
737
|
-
// ),
|
|
738
|
-
// );
|
|
739
|
-
// const builtRelationJoin = this.buildRelationalQueryWithPK({
|
|
740
|
-
// fullSchema,
|
|
741
|
-
// schema,
|
|
742
|
-
// tableNamesMap,
|
|
743
|
-
// table: fullSchema[relationTableTsName] as GelTable,
|
|
744
|
-
// tableConfig: schema[relationTableTsName]!,
|
|
745
|
-
// queryConfig: selectedRelationQueryConfig,
|
|
746
|
-
// tableAlias: relationTableAlias,
|
|
747
|
-
// joinOn,
|
|
748
|
-
// });
|
|
749
|
-
// const builtRelationSelectionField = sql`case when ${
|
|
750
|
-
// sql.identifier(relationTableAlias)
|
|
751
|
-
// } is null then '[]' else json_agg(json_build_array(${
|
|
752
|
-
// sql.join(
|
|
753
|
-
// builtRelationJoin.selection.map(({ field }) =>
|
|
754
|
-
// is(field, SQL.Aliased)
|
|
755
|
-
// ? sql`${sql.identifier(relationTableAlias)}.${sql.identifier(field.fieldAlias)}`
|
|
756
|
-
// : is(field, Column)
|
|
757
|
-
// ? aliasedTableColumn(field, relationTableAlias)
|
|
758
|
-
// : field
|
|
759
|
-
// ),
|
|
760
|
-
// sql`, `,
|
|
761
|
-
// )
|
|
762
|
-
// })) over (partition by ${sql.join(distinct.on, sql`, `)}) end`.as(selectedRelationTsKey);
|
|
763
|
-
// const isLateralJoin = is(builtRelationJoin.sql, SQL);
|
|
764
|
-
// joins.push({
|
|
765
|
-
// on: isLateralJoin ? sql`true` : joinOn,
|
|
766
|
-
// table: isLateralJoin
|
|
767
|
-
// ? new Subquery(builtRelationJoin.sql as SQL, {}, relationTableAlias)
|
|
768
|
-
// : aliasedTable(builtRelationJoin.sql as GelTable, relationTableAlias),
|
|
769
|
-
// alias: relationTableAlias,
|
|
770
|
-
// joinType: 'left',
|
|
771
|
-
// lateral: isLateralJoin,
|
|
772
|
-
// });
|
|
773
|
-
// // Build the "from" subquery with the remaining Many relations
|
|
774
|
-
// const builtTableFrom = this.buildRelationalQueryWithPK({
|
|
775
|
-
// fullSchema,
|
|
776
|
-
// schema,
|
|
777
|
-
// tableNamesMap,
|
|
778
|
-
// table,
|
|
779
|
-
// tableConfig,
|
|
780
|
-
// queryConfig: {
|
|
781
|
-
// ...config,
|
|
782
|
-
// where: undefined,
|
|
783
|
-
// orderBy: undefined,
|
|
784
|
-
// limit: undefined,
|
|
785
|
-
// offset: undefined,
|
|
786
|
-
// with: manyRelations.slice(1).reduce<NonNullable<typeof config['with']>>(
|
|
787
|
-
// (result, { tsKey, queryConfig: configValue }) => {
|
|
788
|
-
// result[tsKey] = configValue;
|
|
789
|
-
// return result;
|
|
790
|
-
// },
|
|
791
|
-
// {},
|
|
792
|
-
// ),
|
|
793
|
-
// },
|
|
794
|
-
// tableAlias,
|
|
795
|
-
// });
|
|
796
|
-
// selectedRelations.push({
|
|
797
|
-
// dbKey: selectedRelationTsKey,
|
|
798
|
-
// tsKey: selectedRelationTsKey,
|
|
799
|
-
// field: builtRelationSelectionField,
|
|
800
|
-
// relationTableTsKey: relationTableTsName,
|
|
801
|
-
// isJson: true,
|
|
802
|
-
// selection: builtRelationJoin.selection,
|
|
803
|
-
// });
|
|
804
|
-
// // selection = builtTableFrom.selection.map((item) =>
|
|
805
|
-
// // is(item.field, SQL.Aliased)
|
|
806
|
-
// // ? { ...item, field: sql`${sql.identifier(tableAlias)}.${sql.identifier(item.field.fieldAlias)}` }
|
|
807
|
-
// // : item
|
|
808
|
-
// // );
|
|
809
|
-
// // selectionForBuild = [{
|
|
810
|
-
// // dbKey: '*',
|
|
811
|
-
// // tsKey: '*',
|
|
812
|
-
// // field: sql`${sql.identifier(tableAlias)}.*`,
|
|
813
|
-
// // selection: [],
|
|
814
|
-
// // isJson: false,
|
|
815
|
-
// // relationTableTsKey: undefined,
|
|
816
|
-
// // }];
|
|
817
|
-
// // const newSelectionItem: (typeof selection)[number] = {
|
|
818
|
-
// // dbKey: selectedRelationTsKey,
|
|
819
|
-
// // tsKey: selectedRelationTsKey,
|
|
820
|
-
// // field,
|
|
821
|
-
// // relationTableTsKey: relationTableTsName,
|
|
822
|
-
// // isJson: true,
|
|
823
|
-
// // selection: builtRelationJoin.selection,
|
|
824
|
-
// // };
|
|
825
|
-
// // selection.push(newSelectionItem);
|
|
826
|
-
// // selectionForBuild.push(newSelectionItem);
|
|
827
|
-
// tableFrom = is(builtTableFrom.sql, GelTable)
|
|
828
|
-
// ? builtTableFrom.sql
|
|
829
|
-
// : new Subquery(builtTableFrom.sql, {}, tableAlias);
|
|
830
|
-
// }
|
|
831
|
-
// if (selectedColumns.length === 0 && selectedRelations.length === 0 && selectedExtras.length === 0) {
|
|
832
|
-
// throw new DrizzleError(`No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")`);
|
|
833
|
-
// }
|
|
834
|
-
// let selection: BuildRelationalQueryResult<GelTable, GelColumn>['selection'];
|
|
835
|
-
// function prepareSelectedColumns() {
|
|
836
|
-
// return selectedColumns.map((key) => ({
|
|
837
|
-
// dbKey: tableConfig.columns[key]!.name,
|
|
838
|
-
// tsKey: key,
|
|
839
|
-
// field: tableConfig.columns[key] as GelColumn,
|
|
840
|
-
// relationTableTsKey: undefined,
|
|
841
|
-
// isJson: false,
|
|
842
|
-
// selection: [],
|
|
843
|
-
// }));
|
|
844
|
-
// }
|
|
845
|
-
// function prepareSelectedExtras() {
|
|
846
|
-
// return selectedExtras.map((item) => ({
|
|
847
|
-
// dbKey: item.value.fieldAlias,
|
|
848
|
-
// tsKey: item.tsKey,
|
|
849
|
-
// field: item.value,
|
|
850
|
-
// relationTableTsKey: undefined,
|
|
851
|
-
// isJson: false,
|
|
852
|
-
// selection: [],
|
|
853
|
-
// }));
|
|
854
|
-
// }
|
|
855
|
-
// if (isRoot) {
|
|
856
|
-
// selection = [
|
|
857
|
-
// ...prepareSelectedColumns(),
|
|
858
|
-
// ...prepareSelectedExtras(),
|
|
859
|
-
// ];
|
|
860
|
-
// }
|
|
861
|
-
// if (hasUserDefinedWhere || orderBy.length > 0) {
|
|
862
|
-
// tableFrom = new Subquery(
|
|
863
|
-
// this.buildSelectQuery({
|
|
864
|
-
// table: is(tableFrom, GelTable) ? aliasedTable(tableFrom, tableAlias) : tableFrom,
|
|
865
|
-
// fields: {},
|
|
866
|
-
// fieldsFlat: selectionForBuild.map(({ field }) => ({
|
|
867
|
-
// path: [],
|
|
868
|
-
// field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
|
|
869
|
-
// })),
|
|
870
|
-
// joins,
|
|
871
|
-
// distinct,
|
|
872
|
-
// }),
|
|
873
|
-
// {},
|
|
874
|
-
// tableAlias,
|
|
875
|
-
// );
|
|
876
|
-
// selectionForBuild = selection.map((item) =>
|
|
877
|
-
// is(item.field, SQL.Aliased)
|
|
878
|
-
// ? { ...item, field: sql`${sql.identifier(tableAlias)}.${sql.identifier(item.field.fieldAlias)}` }
|
|
879
|
-
// : item
|
|
880
|
-
// );
|
|
881
|
-
// joins = [];
|
|
882
|
-
// distinct = undefined;
|
|
883
|
-
// }
|
|
884
|
-
// const result = this.buildSelectQuery({
|
|
885
|
-
// table: is(tableFrom, GelTable) ? aliasedTable(tableFrom, tableAlias) : tableFrom,
|
|
886
|
-
// fields: {},
|
|
887
|
-
// fieldsFlat: selectionForBuild.map(({ field }) => ({
|
|
888
|
-
// path: [],
|
|
889
|
-
// field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
|
|
890
|
-
// })),
|
|
891
|
-
// where,
|
|
892
|
-
// limit,
|
|
893
|
-
// offset,
|
|
894
|
-
// joins,
|
|
895
|
-
// orderBy,
|
|
896
|
-
// distinct,
|
|
897
|
-
// });
|
|
898
|
-
// return {
|
|
899
|
-
// tableTsKey: tableConfig.tsName,
|
|
900
|
-
// sql: result,
|
|
901
|
-
// selection,
|
|
902
|
-
// };
|
|
903
|
-
// }
|
|
904
|
-
buildRelationalQueryWithoutPK({
|
|
425
|
+
_buildRelationalQuery({
|
|
905
426
|
fullSchema,
|
|
906
427
|
schema,
|
|
907
428
|
tableNamesMap,
|
|
@@ -930,7 +451,7 @@ class GelDialect {
|
|
|
930
451
|
Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)])
|
|
931
452
|
);
|
|
932
453
|
if (config.where) {
|
|
933
|
-
const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, getOperators()) : config.where;
|
|
454
|
+
const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, V1.getOperators()) : config.where;
|
|
934
455
|
where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
|
|
935
456
|
}
|
|
936
457
|
const fieldsSelection = [];
|
|
@@ -982,7 +503,7 @@ class GelDialect {
|
|
|
982
503
|
selection: []
|
|
983
504
|
});
|
|
984
505
|
}
|
|
985
|
-
let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, getOrderByOperators()) : config.orderBy ?? [];
|
|
506
|
+
let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, V1.getOrderByOperators()) : config.orderBy ?? [];
|
|
986
507
|
if (!Array.isArray(orderByOrig)) {
|
|
987
508
|
orderByOrig = [orderByOrig];
|
|
988
509
|
}
|
|
@@ -999,7 +520,7 @@ class GelDialect {
|
|
|
999
520
|
queryConfig: selectedRelationConfigValue,
|
|
1000
521
|
relation
|
|
1001
522
|
} of selectedRelations) {
|
|
1002
|
-
const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
|
|
523
|
+
const normalizedRelation = V1.normalizeRelation(schema, tableNamesMap, relation);
|
|
1003
524
|
const relationTableName = getTableUniqueName(relation.referencedTable);
|
|
1004
525
|
const relationTableTsName = tableNamesMap[relationTableName];
|
|
1005
526
|
const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
@@ -1011,13 +532,13 @@ class GelDialect {
|
|
|
1011
532
|
)
|
|
1012
533
|
)
|
|
1013
534
|
);
|
|
1014
|
-
const builtRelation = this.
|
|
535
|
+
const builtRelation = this._buildRelationalQuery({
|
|
1015
536
|
fullSchema,
|
|
1016
537
|
schema,
|
|
1017
538
|
tableNamesMap,
|
|
1018
539
|
table: fullSchema[relationTableTsName],
|
|
1019
540
|
tableConfig: schema[relationTableTsName],
|
|
1020
|
-
queryConfig: is(relation, One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
|
|
541
|
+
queryConfig: is(relation, V1.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
|
|
1021
542
|
tableAlias: relationTableAlias,
|
|
1022
543
|
joinOn: joinOn2,
|
|
1023
544
|
nestedQueryRelation: relation
|
|
@@ -1052,7 +573,7 @@ class GelDialect {
|
|
|
1052
573
|
),
|
|
1053
574
|
sql`, `
|
|
1054
575
|
)})`;
|
|
1055
|
-
if (is(nestedQueryRelation, Many)) {
|
|
576
|
+
if (is(nestedQueryRelation, V1.Many)) {
|
|
1056
577
|
field = sql`coalesce(json_agg(${field}${orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : void 0}), '[]'::json)`;
|
|
1057
578
|
}
|
|
1058
579
|
const nestedSelection = [{
|
|
@@ -1121,6 +642,160 @@ class GelDialect {
|
|
|
1121
642
|
selection
|
|
1122
643
|
};
|
|
1123
644
|
}
|
|
645
|
+
nestedSelectionerror() {
|
|
646
|
+
throw new DrizzleError({
|
|
647
|
+
message: `Views with nested selections are not supported by the relational query builder`
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
buildRqbColumn(table, column, key) {
|
|
651
|
+
if (is(column, Column)) {
|
|
652
|
+
switch (column.columnType) {
|
|
653
|
+
default: {
|
|
654
|
+
return sql`${table}.${sql.identifier(this.casing.getColumnCasing(column))} as ${sql.identifier(key)}`;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return sql`${table}.${is(column, SQL.Aliased) ? sql.identifier(column.fieldAlias) : isSQLWrapper(column) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
|
|
659
|
+
}
|
|
660
|
+
unwrapAllColumns = (table, selection) => {
|
|
661
|
+
return sql.join(
|
|
662
|
+
Object.entries(table[Columns]).map(([k, v]) => {
|
|
663
|
+
selection.push({
|
|
664
|
+
key: k,
|
|
665
|
+
field: v
|
|
666
|
+
});
|
|
667
|
+
return this.buildRqbColumn(table, v, k);
|
|
668
|
+
}),
|
|
669
|
+
sql`, `
|
|
670
|
+
);
|
|
671
|
+
};
|
|
672
|
+
buildColumns = (table, selection, config) => config?.columns ? (() => {
|
|
673
|
+
const entries = Object.entries(config.columns);
|
|
674
|
+
const columnContainer = table[Columns];
|
|
675
|
+
const columnIdentifiers = [];
|
|
676
|
+
let colSelectionMode;
|
|
677
|
+
for (const [k, v] of entries) {
|
|
678
|
+
if (v === void 0)
|
|
679
|
+
continue;
|
|
680
|
+
colSelectionMode = colSelectionMode || v;
|
|
681
|
+
if (v) {
|
|
682
|
+
const column = columnContainer[k];
|
|
683
|
+
columnIdentifiers.push(
|
|
684
|
+
this.buildRqbColumn(table, column, k)
|
|
685
|
+
);
|
|
686
|
+
selection.push({
|
|
687
|
+
key: k,
|
|
688
|
+
field: column
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
if (colSelectionMode === false) {
|
|
693
|
+
for (const [k, v] of Object.entries(columnContainer)) {
|
|
694
|
+
if (config.columns[k] === false)
|
|
695
|
+
continue;
|
|
696
|
+
columnIdentifiers.push(this.buildRqbColumn(table, v, k));
|
|
697
|
+
selection.push({
|
|
698
|
+
key: k,
|
|
699
|
+
field: v
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
|
|
704
|
+
})() : this.unwrapAllColumns(table, selection);
|
|
705
|
+
buildRelationalQuery({
|
|
706
|
+
tables,
|
|
707
|
+
schema,
|
|
708
|
+
tableNamesMap,
|
|
709
|
+
table,
|
|
710
|
+
tableConfig,
|
|
711
|
+
queryConfig: config,
|
|
712
|
+
relationWhere,
|
|
713
|
+
mode,
|
|
714
|
+
errorPath,
|
|
715
|
+
depth,
|
|
716
|
+
throughJoin
|
|
717
|
+
}) {
|
|
718
|
+
const selection = [];
|
|
719
|
+
const isSingle = mode === "first";
|
|
720
|
+
const params = config === true ? void 0 : config;
|
|
721
|
+
const currentPath = errorPath ?? "";
|
|
722
|
+
const currentDepth = depth ?? 0;
|
|
723
|
+
if (!currentDepth)
|
|
724
|
+
table = aliasedTable(table, `d${currentDepth}`);
|
|
725
|
+
const limit = isSingle ? 1 : params?.limit;
|
|
726
|
+
const offset = params?.offset;
|
|
727
|
+
const where = params?.where && relationWhere ? and(
|
|
728
|
+
relationsFilterToSQL(table, params.where, tableConfig.relations, schema, tableNamesMap, this.casing),
|
|
729
|
+
relationWhere
|
|
730
|
+
) : params?.where ? relationsFilterToSQL(table, params.where, tableConfig.relations, schema, tableNamesMap, this.casing) : relationWhere;
|
|
731
|
+
const order = params?.orderBy ? relationsOrderToSQL(table, params.orderBy) : void 0;
|
|
732
|
+
const columns = this.buildColumns(table, selection, params);
|
|
733
|
+
const extras = params?.extras ? relationExtrasToSQL(table, params.extras) : void 0;
|
|
734
|
+
if (extras)
|
|
735
|
+
selection.push(...extras.selection);
|
|
736
|
+
const selectionArr = columns ? [columns] : [];
|
|
737
|
+
const joins = params ? (() => {
|
|
738
|
+
const { with: joins2 } = params;
|
|
739
|
+
if (!joins2)
|
|
740
|
+
return;
|
|
741
|
+
const withEntries = Object.entries(joins2).filter(([_, v]) => v);
|
|
742
|
+
if (!withEntries.length)
|
|
743
|
+
return;
|
|
744
|
+
return sql.join(
|
|
745
|
+
withEntries.map(([k, join]) => {
|
|
746
|
+
const relation = tableConfig.relations[k];
|
|
747
|
+
const isSingle2 = is(relation, One);
|
|
748
|
+
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
|
749
|
+
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
|
750
|
+
const { filter, joinCondition } = relationToSQL(
|
|
751
|
+
this.casing,
|
|
752
|
+
relation,
|
|
753
|
+
table,
|
|
754
|
+
targetTable,
|
|
755
|
+
throughTable
|
|
756
|
+
);
|
|
757
|
+
selectionArr.push(sql`${sql.identifier(k)}.${sql.identifier("r")} as ${sql.identifier(k)}`);
|
|
758
|
+
const throughJoin2 = throughTable ? sql` inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}` : void 0;
|
|
759
|
+
const innerQuery = this.buildRelationalQuery({
|
|
760
|
+
table: targetTable,
|
|
761
|
+
mode: isSingle2 ? "first" : "many",
|
|
762
|
+
schema,
|
|
763
|
+
queryConfig: join,
|
|
764
|
+
tableConfig: schema[tableNamesMap[getTableUniqueName(relation.targetTable)]],
|
|
765
|
+
tableNamesMap,
|
|
766
|
+
tables,
|
|
767
|
+
relationWhere: filter,
|
|
768
|
+
errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
|
|
769
|
+
depth: currentDepth + 1,
|
|
770
|
+
throughJoin: throughJoin2
|
|
771
|
+
});
|
|
772
|
+
selection.push({
|
|
773
|
+
field: targetTable,
|
|
774
|
+
key: k,
|
|
775
|
+
selection: innerQuery.selection,
|
|
776
|
+
isArray: !isSingle2,
|
|
777
|
+
isOptional: (relation.optional ?? false) || join !== true && !!join.where
|
|
778
|
+
});
|
|
779
|
+
const joinQuery = sql`left join lateral(select ${isSingle2 ? sql`row_to_json(${sql.identifier("t")}.*) ${sql.identifier("r")}` : sql`coalesce(json_agg(row_to_json(${sql.identifier("t")}.*)), '[]') as ${sql.identifier("r")}`} from (${innerQuery.sql}) as ${sql.identifier("t")}) as ${sql.identifier(k)} on true`;
|
|
780
|
+
return joinQuery;
|
|
781
|
+
}),
|
|
782
|
+
sql` `
|
|
783
|
+
);
|
|
784
|
+
})() : void 0;
|
|
785
|
+
if (extras?.sql)
|
|
786
|
+
selectionArr.push(extras.sql);
|
|
787
|
+
if (!selectionArr.length) {
|
|
788
|
+
throw new DrizzleError({
|
|
789
|
+
message: `No fields selected for table "${tableConfig.tsName}"${currentPath ? ` ("${currentPath}")` : ""}`
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
const selectionSet = sql.join(selectionArr.filter((e) => e !== void 0), sql`, `);
|
|
793
|
+
const query = sql`select ${selectionSet} from ${getTableAsAliasSQL(table)}${throughJoin}${sql` ${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
|
794
|
+
return {
|
|
795
|
+
sql: query,
|
|
796
|
+
selection
|
|
797
|
+
};
|
|
798
|
+
}
|
|
1124
799
|
}
|
|
1125
800
|
export {
|
|
1126
801
|
GelDialect
|