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