drizzle-orm 0.43.1-b08434e → 0.43.1-d1468f0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/aws-data-api/pg/driver.cjs +5 -1
- package/aws-data-api/pg/driver.cjs.map +1 -1
- package/aws-data-api/pg/driver.d.cts +1 -0
- package/aws-data-api/pg/driver.d.ts +1 -0
- package/aws-data-api/pg/driver.js +5 -1
- package/aws-data-api/pg/driver.js.map +1 -1
- package/aws-data-api/pg/session.cjs +15 -4
- package/aws-data-api/pg/session.cjs.map +1 -1
- package/aws-data-api/pg/session.d.cts +13 -2
- package/aws-data-api/pg/session.d.ts +13 -2
- package/aws-data-api/pg/session.js +15 -4
- package/aws-data-api/pg/session.js.map +1 -1
- package/better-sqlite3/driver.cjs.map +1 -1
- package/better-sqlite3/driver.js.map +1 -1
- package/better-sqlite3/session.cjs +9 -3
- package/better-sqlite3/session.cjs.map +1 -1
- package/better-sqlite3/session.d.cts +12 -2
- package/better-sqlite3/session.d.ts +12 -2
- package/better-sqlite3/session.js +9 -3
- package/better-sqlite3/session.js.map +1 -1
- package/bun-sql/driver.cjs +5 -1
- package/bun-sql/driver.cjs.map +1 -1
- package/bun-sql/driver.js +5 -1
- package/bun-sql/driver.js.map +1 -1
- package/bun-sql/session.cjs +21 -9
- package/bun-sql/session.cjs.map +1 -1
- package/bun-sql/session.d.cts +12 -2
- package/bun-sql/session.d.ts +12 -2
- package/bun-sql/session.js +21 -9
- package/bun-sql/session.js.map +1 -1
- package/cache/core/cache.cjs +47 -0
- package/cache/core/cache.cjs.map +1 -0
- package/cache/core/cache.d.cts +35 -0
- package/cache/core/cache.d.ts +35 -0
- package/cache/core/cache.js +22 -0
- package/cache/core/cache.js.map +1 -0
- package/cache/core/index.cjs +23 -0
- package/cache/core/index.cjs.map +1 -0
- package/cache/core/index.d.cts +1 -0
- package/cache/core/index.d.ts +1 -0
- package/cache/core/index.js +2 -0
- package/cache/core/index.js.map +1 -0
- package/cache/core/types.cjs +17 -0
- package/cache/core/types.cjs.map +1 -0
- package/cache/core/types.d.cts +33 -0
- package/cache/core/types.d.ts +33 -0
- package/cache/core/types.js +1 -0
- package/cache/core/types.js.map +1 -0
- package/cache/upstash/cache.cjs +191 -0
- package/cache/upstash/cache.cjs.map +1 -0
- package/cache/upstash/cache.d.cts +59 -0
- package/cache/upstash/cache.d.ts +59 -0
- package/cache/upstash/cache.js +166 -0
- package/cache/upstash/cache.js.map +1 -0
- package/cache/upstash/index.cjs +23 -0
- package/cache/upstash/index.cjs.map +1 -0
- package/cache/upstash/index.d.cts +1 -0
- package/cache/upstash/index.d.ts +1 -0
- package/cache/upstash/index.js +2 -0
- package/cache/upstash/index.js.map +1 -0
- package/d1/driver.cjs +5 -1
- package/d1/driver.cjs.map +1 -1
- package/d1/driver.js +5 -1
- package/d1/driver.js.map +1 -1
- package/d1/session.cjs +23 -9
- package/d1/session.cjs.map +1 -1
- package/d1/session.d.cts +12 -2
- package/d1/session.d.ts +12 -2
- package/d1/session.js +23 -9
- package/d1/session.js.map +1 -1
- package/durable-sqlite/session.cjs +1 -1
- package/durable-sqlite/session.cjs.map +1 -1
- package/durable-sqlite/session.js +1 -1
- package/durable-sqlite/session.js.map +1 -1
- package/errors/index.cjs +40 -0
- package/errors/index.cjs.map +1 -0
- package/errors/index.d.cts +6 -0
- package/errors/index.d.ts +6 -0
- package/errors/index.js +16 -0
- package/errors/index.js.map +1 -0
- package/gel/driver.cjs +9 -2
- package/gel/driver.cjs.map +1 -1
- package/gel/driver.d.cts +2 -0
- package/gel/driver.d.ts +2 -0
- package/gel/driver.js +9 -2
- package/gel/driver.js.map +1 -1
- package/gel/session.cjs +25 -10
- package/gel/session.cjs.map +1 -1
- package/gel/session.d.cts +12 -2
- package/gel/session.d.ts +12 -2
- package/gel/session.js +25 -10
- package/gel/session.js.map +1 -1
- package/gel-core/db.cjs +3 -0
- package/gel-core/db.cjs.map +1 -1
- package/gel-core/db.d.cts +4 -0
- package/gel-core/db.d.ts +4 -0
- package/gel-core/db.js +3 -0
- package/gel-core/db.js.map +1 -1
- package/gel-core/query-builders/delete.cjs +5 -1
- package/gel-core/query-builders/delete.cjs.map +1 -1
- package/gel-core/query-builders/delete.js +5 -1
- package/gel-core/query-builders/delete.js.map +1 -1
- package/gel-core/query-builders/insert.cjs +5 -1
- package/gel-core/query-builders/insert.cjs.map +1 -1
- package/gel-core/query-builders/insert.js +5 -1
- package/gel-core/query-builders/insert.js.map +1 -1
- package/gel-core/query-builders/select.cjs +29 -4
- package/gel-core/query-builders/select.cjs.map +1 -1
- package/gel-core/query-builders/select.d.cts +9 -0
- package/gel-core/query-builders/select.d.ts +9 -0
- package/gel-core/query-builders/select.js +29 -4
- package/gel-core/query-builders/select.js.map +1 -1
- package/gel-core/query-builders/update.cjs +5 -1
- package/gel-core/query-builders/update.cjs.map +1 -1
- package/gel-core/query-builders/update.js +5 -1
- package/gel-core/query-builders/update.js.map +1 -1
- package/gel-core/session.cjs +79 -1
- package/gel-core/session.cjs.map +1 -1
- package/gel-core/session.d.cts +14 -3
- package/gel-core/session.d.ts +14 -3
- package/gel-core/session.js +80 -2
- package/gel-core/session.js.map +1 -1
- package/gel-core/utils.cjs +16 -0
- package/gel-core/utils.cjs.map +1 -1
- package/gel-core/utils.d.cts +8 -4
- package/gel-core/utils.d.ts +8 -4
- package/gel-core/utils.js +15 -0
- package/gel-core/utils.js.map +1 -1
- package/libsql/driver-core.cjs +5 -1
- package/libsql/driver-core.cjs.map +1 -1
- package/libsql/driver-core.js +5 -1
- package/libsql/driver-core.js.map +1 -1
- package/libsql/session.cjs +27 -13
- package/libsql/session.cjs.map +1 -1
- package/libsql/session.d.cts +12 -2
- package/libsql/session.d.ts +12 -2
- package/libsql/session.js +27 -13
- package/libsql/session.js.map +1 -1
- package/mysql-core/db.cjs +3 -0
- package/mysql-core/db.cjs.map +1 -1
- package/mysql-core/db.d.cts +4 -0
- package/mysql-core/db.d.ts +4 -0
- package/mysql-core/db.js +3 -0
- package/mysql-core/db.js.map +1 -1
- package/mysql-core/query-builders/delete.cjs +9 -1
- package/mysql-core/query-builders/delete.cjs.map +1 -1
- package/mysql-core/query-builders/delete.js +9 -1
- package/mysql-core/query-builders/delete.js.map +1 -1
- package/mysql-core/query-builders/insert.cjs +8 -1
- package/mysql-core/query-builders/insert.cjs.map +1 -1
- package/mysql-core/query-builders/insert.d.cts +2 -0
- package/mysql-core/query-builders/insert.d.ts +2 -0
- package/mysql-core/query-builders/insert.js +8 -1
- package/mysql-core/query-builders/insert.js.map +1 -1
- package/mysql-core/query-builders/select.cjs +27 -3
- package/mysql-core/query-builders/select.cjs.map +1 -1
- package/mysql-core/query-builders/select.d.cts +9 -0
- package/mysql-core/query-builders/select.d.ts +9 -0
- package/mysql-core/query-builders/select.js +28 -4
- package/mysql-core/query-builders/select.js.map +1 -1
- package/mysql-core/query-builders/update.cjs +11 -1
- package/mysql-core/query-builders/update.cjs.map +1 -1
- package/mysql-core/query-builders/update.d.cts +2 -0
- package/mysql-core/query-builders/update.d.ts +2 -0
- package/mysql-core/query-builders/update.js +11 -1
- package/mysql-core/query-builders/update.js.map +1 -1
- package/mysql-core/session.cjs +80 -0
- package/mysql-core/session.cjs.map +1 -1
- package/mysql-core/session.d.cts +15 -2
- package/mysql-core/session.d.ts +15 -2
- package/mysql-core/session.js +81 -1
- package/mysql-core/session.js.map +1 -1
- package/mysql-core/utils.cjs +16 -0
- package/mysql-core/utils.cjs.map +1 -1
- package/mysql-core/utils.d.cts +6 -2
- package/mysql-core/utils.d.ts +6 -2
- package/mysql-core/utils.js +15 -0
- package/mysql-core/utils.js.map +1 -1
- package/mysql-proxy/session.cjs +15 -5
- package/mysql-proxy/session.cjs.map +1 -1
- package/mysql-proxy/session.d.cts +12 -2
- package/mysql-proxy/session.d.ts +12 -2
- package/mysql-proxy/session.js +15 -5
- package/mysql-proxy/session.js.map +1 -1
- package/mysql2/driver.cjs +10 -2
- package/mysql2/driver.cjs.map +1 -1
- package/mysql2/driver.d.cts +2 -0
- package/mysql2/driver.d.ts +2 -0
- package/mysql2/driver.js +10 -2
- package/mysql2/driver.js.map +1 -1
- package/mysql2/session.cjs +15 -5
- package/mysql2/session.cjs.map +1 -1
- package/mysql2/session.d.cts +12 -2
- package/mysql2/session.d.ts +12 -2
- package/mysql2/session.js +15 -5
- package/mysql2/session.js.map +1 -1
- package/neon-http/driver.cjs +9 -2
- package/neon-http/driver.cjs.map +1 -1
- package/neon-http/driver.d.cts +2 -0
- package/neon-http/driver.d.ts +2 -0
- package/neon-http/driver.js +9 -2
- package/neon-http/driver.js.map +1 -1
- package/neon-http/session.cjs +25 -15
- package/neon-http/session.cjs.map +1 -1
- package/neon-http/session.d.cts +12 -2
- package/neon-http/session.d.ts +12 -2
- package/neon-http/session.js +25 -15
- package/neon-http/session.js.map +1 -1
- package/neon-serverless/driver.cjs +9 -2
- package/neon-serverless/driver.cjs.map +1 -1
- package/neon-serverless/driver.d.cts +2 -0
- package/neon-serverless/driver.d.ts +2 -0
- package/neon-serverless/driver.js +9 -2
- package/neon-serverless/driver.js.map +1 -1
- package/neon-serverless/session.cjs +21 -7
- package/neon-serverless/session.cjs.map +1 -1
- package/neon-serverless/session.d.cts +12 -2
- package/neon-serverless/session.d.ts +12 -2
- package/neon-serverless/session.js +21 -7
- package/neon-serverless/session.js.map +1 -1
- package/node-postgres/driver.cjs +9 -2
- package/node-postgres/driver.cjs.map +1 -1
- package/node-postgres/driver.d.cts +2 -0
- package/node-postgres/driver.d.ts +2 -0
- package/node-postgres/driver.js +9 -2
- package/node-postgres/driver.js.map +1 -1
- package/node-postgres/session.cjs +19 -6
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.d.cts +13 -2
- package/node-postgres/session.d.ts +13 -2
- package/node-postgres/session.js +19 -6
- package/node-postgres/session.js.map +1 -1
- package/op-sqlite/driver.cjs +5 -1
- package/op-sqlite/driver.cjs.map +1 -1
- package/op-sqlite/driver.js +5 -1
- package/op-sqlite/driver.js.map +1 -1
- package/op-sqlite/session.cjs +23 -9
- package/op-sqlite/session.cjs.map +1 -1
- package/op-sqlite/session.d.cts +12 -2
- package/op-sqlite/session.d.ts +12 -2
- package/op-sqlite/session.js +23 -9
- package/op-sqlite/session.js.map +1 -1
- package/package.json +75 -10
- package/pg-core/db.cjs +3 -0
- package/pg-core/db.cjs.map +1 -1
- package/pg-core/db.d.cts +4 -0
- package/pg-core/db.d.ts +4 -0
- package/pg-core/db.js +3 -0
- package/pg-core/db.js.map +1 -1
- package/pg-core/query-builders/delete.cjs +6 -1
- package/pg-core/query-builders/delete.cjs.map +1 -1
- package/pg-core/query-builders/delete.d.cts +3 -1
- package/pg-core/query-builders/delete.d.ts +3 -1
- package/pg-core/query-builders/delete.js +6 -1
- package/pg-core/query-builders/delete.js.map +1 -1
- package/pg-core/query-builders/insert.cjs +6 -1
- package/pg-core/query-builders/insert.cjs.map +1 -1
- package/pg-core/query-builders/insert.d.cts +2 -0
- package/pg-core/query-builders/insert.d.ts +2 -0
- package/pg-core/query-builders/insert.js +6 -1
- package/pg-core/query-builders/insert.js.map +1 -1
- package/pg-core/query-builders/select.cjs +31 -5
- package/pg-core/query-builders/select.cjs.map +1 -1
- package/pg-core/query-builders/select.d.cts +15 -6
- package/pg-core/query-builders/select.d.ts +15 -6
- package/pg-core/query-builders/select.js +31 -5
- package/pg-core/query-builders/select.js.map +1 -1
- package/pg-core/query-builders/update.cjs +6 -1
- package/pg-core/query-builders/update.cjs.map +1 -1
- package/pg-core/query-builders/update.d.cts +4 -2
- package/pg-core/query-builders/update.d.ts +4 -2
- package/pg-core/query-builders/update.js +6 -1
- package/pg-core/query-builders/update.js.map +1 -1
- package/pg-core/session.cjs +79 -1
- package/pg-core/session.cjs.map +1 -1
- package/pg-core/session.d.cts +14 -3
- package/pg-core/session.d.ts +14 -3
- package/pg-core/session.js +80 -2
- package/pg-core/session.js.map +1 -1
- package/pg-core/utils.cjs +16 -0
- package/pg-core/utils.cjs.map +1 -1
- package/pg-core/utils.d.cts +8 -4
- package/pg-core/utils.d.ts +8 -4
- package/pg-core/utils.js +16 -1
- package/pg-core/utils.js.map +1 -1
- package/pg-proxy/driver.cjs +7 -2
- package/pg-proxy/driver.cjs.map +1 -1
- package/pg-proxy/driver.js +7 -2
- package/pg-proxy/driver.js.map +1 -1
- package/pg-proxy/session.cjs +15 -5
- package/pg-proxy/session.cjs.map +1 -1
- package/pg-proxy/session.d.cts +12 -2
- package/pg-proxy/session.d.ts +12 -2
- package/pg-proxy/session.js +15 -5
- package/pg-proxy/session.js.map +1 -1
- package/pglite/driver.cjs +9 -2
- package/pglite/driver.cjs.map +1 -1
- package/pglite/driver.d.cts +2 -0
- package/pglite/driver.d.ts +2 -0
- package/pglite/driver.js +9 -2
- package/pglite/driver.js.map +1 -1
- package/pglite/session.cjs +19 -7
- package/pglite/session.cjs.map +1 -1
- package/pglite/session.d.cts +12 -2
- package/pglite/session.d.ts +12 -2
- package/pglite/session.js +19 -7
- package/pglite/session.js.map +1 -1
- package/planetscale-serverless/driver.cjs +5 -1
- package/planetscale-serverless/driver.cjs.map +1 -1
- package/planetscale-serverless/driver.d.cts +1 -0
- package/planetscale-serverless/driver.d.ts +1 -0
- package/planetscale-serverless/driver.js +5 -1
- package/planetscale-serverless/driver.js.map +1 -1
- package/planetscale-serverless/session.cjs +15 -5
- package/planetscale-serverless/session.cjs.map +1 -1
- package/planetscale-serverless/session.d.cts +12 -2
- package/planetscale-serverless/session.d.ts +12 -2
- package/planetscale-serverless/session.js +15 -5
- package/planetscale-serverless/session.js.map +1 -1
- package/postgres-js/driver.cjs +5 -1
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.js +5 -1
- package/postgres-js/driver.js.map +1 -1
- package/postgres-js/session.cjs +18 -6
- package/postgres-js/session.cjs.map +1 -1
- package/postgres-js/session.d.cts +12 -2
- package/postgres-js/session.d.ts +12 -2
- package/postgres-js/session.js +18 -6
- package/postgres-js/session.js.map +1 -1
- package/prisma/mysql/session.cjs +1 -1
- package/prisma/mysql/session.cjs.map +1 -1
- package/prisma/mysql/session.js +1 -1
- package/prisma/mysql/session.js.map +1 -1
- package/prisma/pg/session.cjs +1 -1
- package/prisma/pg/session.cjs.map +1 -1
- package/prisma/pg/session.js +1 -1
- package/prisma/pg/session.js.map +1 -1
- package/query-builders/query-builder.cjs.map +1 -1
- package/query-builders/query-builder.d.cts +2 -1
- package/query-builders/query-builder.d.ts +2 -1
- package/query-builders/query-builder.js.map +1 -1
- package/singlestore/driver.cjs +12 -2
- package/singlestore/driver.cjs.map +1 -1
- package/singlestore/driver.d.cts +2 -0
- package/singlestore/driver.d.ts +2 -0
- package/singlestore/driver.js +12 -2
- package/singlestore/driver.js.map +1 -1
- package/singlestore/session.cjs +15 -5
- package/singlestore/session.cjs.map +1 -1
- package/singlestore/session.d.cts +12 -2
- package/singlestore/session.d.ts +12 -2
- package/singlestore/session.js +15 -5
- package/singlestore/session.js.map +1 -1
- package/singlestore-core/db.cjs +3 -0
- package/singlestore-core/db.cjs.map +1 -1
- package/singlestore-core/db.d.cts +4 -0
- package/singlestore-core/db.d.ts +4 -0
- package/singlestore-core/db.js +3 -0
- package/singlestore-core/db.js.map +1 -1
- package/singlestore-core/query-builders/delete.cjs +9 -1
- package/singlestore-core/query-builders/delete.cjs.map +1 -1
- package/singlestore-core/query-builders/delete.js +9 -1
- package/singlestore-core/query-builders/delete.js.map +1 -1
- package/singlestore-core/query-builders/insert.cjs +6 -1
- package/singlestore-core/query-builders/insert.cjs.map +1 -1
- package/singlestore-core/query-builders/insert.js +6 -1
- package/singlestore-core/query-builders/insert.js.map +1 -1
- package/singlestore-core/query-builders/select.cjs +28 -3
- package/singlestore-core/query-builders/select.cjs.map +1 -1
- package/singlestore-core/query-builders/select.d.cts +9 -0
- package/singlestore-core/query-builders/select.d.ts +9 -0
- package/singlestore-core/query-builders/select.js +28 -3
- package/singlestore-core/query-builders/select.js.map +1 -1
- package/singlestore-core/query-builders/update.cjs +9 -1
- package/singlestore-core/query-builders/update.cjs.map +1 -1
- package/singlestore-core/query-builders/update.js +9 -1
- package/singlestore-core/query-builders/update.js.map +1 -1
- package/singlestore-core/session.cjs +80 -0
- package/singlestore-core/session.cjs.map +1 -1
- package/singlestore-core/session.d.cts +14 -2
- package/singlestore-core/session.d.ts +14 -2
- package/singlestore-core/session.js +81 -1
- package/singlestore-core/session.js.map +1 -1
- package/singlestore-core/utils.cjs +16 -0
- package/singlestore-core/utils.cjs.map +1 -1
- package/singlestore-core/utils.d.cts +3 -0
- package/singlestore-core/utils.d.ts +3 -0
- package/singlestore-core/utils.js +15 -0
- package/singlestore-core/utils.js.map +1 -1
- package/sql/sql.cjs +10 -0
- package/sql/sql.cjs.map +1 -1
- package/sql/sql.js +10 -0
- package/sql/sql.js.map +1 -1
- package/sqlite-core/db.cjs +3 -0
- package/sqlite-core/db.cjs.map +1 -1
- package/sqlite-core/db.d.cts +4 -0
- package/sqlite-core/db.d.ts +4 -0
- package/sqlite-core/db.js +3 -0
- package/sqlite-core/db.js.map +1 -1
- package/sqlite-core/query-builders/delete.cjs +7 -1
- package/sqlite-core/query-builders/delete.cjs.map +1 -1
- package/sqlite-core/query-builders/delete.js +7 -1
- package/sqlite-core/query-builders/delete.js.map +1 -1
- package/sqlite-core/query-builders/insert.cjs +7 -1
- package/sqlite-core/query-builders/insert.cjs.map +1 -1
- package/sqlite-core/query-builders/insert.js +7 -1
- package/sqlite-core/query-builders/insert.js.map +1 -1
- package/sqlite-core/query-builders/select.cjs +31 -3
- package/sqlite-core/query-builders/select.cjs.map +1 -1
- package/sqlite-core/query-builders/select.d.cts +9 -0
- package/sqlite-core/query-builders/select.d.ts +9 -0
- package/sqlite-core/query-builders/select.js +31 -3
- package/sqlite-core/query-builders/select.js.map +1 -1
- package/sqlite-core/query-builders/update.cjs +7 -1
- package/sqlite-core/query-builders/update.cjs.map +1 -1
- package/sqlite-core/query-builders/update.js +7 -1
- package/sqlite-core/query-builders/update.js.map +1 -1
- package/sqlite-core/session.cjs +89 -3
- package/sqlite-core/session.cjs.map +1 -1
- package/sqlite-core/session.d.cts +18 -4
- package/sqlite-core/session.d.ts +18 -4
- package/sqlite-core/session.js +90 -4
- package/sqlite-core/session.js.map +1 -1
- package/sqlite-core/utils.cjs +16 -0
- package/sqlite-core/utils.cjs.map +1 -1
- package/sqlite-core/utils.d.cts +6 -2
- package/sqlite-core/utils.d.ts +6 -2
- package/sqlite-core/utils.js +15 -0
- package/sqlite-core/utils.js.map +1 -1
- package/sqlite-proxy/driver.cjs +9 -2
- package/sqlite-proxy/driver.cjs.map +1 -1
- package/sqlite-proxy/driver.js +9 -2
- package/sqlite-proxy/driver.js.map +1 -1
- package/sqlite-proxy/session.cjs +22 -8
- package/sqlite-proxy/session.cjs.map +1 -1
- package/sqlite-proxy/session.d.cts +12 -2
- package/sqlite-proxy/session.d.ts +12 -2
- package/sqlite-proxy/session.js +22 -8
- package/sqlite-proxy/session.js.map +1 -1
- package/subquery.cjs +4 -3
- package/subquery.cjs.map +1 -1
- package/subquery.d.cts +2 -1
- package/subquery.d.ts +2 -1
- package/subquery.js +4 -3
- package/subquery.js.map +1 -1
- package/tidb-serverless/driver.cjs +5 -1
- package/tidb-serverless/driver.cjs.map +1 -1
- package/tidb-serverless/driver.d.cts +1 -0
- package/tidb-serverless/driver.d.ts +1 -0
- package/tidb-serverless/driver.js +5 -1
- package/tidb-serverless/driver.js.map +1 -1
- package/tidb-serverless/session.cjs +15 -5
- package/tidb-serverless/session.cjs.map +1 -1
- package/tidb-serverless/session.d.cts +12 -2
- package/tidb-serverless/session.d.ts +12 -2
- package/tidb-serverless/session.js +15 -5
- package/tidb-serverless/session.js.map +1 -1
- package/utils.cjs +22 -0
- package/utils.cjs.map +1 -1
- package/utils.d.cts +3 -0
- package/utils.d.ts +3 -0
- package/utils.js +11 -0
- package/utils.js.map +1 -1
- package/vercel-postgres/driver.cjs +9 -2
- package/vercel-postgres/driver.cjs.map +1 -1
- package/vercel-postgres/driver.d.cts +2 -0
- package/vercel-postgres/driver.d.ts +2 -0
- package/vercel-postgres/driver.js +9 -2
- package/vercel-postgres/driver.js.map +1 -1
- package/vercel-postgres/session.cjs +21 -7
- package/vercel-postgres/session.cjs.map +1 -1
- package/vercel-postgres/session.d.cts +12 -2
- package/vercel-postgres/session.d.ts +12 -2
- package/vercel-postgres/session.js +21 -7
- 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 +7 -2
- package/xata-http/driver.cjs.map +1 -1
- package/xata-http/driver.d.cts +2 -0
- package/xata-http/driver.d.ts +2 -0
- package/xata-http/driver.js +7 -2
- package/xata-http/driver.js.map +1 -1
- package/xata-http/session.cjs +21 -7
- package/xata-http/session.cjs.map +1 -1
- package/xata-http/session.d.cts +12 -2
- package/xata-http/session.d.ts +12 -2
- package/xata-http/session.js +21 -7
- package/xata-http/session.js.map +1 -1
|
@@ -4,6 +4,7 @@ import { SelectionProxyHandler } from "../../selection-proxy.js";
|
|
|
4
4
|
import { SQLiteTable } from "../table.js";
|
|
5
5
|
import { Table } from "../../table.js";
|
|
6
6
|
import { orderSelectedFields } from "../../utils.js";
|
|
7
|
+
import { extractUsedTable } from "../utils.js";
|
|
7
8
|
class SQLiteDeleteBase extends QueryPromise {
|
|
8
9
|
constructor(table, session, dialect, withList) {
|
|
9
10
|
super();
|
|
@@ -86,7 +87,12 @@ class SQLiteDeleteBase extends QueryPromise {
|
|
|
86
87
|
this.dialect.sqlToQuery(this.getSQL()),
|
|
87
88
|
this.config.returning,
|
|
88
89
|
this.config.returning ? "all" : "run",
|
|
89
|
-
true
|
|
90
|
+
true,
|
|
91
|
+
void 0,
|
|
92
|
+
{
|
|
93
|
+
type: "delete",
|
|
94
|
+
tables: extractUsedTable(this.config.table)
|
|
95
|
+
}
|
|
90
96
|
);
|
|
91
97
|
}
|
|
92
98
|
prepare() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/sqlite-core/query-builders/delete.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { Placeholder, Query, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Table } from '~/table.ts';\nimport { type DrizzleTypeError, orderSelectedFields, type ValueOrArray } from '~/utils.ts';\nimport type { SQLiteColumn } from '../columns/common.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\n\nexport type SQLiteDeleteWithout<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n> = TDynamic extends true ? T\n\t: Omit<\n\t\tSQLiteDeleteBase<\n\t\t\tT['_']['table'],\n\t\t\tT['_']['resultType'],\n\t\t\tT['_']['runResult'],\n\t\t\tT['_']['returning'],\n\t\t\tTDynamic,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>,\n\t\tT['_']['excludedMethods'] | K\n\t>;\n\nexport type SQLiteDelete<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n> = SQLiteDeleteBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteDeleteConfig {\n\twhere?: SQL | undefined;\n\tlimit?: number | Placeholder;\n\torderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];\n\ttable: SQLiteTable;\n\treturning?: SelectedFieldsOrdered;\n\twithList?: Subquery[];\n}\n\nexport type SQLiteDeleteReturningAll<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteReturning<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteExecute<T extends AnySQLiteDeleteBase> = T['_']['returning'] extends undefined\n\t? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteDeletePrepare<T extends AnySQLiteDeleteBase> = SQLitePreparedQuery<{\n\ttype: T['_']['resultType'];\n\trun: T['_']['runResult'];\n\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t: T['_']['returning'][];\n\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t: T['_']['returning'] | undefined;\n\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t: any[][];\n\texecute: SQLiteDeleteExecute<T>;\n}>;\n\nexport type SQLiteDeleteDynamic<T extends AnySQLiteDeleteBase> = SQLiteDelete<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type AnySQLiteDeleteBase = SQLiteDeleteBase<any, any, any, any, any, any>;\n\nexport interface SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\tdialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteDelete';\n\n\t/** @internal */\n\tconfig: SQLiteDeleteConfig;\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, withList };\n\t}\n\n\t/**\n\t * Adds a `where` clause to the query.\n\t *\n\t * Calling this method will delete only those rows that fulfill a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param where the `where` clause.\n\t *\n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be deleted.\n\t *\n\t * ```ts\n\t * // Delete all cars with green color\n\t * db.delete(cars).where(eq(cars.color, 'green'));\n\t * // or\n\t * db.delete(cars).where(sql`${cars.color} = 'green'`)\n\t * ```\n\t *\n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t *\n\t * ```ts\n\t * // Delete all BMW cars with a green color\n\t * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t *\n\t * // Delete all cars with the green or blue color\n\t * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'> {\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\torderBy(\n\t\tbuilder: (deleteTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>,\n\t): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;\n\torderBy(...columns: (SQLiteColumn | SQL | SQL.Aliased)[]): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;\n\torderBy(\n\t\t...columns:\n\t\t\t| [(deleteTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>]\n\t\t\t| (SQLiteColumn | SQL | SQL.Aliased)[]\n\t): SQLiteDeleteWithout<this, TDynamic, 'orderBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst orderBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.table[Table.Symbol.Columns],\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as any,\n\t\t\t);\n\n\t\t\tconst orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];\n\t\t\tthis.config.orderBy = orderByArray;\n\t\t} else {\n\t\t\tconst orderByArray = columns as (SQLiteColumn | SQL | SQL.Aliased)[];\n\t\t\tthis.config.orderBy = orderByArray;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\tlimit(limit: number | Placeholder): SQLiteDeleteWithout<this, TDynamic, 'limit'> {\n\t\tthis.config.limit = limit;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the deleted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete#delete-with-return}\n\t *\n\t * @example\n\t * ```ts\n\t * // Delete all cars with the green color and return all fields\n\t * const deletedCars: Car[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning();\n\t *\n\t * // Delete all cars with the green color and return only their id and brand fields\n\t * const deletedCarsIdsAndBrands: { id: number, brand: string }[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning({ id: cars.id, brand: cars.brand });\n\t * ```\n\t */\n\treturning(): SQLiteDeleteReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteDeleteReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteDeleteReturning<this, TDynamic, any> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildDeleteQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteDeletePrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t) as SQLiteDeletePrepare<this>;\n\t}\n\n\tprepare(): SQLiteDeletePrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(placeholderValues?: Record<string, unknown>): Promise<SQLiteDeleteExecute<this>> {\n\t\treturn this._prepare().execute(placeholderValues) as SQLiteDeleteExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteDeleteDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB;AAE7B,SAAS,6BAA6B;AAItC,SAAS,mBAAmB;AAE5B,SAAS,aAAa;AACtB,SAAgC,2BAA8C;AAuHvE,MAAM,yBASH,aAEV;AAAA,EAMC,YACS,OACA,SACA,SACR,UACC;AACD,UAAM;AALE;AACA;AACA;AAIR,SAAK,SAAS,EAAE,OAAO,SAAS;AAAA,EACjC;AAAA,EAbA,QAA0B,UAAU,IAAY;AAAA;AAAA,EAGhD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyCA,MAAM,OAAsE;AAC3E,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EAMA,WACI,SAG8C;AACjD,QAAI,OAAO,QAAQ,CAAC,MAAM,YAAY;AACrC,YAAM,UAAU,QAAQ,CAAC;AAAA,QACxB,IAAI;AAAA,UACH,KAAK,OAAO,MAAM,M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IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,SAAS,EAAE,OAAO,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAAe,QAAQ,mBAAiF;AACvG,WAAO,KAAK,SAAS,EAAE,QAAQ,iBAAiB;AAAA,EACjD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/sqlite-core/query-builders/delete.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { Placeholder, Query, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Table } from '~/table.ts';\nimport { type DrizzleTypeError, orderSelectedFields, type ValueOrArray } from '~/utils.ts';\nimport type { SQLiteColumn } from '../columns/common.ts';\nimport { extractUsedTable } from '../utils.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\n\nexport type SQLiteDeleteWithout<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n> = TDynamic extends true ? T\n\t: Omit<\n\t\tSQLiteDeleteBase<\n\t\t\tT['_']['table'],\n\t\t\tT['_']['resultType'],\n\t\t\tT['_']['runResult'],\n\t\t\tT['_']['returning'],\n\t\t\tTDynamic,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>,\n\t\tT['_']['excludedMethods'] | K\n\t>;\n\nexport type SQLiteDelete<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n> = SQLiteDeleteBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteDeleteConfig {\n\twhere?: SQL | undefined;\n\tlimit?: number | Placeholder;\n\torderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];\n\ttable: SQLiteTable;\n\treturning?: SelectedFieldsOrdered;\n\twithList?: Subquery[];\n}\n\nexport type SQLiteDeleteReturningAll<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteReturning<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteExecute<T extends AnySQLiteDeleteBase> = T['_']['returning'] extends undefined\n\t? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteDeletePrepare<T extends AnySQLiteDeleteBase> = SQLitePreparedQuery<{\n\ttype: T['_']['resultType'];\n\trun: T['_']['runResult'];\n\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t: T['_']['returning'][];\n\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t: T['_']['returning'] | undefined;\n\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t: any[][];\n\texecute: SQLiteDeleteExecute<T>;\n}>;\n\nexport type SQLiteDeleteDynamic<T extends AnySQLiteDeleteBase> = SQLiteDelete<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type AnySQLiteDeleteBase = SQLiteDeleteBase<any, any, any, any, any, any>;\n\nexport interface SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\tdialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteDelete';\n\n\t/** @internal */\n\tconfig: SQLiteDeleteConfig;\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, withList };\n\t}\n\n\t/**\n\t * Adds a `where` clause to the query.\n\t *\n\t * Calling this method will delete only those rows that fulfill a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param where the `where` clause.\n\t *\n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be deleted.\n\t *\n\t * ```ts\n\t * // Delete all cars with green color\n\t * db.delete(cars).where(eq(cars.color, 'green'));\n\t * // or\n\t * db.delete(cars).where(sql`${cars.color} = 'green'`)\n\t * ```\n\t *\n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t *\n\t * ```ts\n\t * // Delete all BMW cars with a green color\n\t * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t *\n\t * // Delete all cars with the green or blue color\n\t * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'> {\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\torderBy(\n\t\tbuilder: (deleteTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>,\n\t): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;\n\torderBy(...columns: (SQLiteColumn | SQL | SQL.Aliased)[]): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;\n\torderBy(\n\t\t...columns:\n\t\t\t| [(deleteTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>]\n\t\t\t| (SQLiteColumn | SQL | SQL.Aliased)[]\n\t): SQLiteDeleteWithout<this, TDynamic, 'orderBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst orderBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.table[Table.Symbol.Columns],\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as any,\n\t\t\t);\n\n\t\t\tconst orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];\n\t\t\tthis.config.orderBy = orderByArray;\n\t\t} else {\n\t\t\tconst orderByArray = columns as (SQLiteColumn | SQL | SQL.Aliased)[];\n\t\t\tthis.config.orderBy = orderByArray;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\tlimit(limit: number | Placeholder): SQLiteDeleteWithout<this, TDynamic, 'limit'> {\n\t\tthis.config.limit = limit;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the deleted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete#delete-with-return}\n\t *\n\t * @example\n\t * ```ts\n\t * // Delete all cars with the green color and return all fields\n\t * const deletedCars: Car[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning();\n\t *\n\t * // Delete all cars with the green color and return only their id and brand fields\n\t * const deletedCarsIdsAndBrands: { id: number, brand: string }[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning({ id: cars.id, brand: cars.brand });\n\t * ```\n\t */\n\treturning(): SQLiteDeleteReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteDeleteReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteDeleteReturning<this, TDynamic, any> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildDeleteQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteDeletePrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t\tundefined,\n\t\t\t{\n\t\t\t\ttype: 'delete',\n\t\t\t\ttables: extractUsedTable(this.config.table),\n\t\t\t},\n\t\t) as SQLiteDeletePrepare<this>;\n\t}\n\n\tprepare(): SQLiteDeletePrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(placeholderValues?: Record<string, unknown>): Promise<SQLiteDeleteExecute<this>> {\n\t\treturn this._prepare().execute(placeholderValues) as SQLiteDeleteExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteDeleteDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB;AAE7B,SAAS,6BAA6B;AAItC,SAAS,mBAAmB;AAE5B,SAAS,aAAa;AACtB,SAAgC,2BAA8C;AAE9E,SAAS,wBAAwB;AAsH1B,MAAM,yBASH,aAEV;AAAA,EAMC,YACS,OACA,SACA,SACR,UACC;AACD,UAAM;AALE;AACA;AACA;AAIR,SAAK,SAAS,EAAE,OAAO,SAAS;AAAA,EACjC;AAAA,EAbA,QAA0B,U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AAW,KAAK,OAAO,CAAC;AAAA,MACrC,KAAK,OAAO;AAAA,MACZ,KAAK,OAAO,YAAY,QAAQ;AAAA,MAChC;AAAA,MACA;AAAA,MACA;AAAA,QACC,MAAM;AAAA,QACN,QAAQ,iBAAiB,KAAK,OAAO,KAAK;AAAA,MAC3C;AAAA,IACD;AAAA,EACD;AAAA,EAEA,UAAqC;AACpC,WAAO,KAAK,SAAS,KAAK;AAAA,EAC3B;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,SAAS,EAAE,OAAO,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAAe,QAAQ,mBAAiF;AACvG,WAAO,KAAK,SAAS,EAAE,QAAQ,iBAAiB;AAAA,EACjD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
|
|
@@ -28,6 +28,7 @@ var import_sql = require("../../sql/sql.cjs");
|
|
|
28
28
|
var import_table = require("../table.cjs");
|
|
29
29
|
var import_table2 = require("../../table.cjs");
|
|
30
30
|
var import_utils = require("../../utils.cjs");
|
|
31
|
+
var import_utils2 = require("../utils.cjs");
|
|
31
32
|
var import_query_builder = require("./query-builder.cjs");
|
|
32
33
|
class SQLiteInsertBuilder {
|
|
33
34
|
constructor(table, session, dialect, withList) {
|
|
@@ -172,7 +173,12 @@ class SQLiteInsertBase extends import_query_promise.QueryPromise {
|
|
|
172
173
|
this.dialect.sqlToQuery(this.getSQL()),
|
|
173
174
|
this.config.returning,
|
|
174
175
|
this.config.returning ? "all" : "run",
|
|
175
|
-
true
|
|
176
|
+
true,
|
|
177
|
+
void 0,
|
|
178
|
+
{
|
|
179
|
+
type: "insert",
|
|
180
|
+
tables: (0, import_utils2.extractUsedTable)(this.config.table)
|
|
181
|
+
}
|
|
176
182
|
);
|
|
177
183
|
}
|
|
178
184
|
prepare() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/sqlite-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Placeholder, Query, SQLWrapper } from '~/sql/sql.ts';\nimport { Param, SQL, sql } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { IndexColumn } from '~/sqlite-core/indexes.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { type DrizzleTypeError, haveSameKeys, mapUpdateSet, orderSelectedFields, type Simplify } from '~/utils.ts';\nimport type { AnySQLiteColumn, SQLiteColumn } from '../columns/common.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { SQLiteUpdateSetSource } from './update.ts';\n\nexport interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | SQLiteInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL[];\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n}\n\nexport type SQLiteInsertValue<TTable extends SQLiteTable> = Simplify<\n\t{\n\t\t[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;\n\t}\n>;\n\nexport type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnySQLiteColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class SQLiteInsertBuilder<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteInsertBuilder';\n\n\tconstructor(\n\t\tprotected table: TTable,\n\t\tprotected session: SQLiteSession<any, any, any, any>,\n\t\tprotected dialect: SQLiteDialect,\n\t\tprivate withList?: Subquery[],\n\t) {}\n\n\tvalues(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(\n\t\tvalues: SQLiteInsertValue<TTable> | SQLiteInsertValue<TTable>[],\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tvalues = Array.isArray(values) ? values : [values];\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('values() must be called with at least one value');\n\t\t}\n\t\tconst mappedValues = values.map((entry) => {\n\t\t\tconst result: Record<string, Param | SQL> = {};\n\t\t\tconst cols = this.table[Table.Symbol.Columns];\n\t\t\tfor (const colKey of Object.keys(entry)) {\n\t\t\t\tconst colValue = entry[colKey as keyof typeof entry];\n\t\t\t\tresult[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\n\t\t// if (mappedValues.length > 1 && mappedValues.some((t) => Object.keys(t).length === 0)) {\n\t\t// \tthrow new Error(\n\t\t// \t\t`One of the values you want to insert is empty. In SQLite you can insert only one empty object per statement. For this case Drizzle with use \"INSERT INTO ... DEFAULT VALUES\" syntax`,\n\t\t// \t);\n\t\t// }\n\n\t\treturn new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);\n\t}\n\n\tselect(\n\t\tselectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>,\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| SQLiteInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable> | SQL),\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tSQLiteInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['resultType'],\n\t\t\t\tT['_']['runResult'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | K\n\t\t\t>,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>;\n\nexport type SQLiteInsertReturning<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertReturningAll<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {\n\ttarget: IndexColumn | IndexColumn[];\n\t/** @deprecated - use either `targetWhere` or `setWhere` */\n\twhere?: SQL;\n\t// TODO: add tests for targetWhere and setWhere\n\ttargetWhere?: SQL;\n\tsetWhere?: SQL;\n\tset: SQLiteUpdateSetSource<T['_']['table']>;\n};\n\nexport type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsert<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type SQLiteInsertExecute<T extends AnySQLiteInsert> = T['_']['returning'] extends undefined ? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteInsertPrepare<T extends AnySQLiteInsert> = SQLitePreparedQuery<\n\t{\n\t\ttype: T['_']['resultType'];\n\t\trun: T['_']['runResult'];\n\t\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'][];\n\t\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'];\n\t\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t\t: any[][];\n\t\texecute: SQLiteInsertExecute<T>;\n\t}\n>;\n\nexport type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;\n\nexport type SQLiteInsert<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = any,\n> = SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tSQLWrapper,\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>\n{\n\treadonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteInsert';\n\n\t/** @internal */\n\tconfig: SQLiteInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: SQLiteInsertConfig['values'],\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select };\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and return all fields\n\t * const insertedCar: Car[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning();\n\t *\n\t * // Insert one row and return only the id\n\t * const insertedCarId: { id: number }[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning({ id: cars.id });\n\t * ```\n\t */\n\treturning(): SQLiteInsertReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteInsertWithout<AnySQLiteInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `on conflict do nothing` clause to the query.\n\t *\n\t * Calling this method simply avoids inserting a row as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}\n\t *\n\t * @param config The `target` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and cancel the insert if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing();\n\t *\n\t * // Explicitly specify conflict target\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing({ target: cars.id });\n\t * ```\n\t */\n\tonConflictDoNothing(config: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {}): this {\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tif (config.target === undefined) {\n\t\t\tthis.config.onConflict.push(sql` on conflict do nothing`);\n\t\t} else {\n\t\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\t\tconst whereSql = config.where ? sql` where ${config.where}` : sql``;\n\t\t\tthis.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an `on conflict do update` clause to the query.\n\t *\n\t * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}\n\t *\n\t * @param config The `target`, `set` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Update the row if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'Porsche' }\n\t * });\n\t *\n\t * // Upsert with 'where' clause\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'newBMW' },\n\t * where: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\tonConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this {\n\t\tif (config.where && (config.targetWhere || config.setWhere)) {\n\t\t\tthrow new Error(\n\t\t\t\t'You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.',\n\t\t\t);\n\t\t}\n\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t\tconst targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;\n\t\tconst setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;\n\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict.push(\n\t\t\tsql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`,\n\t\t);\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildInsertQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteInsertPrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t) as SQLiteInsertPrepare<this>;\n\t}\n\n\tprepare(): SQLiteInsertPrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(): Promise<SQLiteInsertExecute<this>> {\n\t\treturn (this.config.returning ? this.all() : this.run()) as SQLiteInsertExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mapp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BAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,SAAS,EAAE,OAAO,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAAe,UAA8C;AAC5D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":["import_table"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/sqlite-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Placeholder, Query, SQLWrapper } from '~/sql/sql.ts';\nimport { Param, SQL, sql } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { IndexColumn } from '~/sqlite-core/indexes.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { type DrizzleTypeError, haveSameKeys, mapUpdateSet, orderSelectedFields, type Simplify } from '~/utils.ts';\nimport type { AnySQLiteColumn, SQLiteColumn } from '../columns/common.ts';\nimport { extractUsedTable } from '../utils.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { SQLiteUpdateSetSource } from './update.ts';\n\nexport interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | SQLiteInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL[];\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n}\n\nexport type SQLiteInsertValue<TTable extends SQLiteTable> = Simplify<\n\t{\n\t\t[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;\n\t}\n>;\n\nexport type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnySQLiteColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class SQLiteInsertBuilder<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteInsertBuilder';\n\n\tconstructor(\n\t\tprotected table: TTable,\n\t\tprotected session: SQLiteSession<any, any, any, any>,\n\t\tprotected dialect: SQLiteDialect,\n\t\tprivate withList?: Subquery[],\n\t) {}\n\n\tvalues(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(\n\t\tvalues: SQLiteInsertValue<TTable> | SQLiteInsertValue<TTable>[],\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tvalues = Array.isArray(values) ? values : [values];\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('values() must be called with at least one value');\n\t\t}\n\t\tconst mappedValues = values.map((entry) => {\n\t\t\tconst result: Record<string, Param | SQL> = {};\n\t\t\tconst cols = this.table[Table.Symbol.Columns];\n\t\t\tfor (const colKey of Object.keys(entry)) {\n\t\t\t\tconst colValue = entry[colKey as keyof typeof entry];\n\t\t\t\tresult[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\n\t\t// if (mappedValues.length > 1 && mappedValues.some((t) => Object.keys(t).length === 0)) {\n\t\t// \tthrow new Error(\n\t\t// \t\t`One of the values you want to insert is empty. In SQLite you can insert only one empty object per statement. For this case Drizzle with use \"INSERT INTO ... DEFAULT VALUES\" syntax`,\n\t\t// \t);\n\t\t// }\n\n\t\treturn new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);\n\t}\n\n\tselect(\n\t\tselectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>,\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| SQLiteInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable> | SQL),\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tSQLiteInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['resultType'],\n\t\t\t\tT['_']['runResult'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | K\n\t\t\t>,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>;\n\nexport type SQLiteInsertReturning<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertReturningAll<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {\n\ttarget: IndexColumn | IndexColumn[];\n\t/** @deprecated - use either `targetWhere` or `setWhere` */\n\twhere?: SQL;\n\t// TODO: add tests for targetWhere and setWhere\n\ttargetWhere?: SQL;\n\tsetWhere?: SQL;\n\tset: SQLiteUpdateSetSource<T['_']['table']>;\n};\n\nexport type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsert<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type SQLiteInsertExecute<T extends AnySQLiteInsert> = T['_']['returning'] extends undefined ? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteInsertPrepare<T extends AnySQLiteInsert> = SQLitePreparedQuery<\n\t{\n\t\ttype: T['_']['resultType'];\n\t\trun: T['_']['runResult'];\n\t\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'][];\n\t\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'];\n\t\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t\t: any[][];\n\t\texecute: SQLiteInsertExecute<T>;\n\t}\n>;\n\nexport type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;\n\nexport type SQLiteInsert<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = any,\n> = SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tSQLWrapper,\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>\n{\n\treadonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteInsert';\n\n\t/** @internal */\n\tconfig: SQLiteInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: SQLiteInsertConfig['values'],\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select };\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and return all fields\n\t * const insertedCar: Car[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning();\n\t *\n\t * // Insert one row and return only the id\n\t * const insertedCarId: { id: number }[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning({ id: cars.id });\n\t * ```\n\t */\n\treturning(): SQLiteInsertReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteInsertWithout<AnySQLiteInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `on conflict do nothing` clause to the query.\n\t *\n\t * Calling this method simply avoids inserting a row as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}\n\t *\n\t * @param config The `target` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and cancel the insert if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing();\n\t *\n\t * // Explicitly specify conflict target\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing({ target: cars.id });\n\t * ```\n\t */\n\tonConflictDoNothing(config: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {}): this {\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tif (config.target === undefined) {\n\t\t\tthis.config.onConflict.push(sql` on conflict do nothing`);\n\t\t} else {\n\t\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\t\tconst whereSql = config.where ? sql` where ${config.where}` : sql``;\n\t\t\tthis.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an `on conflict do update` clause to the query.\n\t *\n\t * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}\n\t *\n\t * @param config The `target`, `set` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Update the row if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'Porsche' }\n\t * });\n\t *\n\t * // Upsert with 'where' clause\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'newBMW' },\n\t * where: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\tonConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this {\n\t\tif (config.where && (config.targetWhere || config.setWhere)) {\n\t\t\tthrow new Error(\n\t\t\t\t'You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.',\n\t\t\t);\n\t\t}\n\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t\tconst targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;\n\t\tconst setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;\n\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict.push(\n\t\t\tsql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`,\n\t\t);\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildInsertQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteInsertPrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t\tundefined,\n\t\t\t{\n\t\t\t\ttype: 'insert',\n\t\t\t\ttables: extractUsedTable(this.config.table),\n\t\t\t},\n\t\t) as SQLiteInsertPrepare<this>;\n\t}\n\n\tprepare(): SQLiteInsertPrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(): Promise<SQLiteInsertExecute<this>> {\n\t\treturn (this.config.returning ? this.all() : this.run()) as SQLiteInsertExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+B;AAG/B,2BAA6B;AAG7B,iBAAgC;AAIhC,mBAA4B;AAE5B,IAAAA,gBAA+B;AAC/B,mBAAsG;AAEtG,IAAAC,gBAAiC;AACjC,2BAA6B;AAuBtB,MAAM,oBAIX;AAAA,EAGD,YACW,OACA,SACA,SACF,UACP;AAJS;AACA;AACA;AACF;AAAA,EACN;AAAA,EAPH,QAAiB,wBAAU,IAAY;AAAA,EAWvC,OACC,QACoD;AACpD,aAAS,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AACjD,QAAI,OAAO,WAAW,GAAG;AACxB,YAAM,IAAI,MAAM,iDAAiD;AAAA,IAClE;AACA,UAAM,eAAe,OAAO,IAAI,CAAC,UAAU;AAC1C,YAAM,SAAsC,CAAC;AAC7C,YAAM,OAAO,KAAK,MAAM,oBAAM,OAAO,OAAO;AAC5C,iBAAW,UAAU,OAAO,KAAK,KAAK,GAAG;AACxC,cAAM,WAAW,MAAM,MAA4B;AACnD,eAAO,MAAM,QAAI,kBAAG,UAAU,cAAG,IAAI,WAAW,IAAI,iBAAM,UAAU,KAAK,MAAM,CAAC;AAAA,MACjF;AACA,aAAO;AAAA,IACR,CAAC;AAQD,WAAO,IAAI,iBAAiB,KAAK,OAAO,cAAc,KAAK,SAAS,KAAK,SAAS,KAAK,QAAQ;AAAA,EAChG;AAAA,EAQA,OACC,aAIoD;AACpD,UAAM,SAAS,OAAO,gBAAgB,aAAa,YAA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AAA,MACZ,KAAK,OAAO,YAAY,QAAQ;AAAA,MAChC;AAAA,MACA;AAAA,MACA;AAAA,QACC,MAAM;AAAA,QACN,YAAQ,gCAAiB,KAAK,OAAO,KAAK;AAAA,MAC3C;AAAA,IACD;AAAA,EACD;AAAA,EAEA,UAAqC;AACpC,WAAO,KAAK,SAAS,KAAK;AAAA,EAC3B;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,SAAS,EAAE,OAAO,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAAe,UAA8C;AAC5D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":["import_table","import_utils"]}
|
|
@@ -4,6 +4,7 @@ import { Param, SQL, sql } from "../../sql/sql.js";
|
|
|
4
4
|
import { SQLiteTable } from "../table.js";
|
|
5
5
|
import { Columns, Table } from "../../table.js";
|
|
6
6
|
import { haveSameKeys, mapUpdateSet, orderSelectedFields } from "../../utils.js";
|
|
7
|
+
import { extractUsedTable } from "../utils.js";
|
|
7
8
|
import { QueryBuilder } from "./query-builder.js";
|
|
8
9
|
class SQLiteInsertBuilder {
|
|
9
10
|
constructor(table, session, dialect, withList) {
|
|
@@ -148,7 +149,12 @@ class SQLiteInsertBase extends QueryPromise {
|
|
|
148
149
|
this.dialect.sqlToQuery(this.getSQL()),
|
|
149
150
|
this.config.returning,
|
|
150
151
|
this.config.returning ? "all" : "run",
|
|
151
|
-
true
|
|
152
|
+
true,
|
|
153
|
+
void 0,
|
|
154
|
+
{
|
|
155
|
+
type: "insert",
|
|
156
|
+
tables: extractUsedTable(this.config.table)
|
|
157
|
+
}
|
|
152
158
|
);
|
|
153
159
|
}
|
|
154
160
|
prepare() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/sqlite-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Placeholder, Query, SQLWrapper } from '~/sql/sql.ts';\nimport { Param, SQL, sql } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { IndexColumn } from '~/sqlite-core/indexes.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { type DrizzleTypeError, haveSameKeys, mapUpdateSet, orderSelectedFields, type Simplify } from '~/utils.ts';\nimport type { AnySQLiteColumn, SQLiteColumn } from '../columns/common.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { SQLiteUpdateSetSource } from './update.ts';\n\nexport interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | SQLiteInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL[];\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n}\n\nexport type SQLiteInsertValue<TTable extends SQLiteTable> = Simplify<\n\t{\n\t\t[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;\n\t}\n>;\n\nexport type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnySQLiteColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class SQLiteInsertBuilder<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteInsertBuilder';\n\n\tconstructor(\n\t\tprotected table: TTable,\n\t\tprotected session: SQLiteSession<any, any, any, any>,\n\t\tprotected dialect: SQLiteDialect,\n\t\tprivate withList?: Subquery[],\n\t) {}\n\n\tvalues(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(\n\t\tvalues: SQLiteInsertValue<TTable> | SQLiteInsertValue<TTable>[],\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tvalues = Array.isArray(values) ? values : [values];\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('values() must be called with at least one value');\n\t\t}\n\t\tconst mappedValues = values.map((entry) => {\n\t\t\tconst result: Record<string, Param | SQL> = {};\n\t\t\tconst cols = this.table[Table.Symbol.Columns];\n\t\t\tfor (const colKey of Object.keys(entry)) {\n\t\t\t\tconst colValue = entry[colKey as keyof typeof entry];\n\t\t\t\tresult[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\n\t\t// if (mappedValues.length > 1 && mappedValues.some((t) => Object.keys(t).length === 0)) {\n\t\t// \tthrow new Error(\n\t\t// \t\t`One of the values you want to insert is empty. In SQLite you can insert only one empty object per statement. For this case Drizzle with use \"INSERT INTO ... DEFAULT VALUES\" syntax`,\n\t\t// \t);\n\t\t// }\n\n\t\treturn new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);\n\t}\n\n\tselect(\n\t\tselectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>,\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| SQLiteInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable> | SQL),\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tSQLiteInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['resultType'],\n\t\t\t\tT['_']['runResult'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | K\n\t\t\t>,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>;\n\nexport type SQLiteInsertReturning<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertReturningAll<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {\n\ttarget: IndexColumn | IndexColumn[];\n\t/** @deprecated - use either `targetWhere` or `setWhere` */\n\twhere?: SQL;\n\t// TODO: add tests for targetWhere and setWhere\n\ttargetWhere?: SQL;\n\tsetWhere?: SQL;\n\tset: SQLiteUpdateSetSource<T['_']['table']>;\n};\n\nexport type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsert<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type SQLiteInsertExecute<T extends AnySQLiteInsert> = T['_']['returning'] extends undefined ? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteInsertPrepare<T extends AnySQLiteInsert> = SQLitePreparedQuery<\n\t{\n\t\ttype: T['_']['resultType'];\n\t\trun: T['_']['runResult'];\n\t\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'][];\n\t\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'];\n\t\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t\t: any[][];\n\t\texecute: SQLiteInsertExecute<T>;\n\t}\n>;\n\nexport type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;\n\nexport type SQLiteInsert<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = any,\n> = SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tSQLWrapper,\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>\n{\n\treadonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteInsert';\n\n\t/** @internal */\n\tconfig: SQLiteInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: SQLiteInsertConfig['values'],\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select };\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and return all fields\n\t * const insertedCar: Car[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning();\n\t *\n\t * // Insert one row and return only the id\n\t * const insertedCarId: { id: number }[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning({ id: cars.id });\n\t * ```\n\t */\n\treturning(): SQLiteInsertReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteInsertWithout<AnySQLiteInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `on conflict do nothing` clause to the query.\n\t *\n\t * Calling this method simply avoids inserting a row as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}\n\t *\n\t * @param config The `target` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and cancel the insert if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing();\n\t *\n\t * // Explicitly specify conflict target\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing({ target: cars.id });\n\t * ```\n\t */\n\tonConflictDoNothing(config: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {}): this {\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tif (config.target === undefined) {\n\t\t\tthis.config.onConflict.push(sql` on conflict do nothing`);\n\t\t} else {\n\t\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\t\tconst whereSql = config.where ? sql` where ${config.where}` : sql``;\n\t\t\tthis.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an `on conflict do update` clause to the query.\n\t *\n\t * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}\n\t *\n\t * @param config The `target`, `set` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Update the row if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'Porsche' }\n\t * });\n\t *\n\t * // Upsert with 'where' clause\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'newBMW' },\n\t * where: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\tonConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this {\n\t\tif (config.where && (config.targetWhere || config.setWhere)) {\n\t\t\tthrow new Error(\n\t\t\t\t'You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.',\n\t\t\t);\n\t\t}\n\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t\tconst targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;\n\t\tconst setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;\n\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict.push(\n\t\t\tsql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`,\n\t\t);\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildInsertQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteInsertPrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t) as SQLiteInsertPrepare<this>;\n\t}\n\n\tprepare(): SQLiteInsertPrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(): Promise<SQLiteInsertExecute<this>> {\n\t\treturn (this.config.returning ? this.all() : this.run()) as SQLiteInsertExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AAAA,SAAS,Y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AA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,SAAS,EAAE,OAAO,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAAe,UAA8C;AAC5D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/sqlite-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Placeholder, Query, SQLWrapper } from '~/sql/sql.ts';\nimport { Param, SQL, sql } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { IndexColumn } from '~/sqlite-core/indexes.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { type DrizzleTypeError, haveSameKeys, mapUpdateSet, orderSelectedFields, type Simplify } from '~/utils.ts';\nimport type { AnySQLiteColumn, SQLiteColumn } from '../columns/common.ts';\nimport { extractUsedTable } from '../utils.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { SQLiteUpdateSetSource } from './update.ts';\n\nexport interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | SQLiteInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL[];\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n}\n\nexport type SQLiteInsertValue<TTable extends SQLiteTable> = Simplify<\n\t{\n\t\t[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;\n\t}\n>;\n\nexport type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnySQLiteColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class SQLiteInsertBuilder<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteInsertBuilder';\n\n\tconstructor(\n\t\tprotected table: TTable,\n\t\tprotected session: SQLiteSession<any, any, any, any>,\n\t\tprotected dialect: SQLiteDialect,\n\t\tprivate withList?: Subquery[],\n\t) {}\n\n\tvalues(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(\n\t\tvalues: SQLiteInsertValue<TTable> | SQLiteInsertValue<TTable>[],\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tvalues = Array.isArray(values) ? values : [values];\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('values() must be called with at least one value');\n\t\t}\n\t\tconst mappedValues = values.map((entry) => {\n\t\t\tconst result: Record<string, Param | SQL> = {};\n\t\t\tconst cols = this.table[Table.Symbol.Columns];\n\t\t\tfor (const colKey of Object.keys(entry)) {\n\t\t\t\tconst colValue = entry[colKey as keyof typeof entry];\n\t\t\t\tresult[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\n\t\t// if (mappedValues.length > 1 && mappedValues.some((t) => Object.keys(t).length === 0)) {\n\t\t// \tthrow new Error(\n\t\t// \t\t`One of the values you want to insert is empty. In SQLite you can insert only one empty object per statement. For this case Drizzle with use \"INSERT INTO ... DEFAULT VALUES\" syntax`,\n\t\t// \t);\n\t\t// }\n\n\t\treturn new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);\n\t}\n\n\tselect(\n\t\tselectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>,\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| SQLiteInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable> | SQL),\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tSQLiteInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['resultType'],\n\t\t\t\tT['_']['runResult'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | K\n\t\t\t>,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>;\n\nexport type SQLiteInsertReturning<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertReturningAll<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {\n\ttarget: IndexColumn | IndexColumn[];\n\t/** @deprecated - use either `targetWhere` or `setWhere` */\n\twhere?: SQL;\n\t// TODO: add tests for targetWhere and setWhere\n\ttargetWhere?: SQL;\n\tsetWhere?: SQL;\n\tset: SQLiteUpdateSetSource<T['_']['table']>;\n};\n\nexport type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsert<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type SQLiteInsertExecute<T extends AnySQLiteInsert> = T['_']['returning'] extends undefined ? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteInsertPrepare<T extends AnySQLiteInsert> = SQLitePreparedQuery<\n\t{\n\t\ttype: T['_']['resultType'];\n\t\trun: T['_']['runResult'];\n\t\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'][];\n\t\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'];\n\t\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t\t: any[][];\n\t\texecute: SQLiteInsertExecute<T>;\n\t}\n>;\n\nexport type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;\n\nexport type SQLiteInsert<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = any,\n> = SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tSQLWrapper,\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>\n{\n\treadonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteInsert';\n\n\t/** @internal */\n\tconfig: SQLiteInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: SQLiteInsertConfig['values'],\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select };\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and return all fields\n\t * const insertedCar: Car[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning();\n\t *\n\t * // Insert one row and return only the id\n\t * const insertedCarId: { id: number }[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning({ id: cars.id });\n\t * ```\n\t */\n\treturning(): SQLiteInsertReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteInsertWithout<AnySQLiteInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `on conflict do nothing` clause to the query.\n\t *\n\t * Calling this method simply avoids inserting a row as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}\n\t *\n\t * @param config The `target` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and cancel the insert if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing();\n\t *\n\t * // Explicitly specify conflict target\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing({ target: cars.id });\n\t * ```\n\t */\n\tonConflictDoNothing(config: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {}): this {\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tif (config.target === undefined) {\n\t\t\tthis.config.onConflict.push(sql` on conflict do nothing`);\n\t\t} else {\n\t\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\t\tconst whereSql = config.where ? sql` where ${config.where}` : sql``;\n\t\t\tthis.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an `on conflict do update` clause to the query.\n\t *\n\t * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}\n\t *\n\t * @param config The `target`, `set` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Update the row if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'Porsche' }\n\t * });\n\t *\n\t * // Upsert with 'where' clause\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'newBMW' },\n\t * where: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\tonConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this {\n\t\tif (config.where && (config.targetWhere || config.setWhere)) {\n\t\t\tthrow new Error(\n\t\t\t\t'You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.',\n\t\t\t);\n\t\t}\n\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t\tconst targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;\n\t\tconst setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;\n\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict.push(\n\t\t\tsql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`,\n\t\t);\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildInsertQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteInsertPrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t\tundefined,\n\t\t\t{\n\t\t\t\ttype: 'insert',\n\t\t\t\ttables: extractUsedTable(this.config.table),\n\t\t\t},\n\t\t) as SQLiteInsertPrepare<this>;\n\t}\n\n\tprepare(): SQLiteInsertPrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(): Promise<SQLiteInsertExecute<this>> {\n\t\treturn (this.config.returning ? this.all() : this.run()) as SQLiteInsertExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AAAA,SAAS,YAAY,UAAU;AAG/B,SAAS,oBAAoB;AAG7B,SAAS,OAAO,KAAK,WAAW;AAIhC,SAAS,mBAAmB;AAE5B,SAAS,SAAS,aAAa;AAC/B,SAAgC,cAAc,cAAc,2BAA0C;AAEtG,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAuBtB,MAAM,oBAIX;AAAA,EAGD,YACW,OACA,SACA,SACF,UACP;AAJS;AACA;AACA;AACF;AAAA,EACN;AAAA,EAPH,QAAiB,UAAU,IAAY;AAAA,EAWvC,OACC,QACoD;AACpD,aAAS,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AACjD,QAAI,OAAO,WAAW,GAAG;AACxB,YAAM,IAAI,MAAM,iDAAiD;AAAA,IAClE;AACA,UAAM,eAAe,OAAO,IAAI,CAAC,UAAU;AAC1C,YAAM,SAAsC,CAAC;AAC7C,YAAM,OAAO,KAAK,MAAM,MAAM,OAAO,OAAO;AAC5C,iBAAW,UAAU,OAAO,KAAK,KAAK,GAAG;AACxC,cAAM,WAAW,MAAM,MAA4B;AACnD,eAAO,MAAM,IAAI,GAAG,UAAU,GAAG,IAAI,WAAW,IAAI,MAAM,UAAU,KAAK,MAAM,CAAC;AAAA,MACjF;AACA,aAAO;AAAA,IACR,CAAC;AAQD,WAAO,IAAI,iBAAiB,KAAK,OAAO,cAAc,KAAK,SAAS,KAAK,SAAS,KAAK,QAAQ;AAAA,EAChG;AAAA,EAQA,OACC,aAIoD;AACpD,UAAM,SAAS,OAAO,gBAAgB,aAAa,YAAY,IAAI,aAAa,CAAC,IAAI;AAErF,QACC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A;AAAA,MACA;AAAA,QACC,MAAM;AAAA,QACN,QAAQ,iBAAiB,KAAK,OAAO,KAAK;AAAA,MAC3C;AAAA,IACD;AAAA,EACD;AAAA,EAEA,UAAqC;AACpC,WAAO,KAAK,SAAS,KAAK;AAAA,EAC3B;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,SAAS,EAAE,OAAO,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAAe,UAA8C;AAC5D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
|
|
@@ -36,6 +36,7 @@ var import_subquery = require("../../subquery.cjs");
|
|
|
36
36
|
var import_table = require("../../table.cjs");
|
|
37
37
|
var import_utils = require("../../utils.cjs");
|
|
38
38
|
var import_view_common = require("../../view-common.cjs");
|
|
39
|
+
var import_utils2 = require("../utils.cjs");
|
|
39
40
|
var import_view_base = require("../view-base.cjs");
|
|
40
41
|
class SQLiteSelectBuilder {
|
|
41
42
|
static [import_entity.entityKind] = "SQLiteSelectBuilder";
|
|
@@ -88,6 +89,8 @@ class SQLiteSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilde
|
|
|
88
89
|
isPartialSelect;
|
|
89
90
|
session;
|
|
90
91
|
dialect;
|
|
92
|
+
cacheConfig = void 0;
|
|
93
|
+
usedTables = /* @__PURE__ */ new Set();
|
|
91
94
|
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
|
|
92
95
|
super();
|
|
93
96
|
this.config = {
|
|
@@ -101,15 +104,24 @@ class SQLiteSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilde
|
|
|
101
104
|
this.session = session;
|
|
102
105
|
this.dialect = dialect;
|
|
103
106
|
this._ = {
|
|
104
|
-
selectedFields: fields
|
|
107
|
+
selectedFields: fields,
|
|
108
|
+
config: this.config
|
|
105
109
|
};
|
|
106
110
|
this.tableName = (0, import_utils.getTableLikeName)(table);
|
|
107
111
|
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
|
112
|
+
for (const item of (0, import_utils2.extractUsedTable)(table))
|
|
113
|
+
this.usedTables.add(item);
|
|
114
|
+
}
|
|
115
|
+
/** @internal */
|
|
116
|
+
getUsedTables() {
|
|
117
|
+
return [...this.usedTables];
|
|
108
118
|
}
|
|
109
119
|
createJoin(joinType) {
|
|
110
120
|
return (table, on) => {
|
|
111
121
|
const baseTableName = this.tableName;
|
|
112
122
|
const tableName = (0, import_utils.getTableLikeName)(table);
|
|
123
|
+
for (const item of (0, import_utils2.extractUsedTable)(table))
|
|
124
|
+
this.usedTables.add(item);
|
|
113
125
|
if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
|
|
114
126
|
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
115
127
|
}
|
|
@@ -596,8 +608,14 @@ class SQLiteSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilde
|
|
|
596
608
|
return rest;
|
|
597
609
|
}
|
|
598
610
|
as(alias) {
|
|
611
|
+
const usedTables = [];
|
|
612
|
+
usedTables.push(...(0, import_utils2.extractUsedTable)(this.config.table));
|
|
613
|
+
if (this.config.joins) {
|
|
614
|
+
for (const it of this.config.joins)
|
|
615
|
+
usedTables.push(...(0, import_utils2.extractUsedTable)(it.table));
|
|
616
|
+
}
|
|
599
617
|
return new Proxy(
|
|
600
|
-
new import_subquery.Subquery(this.getSQL(), this.config.fields, alias),
|
|
618
|
+
new import_subquery.Subquery(this.getSQL(), this.config.fields, alias, false, [...new Set(usedTables)]),
|
|
601
619
|
new import_selection_proxy.SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
|
602
620
|
);
|
|
603
621
|
}
|
|
@@ -624,11 +642,21 @@ class SQLiteSelectBase extends SQLiteSelectQueryBuilderBase {
|
|
|
624
642
|
this.dialect.sqlToQuery(this.getSQL()),
|
|
625
643
|
fieldsList,
|
|
626
644
|
"all",
|
|
627
|
-
true
|
|
645
|
+
true,
|
|
646
|
+
void 0,
|
|
647
|
+
{
|
|
648
|
+
type: "select",
|
|
649
|
+
tables: [...this.usedTables]
|
|
650
|
+
},
|
|
651
|
+
this.cacheConfig
|
|
628
652
|
);
|
|
629
653
|
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
|
630
654
|
return query;
|
|
631
655
|
}
|
|
656
|
+
$withCache(config) {
|
|
657
|
+
this.cacheConfig = config === void 0 ? { config: {}, enable: true, autoInvalidate: true } : config === false ? { enable: false } : { enable: true, autoInvalidate: true, ...config };
|
|
658
|
+
return this;
|
|
659
|
+
}
|
|
632
660
|
prepare() {
|
|
633
661
|
return this._prepare(false);
|
|
634
662
|
}
|