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/relations.cjs
CHANGED
|
@@ -18,311 +18,723 @@ var __copyProps = (to, from, except, desc2) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var relations_exports = {};
|
|
20
20
|
__export(relations_exports, {
|
|
21
|
+
AggregatedField: () => AggregatedField,
|
|
22
|
+
Count: () => Count,
|
|
21
23
|
Many: () => Many,
|
|
22
24
|
One: () => One,
|
|
23
25
|
Relation: () => Relation,
|
|
24
26
|
Relations: () => Relations,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
RelationsBuilderColumn: () => RelationsBuilderColumn,
|
|
28
|
+
RelationsBuilderJunctionColumn: () => RelationsBuilderJunctionColumn,
|
|
29
|
+
RelationsBuilderTable: () => RelationsBuilderTable,
|
|
30
|
+
RelationsHelperStatic: () => RelationsHelperStatic,
|
|
31
|
+
createRelationsHelper: () => createRelationsHelper,
|
|
32
|
+
defineRelations: () => defineRelations,
|
|
33
|
+
fieldSelectionToSQL: () => fieldSelectionToSQL,
|
|
30
34
|
getOrderByOperators: () => getOrderByOperators,
|
|
35
|
+
getTableAsAliasSQL: () => getTableAsAliasSQL,
|
|
31
36
|
mapRelationalRow: () => mapRelationalRow,
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
operators: () => operators,
|
|
38
|
+
orderByOperators: () => orderByOperators,
|
|
39
|
+
relationExtrasToSQL: () => relationExtrasToSQL,
|
|
40
|
+
relationToSQL: () => relationToSQL,
|
|
41
|
+
relationsFilterToSQL: () => relationsFilterToSQL,
|
|
42
|
+
relationsOrderToSQL: () => relationsOrderToSQL
|
|
34
43
|
});
|
|
35
44
|
module.exports = __toCommonJS(relations_exports);
|
|
36
45
|
var import_table = require("./table.cjs");
|
|
46
|
+
var import_table2 = require("./table.cjs");
|
|
47
|
+
var import_alias = require("./alias.cjs");
|
|
37
48
|
var import_column = require("./column.cjs");
|
|
38
49
|
var import_entity = require("./entity.cjs");
|
|
39
|
-
var
|
|
50
|
+
var import_errors = require("./errors.cjs");
|
|
40
51
|
var import_expressions = require("./sql/expressions/index.cjs");
|
|
41
52
|
var import_sql = require("./sql/sql.cjs");
|
|
42
|
-
class Relation {
|
|
43
|
-
constructor(sourceTable, referencedTable, relationName) {
|
|
44
|
-
this.sourceTable = sourceTable;
|
|
45
|
-
this.referencedTable = referencedTable;
|
|
46
|
-
this.relationName = relationName;
|
|
47
|
-
this.referencedTableName = referencedTable[import_table.Table.Symbol.Name];
|
|
48
|
-
}
|
|
49
|
-
static [import_entity.entityKind] = "Relation";
|
|
50
|
-
referencedTableName;
|
|
51
|
-
fieldName;
|
|
52
|
-
}
|
|
53
53
|
class Relations {
|
|
54
|
-
constructor(
|
|
55
|
-
this.
|
|
54
|
+
constructor(schema, tables, config) {
|
|
55
|
+
this.schema = schema;
|
|
56
|
+
this.tables = tables;
|
|
56
57
|
this.config = config;
|
|
58
|
+
for (const [tsName, table] of Object.entries(tables)) {
|
|
59
|
+
if (config[tsName]?.$drizzleTypeError)
|
|
60
|
+
continue;
|
|
61
|
+
const isTable = (0, import_entity.is)(table, import_table.Table);
|
|
62
|
+
const isView = (0, import_entity.is)(table, import_sql.View);
|
|
63
|
+
if (!(isTable || isView))
|
|
64
|
+
continue;
|
|
65
|
+
this.tableNamesMap[(0, import_table.getTableUniqueName)(table)] = tsName;
|
|
66
|
+
this.tablesConfig[tsName] = {
|
|
67
|
+
table,
|
|
68
|
+
tsName,
|
|
69
|
+
dbName: table[import_table.Table.Symbol.Name],
|
|
70
|
+
schema: table[import_table.Table.Symbol.Schema],
|
|
71
|
+
columns: table[import_table.Table.Symbol.Columns],
|
|
72
|
+
relations: config[tsName] || {}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
for (const tableConfig of Object.values(this.tablesConfig)) {
|
|
76
|
+
for (const [relationFieldName, relation] of Object.entries(tableConfig.relations)) {
|
|
77
|
+
if (!(0, import_entity.is)(relation, Relation)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
relation.sourceTable = tableConfig.table;
|
|
81
|
+
relation.fieldName = relationFieldName;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const tableConfig of Object.values(this.tablesConfig)) {
|
|
85
|
+
for (const [relationFieldName, relation] of Object.entries(tableConfig.relations)) {
|
|
86
|
+
if (!(0, import_entity.is)(relation, Relation)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const relationPrintName = `relations -> ${tableConfig.tsName}: { ${relationFieldName}: r.${(0, import_entity.is)(relation, One) ? "one" : "many"}.${this.tableNamesMap[(0, import_table.getTableUniqueName)(relation.targetTable)]}(...) }`;
|
|
90
|
+
if (typeof relation.alias === "string" && !relation.alias) {
|
|
91
|
+
throw new Error(`${relationPrintName}: "alias" cannot be an empty string - omit it if you don't need it`);
|
|
92
|
+
}
|
|
93
|
+
if (relation.sourceColumns?.length === 0) {
|
|
94
|
+
throw new Error(`${relationPrintName}: "from" cannot be an empty array`);
|
|
95
|
+
}
|
|
96
|
+
if (relation.targetColumns?.length === 0) {
|
|
97
|
+
throw new Error(`${relationPrintName}: "to" cannot be an empty array`);
|
|
98
|
+
}
|
|
99
|
+
if (relation.sourceColumns && relation.targetColumns) {
|
|
100
|
+
if (relation.sourceColumns.length !== relation.targetColumns.length && !relation.throughTable) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`${relationPrintName}: "from" and "to" fields without "through" must have the same length`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (relation.through) {
|
|
106
|
+
if (relation.through.source.length !== relation.sourceColumns.length || relation.through.target.length !== relation.targetColumns.length) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`${relationPrintName}: ".through(column)" must be used either on all columns in "from" and "to" or not defined on any of them`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
for (const column of relation.through.source) {
|
|
112
|
+
if (tables[column._.tableName] !== relation.throughTable) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
`${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
for (const column of relation.through.target) {
|
|
119
|
+
if (tables[column._.tableName] !== relation.throughTable) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (relation.sourceColumns || relation.targetColumns) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`${relationPrintName}: relation must have either both "from" and "to" defined, or none of them`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
let reverseRelation;
|
|
134
|
+
const targetTableTsName = this.tableNamesMap[(0, import_table.getTableUniqueName)(relation.targetTable)];
|
|
135
|
+
if (!targetTableTsName) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Table "${(0, import_table.getTableUniqueName)(relation.targetTable)}" not found in provided TS schema`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
const reverseTableConfig = this.tablesConfig[targetTableTsName];
|
|
141
|
+
if (!reverseTableConfig) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
`${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relations of table "${targetTableTsName}" were found"`
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
if (relation.alias) {
|
|
147
|
+
const reverseRelations = Object.values(reverseTableConfig.relations).filter(
|
|
148
|
+
(it) => (0, import_entity.is)(it, Relation) && it.alias === relation.alias && it !== relation
|
|
149
|
+
);
|
|
150
|
+
if (reverseRelations.length > 1) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations with alias "${relation.alias}" found in table "${targetTableTsName}": ${reverseRelations.map((it) => `"${it.fieldName}"`).join(", ")}`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
reverseRelation = reverseRelations[0];
|
|
156
|
+
if (!reverseRelation) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and there is no reverse relation of table "${targetTableTsName}" with alias "${relation.alias}"`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
const reverseRelations = Object.values(reverseTableConfig.relations).filter(
|
|
163
|
+
(it) => (0, import_entity.is)(it, Relation) && it.targetTable === relation.sourceTable && !it.alias && it !== relation
|
|
164
|
+
);
|
|
165
|
+
if (reverseRelations.length > 1) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
`${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations between "${targetTableTsName}" and "${(0, import_table.getTableUniqueName)(relation.sourceTable)}" were found.
|
|
168
|
+
Hint: you can specify "alias" on both sides of the relation with the same value`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
reverseRelation = reverseRelations[0];
|
|
172
|
+
if (!reverseRelation) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relation of table "${targetTableTsName}" with target table "${(0, import_table.getTableUniqueName)(relation.sourceTable)}" was found`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (!reverseRelation.sourceColumns || !reverseRelation.targetColumns) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and reverse relation "${targetTableTsName}.${reverseRelation.fieldName}" does not have "from"/"to" defined`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
relation.sourceColumns = reverseRelation.targetColumns;
|
|
184
|
+
relation.targetColumns = reverseRelation.sourceColumns;
|
|
185
|
+
relation.through = reverseRelation.through ? {
|
|
186
|
+
source: reverseRelation.through.target,
|
|
187
|
+
target: reverseRelation.through.source
|
|
188
|
+
} : void 0;
|
|
189
|
+
relation.throughTable = reverseRelation.throughTable;
|
|
190
|
+
relation.isReversed = !relation.where;
|
|
191
|
+
relation.where = relation.where ?? reverseRelation.where;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
57
194
|
}
|
|
58
|
-
static [import_entity.entityKind] = "
|
|
195
|
+
static [import_entity.entityKind] = "RelationsV2";
|
|
196
|
+
/** table DB name -> schema table key */
|
|
197
|
+
tableNamesMap = {};
|
|
198
|
+
tablesConfig = {};
|
|
59
199
|
}
|
|
60
|
-
class
|
|
61
|
-
constructor(
|
|
62
|
-
|
|
63
|
-
this.config = config;
|
|
64
|
-
this.isNullable = isNullable;
|
|
200
|
+
class Relation {
|
|
201
|
+
constructor(targetTable) {
|
|
202
|
+
this.targetTable = targetTable;
|
|
65
203
|
}
|
|
66
|
-
static [import_entity.entityKind] = "
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
204
|
+
static [import_entity.entityKind] = "RelationV2";
|
|
205
|
+
fieldName;
|
|
206
|
+
sourceColumns;
|
|
207
|
+
targetColumns;
|
|
208
|
+
alias;
|
|
209
|
+
where;
|
|
210
|
+
sourceTable;
|
|
211
|
+
through;
|
|
212
|
+
throughTable;
|
|
213
|
+
isReversed;
|
|
214
|
+
}
|
|
215
|
+
class One extends Relation {
|
|
216
|
+
static [import_entity.entityKind] = "OneV2";
|
|
217
|
+
optional;
|
|
218
|
+
constructor(tables, targetTable, config) {
|
|
219
|
+
super(targetTable);
|
|
220
|
+
this.alias = config?.alias;
|
|
221
|
+
this.where = config?.where;
|
|
222
|
+
if (config?.from) {
|
|
223
|
+
this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
|
|
224
|
+
this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
|
|
225
|
+
return it._.column;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
if (config?.to) {
|
|
229
|
+
this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
|
|
230
|
+
this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
|
|
231
|
+
return it._.column;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
if (this.throughTable) {
|
|
235
|
+
this.through = {
|
|
236
|
+
source: (Array.isArray(config?.from) ? config.from : [config.from]).map((c) => c._.through),
|
|
237
|
+
target: (Array.isArray(config?.to) ? config.to : [config.to]).map((c) => c._.through)
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
this.optional = config?.optional ?? true;
|
|
76
241
|
}
|
|
77
242
|
}
|
|
78
243
|
class Many extends Relation {
|
|
79
|
-
constructor(
|
|
80
|
-
super(
|
|
244
|
+
constructor(tables, targetTable, config) {
|
|
245
|
+
super(targetTable);
|
|
81
246
|
this.config = config;
|
|
247
|
+
this.alias = config?.alias;
|
|
248
|
+
this.where = config?.where;
|
|
249
|
+
if (config?.from) {
|
|
250
|
+
this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
|
|
251
|
+
this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
|
|
252
|
+
return it._.column;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (config?.to) {
|
|
256
|
+
this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
|
|
257
|
+
this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
|
|
258
|
+
return it._.column;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
if (this.throughTable) {
|
|
262
|
+
this.through = {
|
|
263
|
+
source: (Array.isArray(config?.from) ? config.from : [config.from]).map((c) => c._.through),
|
|
264
|
+
target: (Array.isArray(config?.to) ? config.to : [config.to]).map((c) => c._.through)
|
|
265
|
+
};
|
|
266
|
+
}
|
|
82
267
|
}
|
|
83
|
-
static [import_entity.entityKind] = "
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return relation;
|
|
268
|
+
static [import_entity.entityKind] = "ManyV2";
|
|
269
|
+
}
|
|
270
|
+
class AggregatedField {
|
|
271
|
+
static [import_entity.entityKind] = "AggregatedField";
|
|
272
|
+
table;
|
|
273
|
+
onTable(table) {
|
|
274
|
+
this.table = table;
|
|
275
|
+
return this;
|
|
92
276
|
}
|
|
93
277
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
isNotNull: import_expressions.isNotNull,
|
|
106
|
-
like: import_expressions.like,
|
|
107
|
-
lt: import_expressions.lt,
|
|
108
|
-
lte: import_expressions.lte,
|
|
109
|
-
ne: import_expressions.ne,
|
|
110
|
-
not: import_expressions.not,
|
|
111
|
-
notBetween: import_expressions.notBetween,
|
|
112
|
-
notExists: import_expressions.notExists,
|
|
113
|
-
notLike: import_expressions.notLike,
|
|
114
|
-
notIlike: import_expressions.notIlike,
|
|
115
|
-
notInArray: import_expressions.notInArray,
|
|
116
|
-
or: import_expressions.or,
|
|
117
|
-
sql: import_sql.sql
|
|
118
|
-
};
|
|
278
|
+
class Count extends AggregatedField {
|
|
279
|
+
static [import_entity.entityKind] = "AggregatedFieldCount";
|
|
280
|
+
query;
|
|
281
|
+
getSQL() {
|
|
282
|
+
if (!this.query) {
|
|
283
|
+
if (!this.table)
|
|
284
|
+
throw new Error("Table must be set before building aggregate field");
|
|
285
|
+
this.query = import_sql.sql`select count(*) as ${import_sql.sql.identifier("r")} from ${getTableAsAliasSQL(this.table)}`.mapWith(Number);
|
|
286
|
+
}
|
|
287
|
+
return this.query;
|
|
288
|
+
}
|
|
119
289
|
}
|
|
290
|
+
const operators = {
|
|
291
|
+
and: import_expressions.and,
|
|
292
|
+
between: import_expressions.between,
|
|
293
|
+
eq: import_expressions.eq,
|
|
294
|
+
exists: import_expressions.exists,
|
|
295
|
+
gt: import_expressions.gt,
|
|
296
|
+
gte: import_expressions.gte,
|
|
297
|
+
ilike: import_expressions.ilike,
|
|
298
|
+
inArray: import_expressions.inArray,
|
|
299
|
+
isNull: import_expressions.isNull,
|
|
300
|
+
isNotNull: import_expressions.isNotNull,
|
|
301
|
+
like: import_expressions.like,
|
|
302
|
+
lt: import_expressions.lt,
|
|
303
|
+
lte: import_expressions.lte,
|
|
304
|
+
ne: import_expressions.ne,
|
|
305
|
+
not: import_expressions.not,
|
|
306
|
+
notBetween: import_expressions.notBetween,
|
|
307
|
+
notExists: import_expressions.notExists,
|
|
308
|
+
notLike: import_expressions.notLike,
|
|
309
|
+
notIlike: import_expressions.notIlike,
|
|
310
|
+
notInArray: import_expressions.notInArray,
|
|
311
|
+
or: import_expressions.or,
|
|
312
|
+
sql: import_sql.sql
|
|
313
|
+
};
|
|
314
|
+
const orderByOperators = {
|
|
315
|
+
sql: import_sql.sql,
|
|
316
|
+
asc: import_expressions.asc,
|
|
317
|
+
desc: import_expressions.desc
|
|
318
|
+
};
|
|
120
319
|
function getOrderByOperators() {
|
|
121
|
-
return
|
|
122
|
-
sql: import_sql.sql,
|
|
123
|
-
asc: import_expressions.asc,
|
|
124
|
-
desc: import_expressions.desc
|
|
125
|
-
};
|
|
320
|
+
return orderByOperators;
|
|
126
321
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
relations: bufferedRelations?.relations ?? {},
|
|
145
|
-
primaryKey: bufferedRelations?.primaryKey ?? []
|
|
146
|
-
};
|
|
147
|
-
for (const column of Object.values(
|
|
148
|
-
value[import_table.Table.Symbol.Columns]
|
|
149
|
-
)) {
|
|
150
|
-
if (column.primary) {
|
|
151
|
-
tablesConfig[key].primaryKey.push(column);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const extraConfig = value[import_table.Table.Symbol.ExtraConfigBuilder]?.(value[import_table.Table.Symbol.ExtraConfigColumns]);
|
|
155
|
-
if (extraConfig) {
|
|
156
|
-
for (const configEntry of Object.values(extraConfig)) {
|
|
157
|
-
if ((0, import_entity.is)(configEntry, import_primary_keys.PrimaryKeyBuilder)) {
|
|
158
|
-
tablesConfig[key].primaryKey.push(...configEntry.columns);
|
|
159
|
-
}
|
|
322
|
+
function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (value) => value, parseJson = false, path) {
|
|
323
|
+
for (const selectionItem of buildQueryResultSelection) {
|
|
324
|
+
if (selectionItem.selection) {
|
|
325
|
+
const currentPath = `${path ? `${path}.` : ""}${selectionItem.key}`;
|
|
326
|
+
if (row[selectionItem.key] === null)
|
|
327
|
+
continue;
|
|
328
|
+
if (parseJson)
|
|
329
|
+
row[selectionItem.key] = JSON.parse(row[selectionItem.key]);
|
|
330
|
+
if (selectionItem.isArray) {
|
|
331
|
+
for (const item of row[selectionItem.key]) {
|
|
332
|
+
mapRelationalRow(
|
|
333
|
+
item,
|
|
334
|
+
selectionItem.selection,
|
|
335
|
+
mapColumnValue,
|
|
336
|
+
false,
|
|
337
|
+
currentPath
|
|
338
|
+
);
|
|
160
339
|
}
|
|
340
|
+
continue;
|
|
161
341
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
342
|
+
mapRelationalRow(
|
|
343
|
+
row[selectionItem.key],
|
|
344
|
+
selectionItem.selection,
|
|
345
|
+
mapColumnValue,
|
|
346
|
+
false,
|
|
347
|
+
currentPath
|
|
167
348
|
);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
relationsBuffer[dbName].relations[relationName] = relation;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const field = selectionItem.field;
|
|
352
|
+
const value = mapColumnValue(row[selectionItem.key]);
|
|
353
|
+
if (value === null)
|
|
354
|
+
continue;
|
|
355
|
+
let decoder;
|
|
356
|
+
if ((0, import_entity.is)(field, import_column.Column)) {
|
|
357
|
+
decoder = field;
|
|
358
|
+
} else if ((0, import_entity.is)(field, import_sql.SQL)) {
|
|
359
|
+
decoder = field.decoder;
|
|
360
|
+
} else if ((0, import_entity.is)(field, import_sql.SQL.Aliased)) {
|
|
361
|
+
decoder = field.sql.decoder;
|
|
362
|
+
} else {
|
|
363
|
+
decoder = field.getSQL().decoder;
|
|
186
364
|
}
|
|
365
|
+
row[selectionItem.key] = decoder.mapFromDriverValue(value);
|
|
187
366
|
}
|
|
188
|
-
return
|
|
189
|
-
}
|
|
190
|
-
function relations(table, relations2) {
|
|
191
|
-
return new Relations(
|
|
192
|
-
table,
|
|
193
|
-
(helpers) => Object.fromEntries(
|
|
194
|
-
Object.entries(relations2(helpers)).map(([key, value]) => [
|
|
195
|
-
key,
|
|
196
|
-
value.withFieldName(key)
|
|
197
|
-
])
|
|
198
|
-
)
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
function createOne(sourceTable) {
|
|
202
|
-
return function one(table, config) {
|
|
203
|
-
return new One(
|
|
204
|
-
sourceTable,
|
|
205
|
-
table,
|
|
206
|
-
config,
|
|
207
|
-
config?.fields.reduce((res, f) => res && f.notNull, true) ?? false
|
|
208
|
-
);
|
|
209
|
-
};
|
|
367
|
+
return row;
|
|
210
368
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
369
|
+
class RelationsBuilderTable {
|
|
370
|
+
static [import_entity.entityKind] = "RelationsBuilderTable";
|
|
371
|
+
_;
|
|
372
|
+
constructor(table, key) {
|
|
373
|
+
this._ = {
|
|
374
|
+
name: key,
|
|
375
|
+
table
|
|
376
|
+
};
|
|
377
|
+
}
|
|
215
378
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
379
|
+
class RelationsBuilderColumn {
|
|
380
|
+
static [import_entity.entityKind] = "RelationsBuilderColumn";
|
|
381
|
+
_;
|
|
382
|
+
constructor(column, tableName, key) {
|
|
383
|
+
this._ = {
|
|
384
|
+
tableName,
|
|
385
|
+
data: void 0,
|
|
386
|
+
column,
|
|
387
|
+
key
|
|
221
388
|
};
|
|
222
389
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
390
|
+
through(column) {
|
|
391
|
+
return new RelationsBuilderJunctionColumn(
|
|
392
|
+
this._.column,
|
|
393
|
+
this._.tableName,
|
|
394
|
+
this._.key,
|
|
395
|
+
column
|
|
227
396
|
);
|
|
228
397
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
398
|
+
}
|
|
399
|
+
class RelationsBuilderJunctionColumn {
|
|
400
|
+
static [import_entity.entityKind] = "RelationsBuilderColumn";
|
|
401
|
+
_;
|
|
402
|
+
constructor(column, tableName, key, through) {
|
|
403
|
+
this._ = {
|
|
404
|
+
tableName,
|
|
405
|
+
data: void 0,
|
|
406
|
+
column,
|
|
407
|
+
through,
|
|
408
|
+
key
|
|
409
|
+
};
|
|
232
410
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
411
|
+
}
|
|
412
|
+
class RelationsHelperStatic {
|
|
413
|
+
static [import_entity.entityKind] = "RelationsHelperStatic";
|
|
414
|
+
_;
|
|
415
|
+
constructor(tables) {
|
|
416
|
+
this._ = {
|
|
417
|
+
tables
|
|
418
|
+
};
|
|
419
|
+
const one = {};
|
|
420
|
+
const many = {};
|
|
421
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
422
|
+
one[tableName] = (config) => {
|
|
423
|
+
return new One(tables, table, config);
|
|
424
|
+
};
|
|
425
|
+
many[tableName] = (config) => {
|
|
426
|
+
return new Many(tables, table, config);
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
this.one = one;
|
|
430
|
+
this.many = many;
|
|
239
431
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
432
|
+
one;
|
|
433
|
+
many;
|
|
434
|
+
/** @internal - to be reworked */
|
|
435
|
+
aggs = {
|
|
436
|
+
count() {
|
|
437
|
+
return new Count();
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function createRelationsHelper(schema) {
|
|
442
|
+
const schemaTables = Object.fromEntries(
|
|
443
|
+
Object.entries(schema).filter((e) => (0, import_entity.is)(e[1], import_table.Table) || (0, import_entity.is)(e[1], import_sql.View))
|
|
444
|
+
);
|
|
445
|
+
const helperStatic = new RelationsHelperStatic(schemaTables);
|
|
446
|
+
const tables = Object.entries(schema).reduce((acc, [tKey, value]) => {
|
|
447
|
+
if ((0, import_entity.is)(value, import_table.Table) || (0, import_entity.is)(value, import_sql.View)) {
|
|
448
|
+
const rTable = new RelationsBuilderTable(value, tKey);
|
|
449
|
+
const columns = Object.entries(value[import_table2.Columns]).reduce(
|
|
450
|
+
(acc2, [cKey, column]) => {
|
|
451
|
+
const rbColumn = new RelationsBuilderColumn(column, tKey, cKey);
|
|
452
|
+
acc2[cKey] = rbColumn;
|
|
453
|
+
return acc2;
|
|
454
|
+
},
|
|
455
|
+
{}
|
|
456
|
+
);
|
|
457
|
+
acc[tKey] = Object.assign(rTable, columns);
|
|
458
|
+
}
|
|
459
|
+
return acc;
|
|
460
|
+
}, {});
|
|
461
|
+
return Object.assign(helperStatic, tables);
|
|
462
|
+
}
|
|
463
|
+
function defineRelations(schema, relations) {
|
|
464
|
+
return new Relations(
|
|
465
|
+
schema,
|
|
466
|
+
schema,
|
|
467
|
+
relations ? relations(createRelationsHelper(schema)) : {}
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
function fieldSelectionToSQL(table, target) {
|
|
471
|
+
const field = table[import_table2.Columns][target];
|
|
472
|
+
return field ? (0, import_entity.is)(field, import_column.Column) ? field : (0, import_entity.is)(field, import_sql.SQL.Aliased) ? import_sql.sql`${table}.${import_sql.sql.identifier(field.fieldAlias)}` : import_sql.sql`${table}.${import_sql.sql.identifier(target)}` : import_sql.sql`${table}.${import_sql.sql.identifier(target)}`;
|
|
473
|
+
}
|
|
474
|
+
function relationsFieldFilterToSQL(column, filter) {
|
|
475
|
+
if (typeof filter !== "object" || (0, import_entity.is)(filter, import_sql.Placeholder))
|
|
476
|
+
return (0, import_expressions.eq)(column, filter);
|
|
477
|
+
const entries = Object.entries(filter);
|
|
478
|
+
if (!entries.length)
|
|
479
|
+
return void 0;
|
|
480
|
+
const parts = [];
|
|
481
|
+
for (const [target, value] of entries) {
|
|
482
|
+
if (value === void 0)
|
|
483
|
+
continue;
|
|
484
|
+
switch (target) {
|
|
485
|
+
case "NOT": {
|
|
486
|
+
const res = relationsFieldFilterToSQL(column, value);
|
|
487
|
+
if (!res)
|
|
488
|
+
continue;
|
|
489
|
+
parts.push((0, import_expressions.not)(res));
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
case "OR": {
|
|
493
|
+
if (!value.length)
|
|
494
|
+
continue;
|
|
495
|
+
parts.push(
|
|
496
|
+
(0, import_expressions.or)(
|
|
497
|
+
...value.map((subFilter) => relationsFieldFilterToSQL(column, subFilter))
|
|
498
|
+
)
|
|
499
|
+
);
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
case "AND": {
|
|
503
|
+
if (!value.length)
|
|
504
|
+
continue;
|
|
505
|
+
parts.push(
|
|
506
|
+
(0, import_expressions.and)(
|
|
507
|
+
...value.map((subFilter) => relationsFieldFilterToSQL(column, subFilter))
|
|
508
|
+
)
|
|
509
|
+
);
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
case "isNotNull":
|
|
513
|
+
case "isNull": {
|
|
514
|
+
if (!value)
|
|
515
|
+
continue;
|
|
516
|
+
parts.push(operators[target](column));
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
case "in": {
|
|
520
|
+
parts.push(operators.inArray(column, value));
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
case "notIn": {
|
|
524
|
+
parts.push(operators.notInArray(column, value));
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
default: {
|
|
528
|
+
parts.push(
|
|
529
|
+
operators[target](
|
|
530
|
+
column,
|
|
531
|
+
value
|
|
532
|
+
)
|
|
533
|
+
);
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
246
536
|
}
|
|
247
537
|
}
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
538
|
+
if (!parts.length)
|
|
539
|
+
return void 0;
|
|
540
|
+
return (0, import_expressions.and)(...parts);
|
|
541
|
+
}
|
|
542
|
+
function relationsFilterToSQL(table, filter, tableRelations = {}, tablesRelations = {}, tableNamesMap = {}, casing, depth = 0) {
|
|
543
|
+
const entries = Object.entries(filter);
|
|
544
|
+
if (!entries.length)
|
|
545
|
+
return void 0;
|
|
546
|
+
const parts = [];
|
|
547
|
+
for (const [target, value] of entries) {
|
|
548
|
+
if (value === void 0)
|
|
549
|
+
continue;
|
|
550
|
+
switch (target) {
|
|
551
|
+
case "RAW": {
|
|
552
|
+
const processed = typeof value === "function" ? value(table, operators) : value.getSQL();
|
|
553
|
+
parts.push(processed);
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
case "OR": {
|
|
557
|
+
if (!value?.length)
|
|
558
|
+
continue;
|
|
559
|
+
parts.push(
|
|
560
|
+
(0, import_expressions.or)(
|
|
561
|
+
...value.map(
|
|
562
|
+
(subFilter) => relationsFilterToSQL(table, subFilter, tableRelations, tablesRelations, tableNamesMap, casing, depth)
|
|
563
|
+
)
|
|
564
|
+
)
|
|
565
|
+
);
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
case "AND": {
|
|
569
|
+
if (!value?.length)
|
|
570
|
+
continue;
|
|
571
|
+
parts.push(
|
|
572
|
+
(0, import_expressions.and)(
|
|
573
|
+
...value.map(
|
|
574
|
+
(subFilter) => relationsFilterToSQL(table, subFilter, tableRelations, tablesRelations, tableNamesMap, casing, depth)
|
|
575
|
+
)
|
|
576
|
+
)
|
|
577
|
+
);
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
case "NOT": {
|
|
581
|
+
if (value === void 0)
|
|
582
|
+
continue;
|
|
583
|
+
const built = relationsFilterToSQL(
|
|
584
|
+
table,
|
|
585
|
+
value,
|
|
586
|
+
tableRelations,
|
|
587
|
+
tablesRelations,
|
|
588
|
+
tableNamesMap,
|
|
589
|
+
casing,
|
|
590
|
+
depth
|
|
591
|
+
);
|
|
592
|
+
if (!built)
|
|
593
|
+
continue;
|
|
594
|
+
parts.push((0, import_expressions.not)(built));
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
default: {
|
|
598
|
+
if (table[import_table2.Columns][target]) {
|
|
599
|
+
const column = fieldSelectionToSQL(table, target);
|
|
600
|
+
const colFilter = relationsFieldFilterToSQL(
|
|
601
|
+
column,
|
|
602
|
+
value
|
|
603
|
+
);
|
|
604
|
+
if (colFilter)
|
|
605
|
+
parts.push(colFilter);
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
608
|
+
const relation = tableRelations[target];
|
|
609
|
+
if (!relation) {
|
|
610
|
+
throw new import_errors.DrizzleError({
|
|
611
|
+
message: `Unknown relational filter field: "${target}"`
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
const targetTable = (0, import_alias.aliasedTable)(relation.targetTable, `f${depth}`);
|
|
615
|
+
const throughTable = relation.throughTable ? (0, import_alias.aliasedTable)(relation.throughTable, `ft${depth}`) : void 0;
|
|
616
|
+
const targetConfig = tablesRelations[tableNamesMap[(0, import_table.getTableUniqueName)(relation.targetTable)]];
|
|
617
|
+
const {
|
|
618
|
+
filter: relationFilter,
|
|
619
|
+
joinCondition
|
|
620
|
+
} = relationToSQL(casing, relation, table, targetTable, throughTable);
|
|
621
|
+
const subfilter = typeof value === "boolean" ? void 0 : relationsFilterToSQL(
|
|
622
|
+
targetTable,
|
|
623
|
+
value,
|
|
624
|
+
targetConfig.relations,
|
|
625
|
+
tablesRelations,
|
|
626
|
+
tableNamesMap,
|
|
627
|
+
casing,
|
|
628
|
+
depth + 1
|
|
629
|
+
);
|
|
630
|
+
const filter2 = (0, import_expressions.and)(
|
|
631
|
+
relationFilter,
|
|
632
|
+
subfilter
|
|
633
|
+
);
|
|
634
|
+
const subquery = throughTable ? import_sql.sql`(select * from ${getTableAsAliasSQL(targetTable)} inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}${import_sql.sql` where ${filter2}`.if(filter2)} limit 1)` : import_sql.sql`(select * from ${getTableAsAliasSQL(targetTable)}${import_sql.sql` where ${filter2}`.if(filter2)} limit 1)`;
|
|
635
|
+
if (filter2)
|
|
636
|
+
parts.push((value ? import_expressions.exists : import_expressions.notExists)(subquery));
|
|
637
|
+
}
|
|
638
|
+
}
|
|
254
639
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
640
|
+
return (0, import_expressions.and)(...parts);
|
|
641
|
+
}
|
|
642
|
+
function relationsOrderToSQL(table, orders) {
|
|
643
|
+
if (typeof orders === "function") {
|
|
644
|
+
const data = orders(table, orderByOperators);
|
|
645
|
+
return (0, import_entity.is)(data, import_sql.SQL) ? data : Array.isArray(data) ? data.length ? import_sql.sql.join(data.map((o) => (0, import_entity.is)(o, import_sql.SQL) ? o : (0, import_expressions.asc)(o)), import_sql.sql`, `) : void 0 : (0, import_entity.is)(data, import_column.Column) ? (0, import_expressions.asc)(data) : void 0;
|
|
260
646
|
}
|
|
261
|
-
|
|
262
|
-
|
|
647
|
+
const entries = Object.entries(orders).filter(([_, value]) => value);
|
|
648
|
+
if (!entries.length)
|
|
649
|
+
return void 0;
|
|
650
|
+
return import_sql.sql.join(
|
|
651
|
+
entries.map(([target, value]) => (value === "asc" ? import_expressions.asc : import_expressions.desc)(fieldSelectionToSQL(table, target))),
|
|
652
|
+
import_sql.sql`, `
|
|
263
653
|
);
|
|
264
654
|
}
|
|
265
|
-
function
|
|
655
|
+
function relationExtrasToSQL(table, extras) {
|
|
656
|
+
const subqueries = [];
|
|
657
|
+
const selection = [];
|
|
658
|
+
for (const [key, field] of Object.entries(extras)) {
|
|
659
|
+
if (!field)
|
|
660
|
+
continue;
|
|
661
|
+
const extra = typeof field === "function" ? field(table, { sql: operators.sql }) : field;
|
|
662
|
+
const query = import_sql.sql`(${extra.getSQL()}) as ${import_sql.sql.identifier(key)}`;
|
|
663
|
+
query.decoder = extra.getSQL().decoder;
|
|
664
|
+
subqueries.push(query);
|
|
665
|
+
selection.push({
|
|
666
|
+
key,
|
|
667
|
+
field: query
|
|
668
|
+
});
|
|
669
|
+
}
|
|
266
670
|
return {
|
|
267
|
-
|
|
268
|
-
|
|
671
|
+
sql: subqueries.length ? import_sql.sql.join(subqueries, import_sql.sql`, `) : void 0,
|
|
672
|
+
selection
|
|
269
673
|
};
|
|
270
674
|
}
|
|
271
|
-
function
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const relation = tableConfig.relations[selectionItem.tsKey];
|
|
279
|
-
const rawSubRows = row[selectionItemIndex];
|
|
280
|
-
const subRows = typeof rawSubRows === "string" ? JSON.parse(rawSubRows) : rawSubRows;
|
|
281
|
-
result[selectionItem.tsKey] = (0, import_entity.is)(relation, One) ? subRows && mapRelationalRow(
|
|
282
|
-
tablesConfig,
|
|
283
|
-
tablesConfig[selectionItem.relationTableTsKey],
|
|
284
|
-
subRows,
|
|
285
|
-
selectionItem.selection,
|
|
286
|
-
mapColumnValue
|
|
287
|
-
) : subRows.map(
|
|
288
|
-
(subRow) => mapRelationalRow(
|
|
289
|
-
tablesConfig,
|
|
290
|
-
tablesConfig[selectionItem.relationTableTsKey],
|
|
291
|
-
subRow,
|
|
292
|
-
selectionItem.selection,
|
|
293
|
-
mapColumnValue
|
|
294
|
-
)
|
|
675
|
+
function relationToSQL(casing, relation, sourceTable, targetTable, throughTable) {
|
|
676
|
+
if (relation.through) {
|
|
677
|
+
const outerColumnWhere = relation.sourceColumns.map((s, i) => {
|
|
678
|
+
const t = relation.through.source[i];
|
|
679
|
+
return (0, import_expressions.eq)(
|
|
680
|
+
import_sql.sql`${sourceTable}.${import_sql.sql.identifier(casing.getColumnCasing(s))}`,
|
|
681
|
+
import_sql.sql`${throughTable}.${import_sql.sql.identifier((0, import_entity.is)(t._.column, import_column.Column) ? casing.getColumnCasing(t._.column) : t._.key)}`
|
|
295
682
|
);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
683
|
+
});
|
|
684
|
+
const innerColumnWhere = relation.targetColumns.map((s, i) => {
|
|
685
|
+
const t = relation.through.target[i];
|
|
686
|
+
return (0, import_expressions.eq)(
|
|
687
|
+
import_sql.sql`${throughTable}.${import_sql.sql.identifier((0, import_entity.is)(t._.column, import_column.Column) ? casing.getColumnCasing(t._.column) : t._.key)}`,
|
|
688
|
+
import_sql.sql`${targetTable}.${import_sql.sql.identifier(casing.getColumnCasing(s))}`
|
|
689
|
+
);
|
|
690
|
+
});
|
|
691
|
+
return {
|
|
692
|
+
filter: (0, import_expressions.and)(
|
|
693
|
+
relation.where ? relationsFilterToSQL(relation.isReversed ? sourceTable : targetTable, relation.where) : void 0,
|
|
694
|
+
...outerColumnWhere
|
|
695
|
+
),
|
|
696
|
+
joinCondition: (0, import_expressions.and)(...innerColumnWhere)
|
|
697
|
+
};
|
|
309
698
|
}
|
|
310
|
-
|
|
699
|
+
const columnWhere = relation.sourceColumns.map((s, i) => {
|
|
700
|
+
const t = relation.targetColumns[i];
|
|
701
|
+
return (0, import_expressions.eq)(
|
|
702
|
+
import_sql.sql`${sourceTable}.${import_sql.sql.identifier(casing.getColumnCasing(s))}`,
|
|
703
|
+
import_sql.sql`${targetTable}.${import_sql.sql.identifier(casing.getColumnCasing(t))}`
|
|
704
|
+
);
|
|
705
|
+
});
|
|
706
|
+
const fullWhere = (0, import_expressions.and)(
|
|
707
|
+
...columnWhere,
|
|
708
|
+
relation.where ? relationsFilterToSQL(relation.isReversed ? sourceTable : targetTable, relation.where) : void 0
|
|
709
|
+
);
|
|
710
|
+
return { filter: fullWhere };
|
|
711
|
+
}
|
|
712
|
+
function getTableAsAliasSQL(table) {
|
|
713
|
+
return import_sql.sql`${table[import_table.IsAlias] ? import_sql.sql`${import_sql.sql`${import_sql.sql.identifier(table[import_table.Schema] ?? "")}.`.if(table[import_table.Schema])}${import_sql.sql.identifier(table[import_table.OriginalName])} as ${table}` : table}`;
|
|
311
714
|
}
|
|
312
715
|
// Annotate the CommonJS export names for ESM import in node:
|
|
313
716
|
0 && (module.exports = {
|
|
717
|
+
AggregatedField,
|
|
718
|
+
Count,
|
|
314
719
|
Many,
|
|
315
720
|
One,
|
|
316
721
|
Relation,
|
|
317
722
|
Relations,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
723
|
+
RelationsBuilderColumn,
|
|
724
|
+
RelationsBuilderJunctionColumn,
|
|
725
|
+
RelationsBuilderTable,
|
|
726
|
+
RelationsHelperStatic,
|
|
727
|
+
createRelationsHelper,
|
|
728
|
+
defineRelations,
|
|
729
|
+
fieldSelectionToSQL,
|
|
323
730
|
getOrderByOperators,
|
|
731
|
+
getTableAsAliasSQL,
|
|
324
732
|
mapRelationalRow,
|
|
325
|
-
|
|
326
|
-
|
|
733
|
+
operators,
|
|
734
|
+
orderByOperators,
|
|
735
|
+
relationExtrasToSQL,
|
|
736
|
+
relationToSQL,
|
|
737
|
+
relationsFilterToSQL,
|
|
738
|
+
relationsOrderToSQL
|
|
327
739
|
});
|
|
328
740
|
//# sourceMappingURL=relations.cjs.map
|