drizzle-orm 0.42.0-da9af74 → 0.43.0-62ea5c4
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 +1 -5
- package/aws-data-api/pg/driver.cjs.map +1 -1
- package/aws-data-api/pg/driver.d.cts +0 -1
- package/aws-data-api/pg/driver.d.ts +0 -1
- package/aws-data-api/pg/driver.js +1 -5
- package/aws-data-api/pg/driver.js.map +1 -1
- package/aws-data-api/pg/session.cjs +4 -15
- package/aws-data-api/pg/session.cjs.map +1 -1
- package/aws-data-api/pg/session.d.cts +2 -13
- package/aws-data-api/pg/session.d.ts +2 -13
- package/aws-data-api/pg/session.js +4 -15
- 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 +3 -9
- package/better-sqlite3/session.cjs.map +1 -1
- package/better-sqlite3/session.d.cts +2 -12
- package/better-sqlite3/session.d.ts +2 -12
- package/better-sqlite3/session.js +3 -9
- package/better-sqlite3/session.js.map +1 -1
- package/bun-sql/driver.cjs +1 -5
- package/bun-sql/driver.cjs.map +1 -1
- package/bun-sql/driver.js +1 -5
- package/bun-sql/driver.js.map +1 -1
- package/bun-sql/session.cjs +9 -21
- package/bun-sql/session.cjs.map +1 -1
- package/bun-sql/session.d.cts +2 -12
- package/bun-sql/session.d.ts +2 -12
- package/bun-sql/session.js +9 -21
- package/bun-sql/session.js.map +1 -1
- package/d1/driver.cjs +1 -5
- package/d1/driver.cjs.map +1 -1
- package/d1/driver.js +1 -5
- package/d1/driver.js.map +1 -1
- package/d1/session.cjs +9 -23
- package/d1/session.cjs.map +1 -1
- package/d1/session.d.cts +2 -12
- package/d1/session.d.ts +2 -12
- package/d1/session.js +9 -23
- 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/gel/driver.cjs +2 -9
- package/gel/driver.cjs.map +1 -1
- package/gel/driver.d.cts +0 -2
- package/gel/driver.d.ts +0 -2
- package/gel/driver.js +2 -9
- package/gel/driver.js.map +1 -1
- package/gel/session.cjs +10 -25
- package/gel/session.cjs.map +1 -1
- package/gel/session.d.cts +2 -12
- package/gel/session.d.ts +2 -12
- package/gel/session.js +10 -25
- package/gel/session.js.map +1 -1
- package/gel-core/db.cjs +0 -1
- package/gel-core/db.cjs.map +1 -1
- package/gel-core/db.d.cts +0 -4
- package/gel-core/db.d.ts +0 -4
- package/gel-core/db.js +0 -1
- package/gel-core/db.js.map +1 -1
- package/gel-core/dialect.cjs +8 -23
- package/gel-core/dialect.cjs.map +1 -1
- package/gel-core/dialect.d.cts +1 -0
- package/gel-core/dialect.d.ts +1 -0
- package/gel-core/dialect.js +8 -23
- package/gel-core/dialect.js.map +1 -1
- package/gel-core/query-builders/delete.cjs +1 -5
- package/gel-core/query-builders/delete.cjs.map +1 -1
- package/gel-core/query-builders/delete.js +1 -5
- package/gel-core/query-builders/delete.js.map +1 -1
- package/gel-core/query-builders/insert.cjs +1 -5
- package/gel-core/query-builders/insert.cjs.map +1 -1
- package/gel-core/query-builders/insert.js +1 -5
- package/gel-core/query-builders/insert.js.map +1 -1
- package/gel-core/query-builders/select.cjs +84 -43
- package/gel-core/query-builders/select.cjs.map +1 -1
- package/gel-core/query-builders/select.d.cts +78 -22
- package/gel-core/query-builders/select.d.ts +78 -22
- package/gel-core/query-builders/select.js +84 -43
- package/gel-core/query-builders/select.js.map +1 -1
- package/gel-core/query-builders/select.types.cjs.map +1 -1
- package/gel-core/query-builders/select.types.d.cts +1 -1
- package/gel-core/query-builders/select.types.d.ts +1 -1
- package/gel-core/query-builders/update.cjs +1 -5
- package/gel-core/query-builders/update.cjs.map +1 -1
- package/gel-core/query-builders/update.js +1 -5
- package/gel-core/query-builders/update.js.map +1 -1
- package/gel-core/session.cjs +1 -52
- package/gel-core/session.cjs.map +1 -1
- package/gel-core/session.d.cts +3 -14
- package/gel-core/session.d.ts +3 -14
- package/gel-core/session.js +2 -53
- package/gel-core/session.js.map +1 -1
- package/gel-core/utils.cjs +0 -16
- package/gel-core/utils.cjs.map +1 -1
- package/gel-core/utils.d.cts +4 -8
- package/gel-core/utils.d.ts +4 -8
- package/gel-core/utils.js +0 -15
- package/gel-core/utils.js.map +1 -1
- package/libsql/driver-core.cjs +1 -5
- package/libsql/driver-core.cjs.map +1 -1
- package/libsql/driver-core.js +1 -5
- package/libsql/driver-core.js.map +1 -1
- package/libsql/session.cjs +13 -27
- package/libsql/session.cjs.map +1 -1
- package/libsql/session.d.cts +2 -12
- package/libsql/session.d.ts +2 -12
- package/libsql/session.js +13 -27
- package/libsql/session.js.map +1 -1
- package/mysql-core/db.cjs +0 -1
- package/mysql-core/db.cjs.map +1 -1
- package/mysql-core/db.d.cts +0 -4
- package/mysql-core/db.d.ts +0 -4
- package/mysql-core/db.js +0 -1
- package/mysql-core/db.js.map +1 -1
- package/mysql-core/dialect.cjs +5 -4
- package/mysql-core/dialect.cjs.map +1 -1
- package/mysql-core/dialect.js +5 -4
- package/mysql-core/dialect.js.map +1 -1
- package/mysql-core/query-builders/delete.cjs +1 -9
- package/mysql-core/query-builders/delete.cjs.map +1 -1
- package/mysql-core/query-builders/delete.js +1 -9
- package/mysql-core/query-builders/delete.js.map +1 -1
- package/mysql-core/query-builders/insert.cjs +1 -8
- package/mysql-core/query-builders/insert.cjs.map +1 -1
- package/mysql-core/query-builders/insert.d.cts +0 -2
- package/mysql-core/query-builders/insert.d.ts +0 -2
- package/mysql-core/query-builders/insert.js +1 -8
- package/mysql-core/query-builders/insert.js.map +1 -1
- package/mysql-core/query-builders/select.cjs +75 -61
- package/mysql-core/query-builders/select.cjs.map +1 -1
- package/mysql-core/query-builders/select.d.cts +66 -34
- package/mysql-core/query-builders/select.d.ts +66 -34
- package/mysql-core/query-builders/select.js +76 -62
- package/mysql-core/query-builders/select.js.map +1 -1
- package/mysql-core/query-builders/select.types.cjs.map +1 -1
- package/mysql-core/query-builders/select.types.d.cts +5 -4
- package/mysql-core/query-builders/select.types.d.ts +5 -4
- package/mysql-core/query-builders/update.cjs +1 -11
- package/mysql-core/query-builders/update.cjs.map +1 -1
- package/mysql-core/query-builders/update.d.cts +0 -2
- package/mysql-core/query-builders/update.d.ts +0 -2
- package/mysql-core/query-builders/update.js +1 -11
- package/mysql-core/query-builders/update.js.map +1 -1
- package/mysql-core/session.cjs +0 -53
- package/mysql-core/session.cjs.map +1 -1
- package/mysql-core/session.d.cts +2 -15
- package/mysql-core/session.d.ts +2 -15
- package/mysql-core/session.js +1 -54
- package/mysql-core/session.js.map +1 -1
- package/mysql-core/utils.cjs +0 -16
- package/mysql-core/utils.cjs.map +1 -1
- package/mysql-core/utils.d.cts +2 -6
- package/mysql-core/utils.d.ts +2 -6
- package/mysql-core/utils.js +0 -15
- package/mysql-core/utils.js.map +1 -1
- package/mysql-proxy/session.cjs +5 -15
- package/mysql-proxy/session.cjs.map +1 -1
- package/mysql-proxy/session.d.cts +2 -12
- package/mysql-proxy/session.d.ts +2 -12
- package/mysql-proxy/session.js +5 -15
- package/mysql-proxy/session.js.map +1 -1
- package/mysql2/driver.cjs +2 -10
- package/mysql2/driver.cjs.map +1 -1
- package/mysql2/driver.d.cts +0 -2
- package/mysql2/driver.d.ts +0 -2
- package/mysql2/driver.js +2 -10
- package/mysql2/driver.js.map +1 -1
- package/mysql2/session.cjs +5 -15
- package/mysql2/session.cjs.map +1 -1
- package/mysql2/session.d.cts +2 -12
- package/mysql2/session.d.ts +2 -12
- package/mysql2/session.js +5 -15
- package/mysql2/session.js.map +1 -1
- package/neon-http/driver.cjs +2 -9
- package/neon-http/driver.cjs.map +1 -1
- package/neon-http/driver.d.cts +0 -2
- package/neon-http/driver.d.ts +0 -2
- package/neon-http/driver.js +2 -9
- package/neon-http/driver.js.map +1 -1
- package/neon-http/session.cjs +15 -25
- package/neon-http/session.cjs.map +1 -1
- package/neon-http/session.d.cts +2 -12
- package/neon-http/session.d.ts +2 -12
- package/neon-http/session.js +15 -25
- package/neon-http/session.js.map +1 -1
- package/neon-serverless/driver.cjs +2 -9
- package/neon-serverless/driver.cjs.map +1 -1
- package/neon-serverless/driver.d.cts +0 -2
- package/neon-serverless/driver.d.ts +0 -2
- package/neon-serverless/driver.js +2 -9
- package/neon-serverless/driver.js.map +1 -1
- package/neon-serverless/session.cjs +7 -21
- package/neon-serverless/session.cjs.map +1 -1
- package/neon-serverless/session.d.cts +2 -12
- package/neon-serverless/session.d.ts +2 -12
- package/neon-serverless/session.js +7 -21
- package/neon-serverless/session.js.map +1 -1
- package/node-postgres/driver.cjs +2 -9
- package/node-postgres/driver.cjs.map +1 -1
- package/node-postgres/driver.d.cts +0 -2
- package/node-postgres/driver.d.ts +0 -2
- package/node-postgres/driver.js +2 -9
- package/node-postgres/driver.js.map +1 -1
- package/node-postgres/session.cjs +6 -19
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.d.cts +2 -13
- package/node-postgres/session.d.ts +2 -13
- package/node-postgres/session.js +6 -19
- package/node-postgres/session.js.map +1 -1
- package/op-sqlite/driver.cjs +1 -5
- package/op-sqlite/driver.cjs.map +1 -1
- package/op-sqlite/driver.js +1 -5
- package/op-sqlite/driver.js.map +1 -1
- package/op-sqlite/session.cjs +9 -23
- package/op-sqlite/session.cjs.map +1 -1
- package/op-sqlite/session.d.cts +2 -12
- package/op-sqlite/session.d.ts +2 -12
- package/op-sqlite/session.js +9 -23
- package/op-sqlite/session.js.map +1 -1
- package/operations.cjs.map +1 -1
- package/operations.d.cts +5 -1
- package/operations.d.ts +5 -1
- package/package.json +4 -69
- package/pg-core/columns/text.cjs.map +1 -1
- package/pg-core/columns/text.d.cts +1 -2
- package/pg-core/columns/text.d.ts +1 -2
- package/pg-core/columns/text.js.map +1 -1
- package/pg-core/db.cjs +0 -1
- package/pg-core/db.cjs.map +1 -1
- package/pg-core/db.d.cts +0 -4
- package/pg-core/db.d.ts +0 -4
- package/pg-core/db.js +0 -1
- package/pg-core/db.js.map +1 -1
- package/pg-core/dialect.cjs +5 -4
- package/pg-core/dialect.cjs.map +1 -1
- package/pg-core/dialect.js +5 -4
- package/pg-core/dialect.js.map +1 -1
- package/pg-core/query-builders/delete.cjs +1 -6
- package/pg-core/query-builders/delete.cjs.map +1 -1
- package/pg-core/query-builders/delete.d.cts +1 -3
- package/pg-core/query-builders/delete.d.ts +1 -3
- package/pg-core/query-builders/delete.js +1 -6
- package/pg-core/query-builders/delete.js.map +1 -1
- package/pg-core/query-builders/insert.cjs +1 -6
- package/pg-core/query-builders/insert.cjs.map +1 -1
- package/pg-core/query-builders/insert.d.cts +0 -2
- package/pg-core/query-builders/insert.d.ts +0 -2
- package/pg-core/query-builders/insert.js +1 -6
- package/pg-core/query-builders/insert.js.map +1 -1
- package/pg-core/query-builders/select.cjs +85 -45
- package/pg-core/query-builders/select.cjs.map +1 -1
- package/pg-core/query-builders/select.d.cts +79 -23
- package/pg-core/query-builders/select.d.ts +79 -23
- package/pg-core/query-builders/select.js +85 -45
- package/pg-core/query-builders/select.js.map +1 -1
- package/pg-core/query-builders/select.types.cjs.map +1 -1
- package/pg-core/query-builders/select.types.d.cts +1 -1
- package/pg-core/query-builders/select.types.d.ts +1 -1
- package/pg-core/query-builders/update.cjs +1 -6
- package/pg-core/query-builders/update.cjs.map +1 -1
- package/pg-core/query-builders/update.d.cts +2 -4
- package/pg-core/query-builders/update.d.ts +2 -4
- package/pg-core/query-builders/update.js +1 -6
- package/pg-core/query-builders/update.js.map +1 -1
- package/pg-core/session.cjs +1 -52
- package/pg-core/session.cjs.map +1 -1
- package/pg-core/session.d.cts +3 -14
- package/pg-core/session.d.ts +3 -14
- package/pg-core/session.js +2 -53
- package/pg-core/session.js.map +1 -1
- package/pg-core/utils.cjs +0 -16
- package/pg-core/utils.cjs.map +1 -1
- package/pg-core/utils.d.cts +4 -8
- package/pg-core/utils.d.ts +4 -8
- package/pg-core/utils.js +1 -16
- package/pg-core/utils.js.map +1 -1
- package/pg-proxy/driver.cjs +2 -7
- package/pg-proxy/driver.cjs.map +1 -1
- package/pg-proxy/driver.js +2 -7
- package/pg-proxy/driver.js.map +1 -1
- package/pg-proxy/session.cjs +5 -15
- package/pg-proxy/session.cjs.map +1 -1
- package/pg-proxy/session.d.cts +2 -12
- package/pg-proxy/session.d.ts +2 -12
- package/pg-proxy/session.js +5 -15
- package/pg-proxy/session.js.map +1 -1
- package/pglite/driver.cjs +2 -9
- package/pglite/driver.cjs.map +1 -1
- package/pglite/driver.d.cts +0 -2
- package/pglite/driver.d.ts +0 -2
- package/pglite/driver.js +2 -9
- package/pglite/driver.js.map +1 -1
- package/pglite/session.cjs +7 -19
- package/pglite/session.cjs.map +1 -1
- package/pglite/session.d.cts +2 -12
- package/pglite/session.d.ts +2 -12
- package/pglite/session.js +7 -19
- package/pglite/session.js.map +1 -1
- package/planetscale-serverless/driver.cjs +1 -5
- package/planetscale-serverless/driver.cjs.map +1 -1
- package/planetscale-serverless/driver.d.cts +0 -1
- package/planetscale-serverless/driver.d.ts +0 -1
- package/planetscale-serverless/driver.js +1 -5
- package/planetscale-serverless/driver.js.map +1 -1
- package/planetscale-serverless/session.cjs +5 -15
- package/planetscale-serverless/session.cjs.map +1 -1
- package/planetscale-serverless/session.d.cts +2 -12
- package/planetscale-serverless/session.d.ts +2 -12
- package/planetscale-serverless/session.js +5 -15
- package/planetscale-serverless/session.js.map +1 -1
- package/postgres-js/driver.cjs +1 -5
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.js +1 -5
- package/postgres-js/driver.js.map +1 -1
- package/postgres-js/session.cjs +6 -18
- package/postgres-js/session.cjs.map +1 -1
- package/postgres-js/session.d.cts +2 -12
- package/postgres-js/session.d.ts +2 -12
- package/postgres-js/session.js +6 -18
- 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 +1 -2
- package/query-builders/query-builder.d.ts +1 -2
- package/query-builders/query-builder.js.map +1 -1
- package/query-builders/select.types.cjs.map +1 -1
- package/query-builders/select.types.d.cts +3 -1
- package/query-builders/select.types.d.ts +3 -1
- package/singlestore/driver.cjs +26 -14
- package/singlestore/driver.cjs.map +1 -1
- package/singlestore/driver.d.cts +3 -7
- package/singlestore/driver.d.ts +3 -7
- package/singlestore/driver.js +26 -14
- package/singlestore/driver.js.map +1 -1
- package/singlestore/session.cjs +5 -15
- package/singlestore/session.cjs.map +1 -1
- package/singlestore/session.d.cts +2 -12
- package/singlestore/session.d.ts +2 -12
- package/singlestore/session.js +5 -15
- package/singlestore/session.js.map +1 -1
- package/singlestore-core/db.cjs +0 -1
- package/singlestore-core/db.cjs.map +1 -1
- package/singlestore-core/db.d.cts +0 -4
- package/singlestore-core/db.d.ts +0 -4
- package/singlestore-core/db.js +0 -1
- package/singlestore-core/db.js.map +1 -1
- package/singlestore-core/dialect.cjs +5 -4
- package/singlestore-core/dialect.cjs.map +1 -1
- package/singlestore-core/dialect.js +5 -4
- package/singlestore-core/dialect.js.map +1 -1
- package/singlestore-core/query-builders/delete.cjs +1 -9
- package/singlestore-core/query-builders/delete.cjs.map +1 -1
- package/singlestore-core/query-builders/delete.js +1 -9
- package/singlestore-core/query-builders/delete.js.map +1 -1
- package/singlestore-core/query-builders/insert.cjs +1 -6
- package/singlestore-core/query-builders/insert.cjs.map +1 -1
- package/singlestore-core/query-builders/insert.js +1 -6
- package/singlestore-core/query-builders/insert.js.map +1 -1
- package/singlestore-core/query-builders/select.cjs +83 -42
- package/singlestore-core/query-builders/select.cjs.map +1 -1
- package/singlestore-core/query-builders/select.d.cts +78 -22
- package/singlestore-core/query-builders/select.d.ts +78 -22
- package/singlestore-core/query-builders/select.js +83 -42
- package/singlestore-core/query-builders/select.js.map +1 -1
- package/singlestore-core/query-builders/select.types.cjs.map +1 -1
- package/singlestore-core/query-builders/select.types.d.cts +1 -2
- package/singlestore-core/query-builders/select.types.d.ts +1 -2
- package/singlestore-core/query-builders/update.cjs +1 -9
- package/singlestore-core/query-builders/update.cjs.map +1 -1
- package/singlestore-core/query-builders/update.js +1 -9
- package/singlestore-core/query-builders/update.js.map +1 -1
- package/singlestore-core/session.cjs +0 -53
- package/singlestore-core/session.cjs.map +1 -1
- package/singlestore-core/session.d.cts +2 -14
- package/singlestore-core/session.d.ts +2 -14
- package/singlestore-core/session.js +1 -54
- package/singlestore-core/session.js.map +1 -1
- package/singlestore-core/utils.cjs +0 -16
- package/singlestore-core/utils.cjs.map +1 -1
- package/singlestore-core/utils.d.cts +0 -3
- package/singlestore-core/utils.d.ts +0 -3
- package/singlestore-core/utils.js +0 -15
- package/singlestore-core/utils.js.map +1 -1
- package/sql/sql.cjs +0 -10
- package/sql/sql.cjs.map +1 -1
- package/sql/sql.js +0 -10
- package/sql/sql.js.map +1 -1
- package/sqlite-core/db.cjs +0 -1
- package/sqlite-core/db.cjs.map +1 -1
- package/sqlite-core/db.d.cts +0 -4
- package/sqlite-core/db.d.ts +0 -4
- package/sqlite-core/db.js +0 -1
- package/sqlite-core/db.js.map +1 -1
- package/sqlite-core/dialect.cjs +3 -2
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.js +3 -2
- package/sqlite-core/dialect.js.map +1 -1
- package/sqlite-core/query-builders/delete.cjs +1 -7
- package/sqlite-core/query-builders/delete.cjs.map +1 -1
- package/sqlite-core/query-builders/delete.js +1 -7
- package/sqlite-core/query-builders/delete.js.map +1 -1
- package/sqlite-core/query-builders/insert.cjs +1 -7
- package/sqlite-core/query-builders/insert.cjs.map +1 -1
- package/sqlite-core/query-builders/insert.js +1 -7
- package/sqlite-core/query-builders/insert.js.map +1 -1
- package/sqlite-core/query-builders/select.cjs +39 -39
- package/sqlite-core/query-builders/select.cjs.map +1 -1
- package/sqlite-core/query-builders/select.d.cts +40 -22
- package/sqlite-core/query-builders/select.d.ts +40 -22
- package/sqlite-core/query-builders/select.js +39 -39
- package/sqlite-core/query-builders/select.js.map +1 -1
- package/sqlite-core/query-builders/select.types.cjs.map +1 -1
- package/sqlite-core/query-builders/select.types.d.cts +1 -1
- package/sqlite-core/query-builders/select.types.d.ts +1 -1
- package/sqlite-core/query-builders/update.cjs +1 -7
- package/sqlite-core/query-builders/update.cjs.map +1 -1
- package/sqlite-core/query-builders/update.js +1 -7
- package/sqlite-core/query-builders/update.js.map +1 -1
- package/sqlite-core/session.cjs +3 -62
- package/sqlite-core/session.cjs.map +1 -1
- package/sqlite-core/session.d.cts +4 -18
- package/sqlite-core/session.d.ts +4 -18
- package/sqlite-core/session.js +4 -63
- package/sqlite-core/session.js.map +1 -1
- package/sqlite-core/utils.cjs +0 -16
- package/sqlite-core/utils.cjs.map +1 -1
- package/sqlite-core/utils.d.cts +2 -6
- package/sqlite-core/utils.d.ts +2 -6
- package/sqlite-core/utils.js +0 -15
- package/sqlite-core/utils.js.map +1 -1
- package/sqlite-proxy/driver.cjs +2 -9
- package/sqlite-proxy/driver.cjs.map +1 -1
- package/sqlite-proxy/driver.js +2 -9
- package/sqlite-proxy/driver.js.map +1 -1
- package/sqlite-proxy/session.cjs +8 -22
- package/sqlite-proxy/session.cjs.map +1 -1
- package/sqlite-proxy/session.d.cts +2 -12
- package/sqlite-proxy/session.d.ts +2 -12
- package/sqlite-proxy/session.js +8 -22
- package/sqlite-proxy/session.js.map +1 -1
- package/subquery.cjs +3 -4
- package/subquery.cjs.map +1 -1
- package/subquery.d.cts +1 -2
- package/subquery.d.ts +1 -2
- package/subquery.js +3 -4
- package/subquery.js.map +1 -1
- package/tidb-serverless/driver.cjs +1 -5
- package/tidb-serverless/driver.cjs.map +1 -1
- package/tidb-serverless/driver.d.cts +0 -1
- package/tidb-serverless/driver.d.ts +0 -1
- package/tidb-serverless/driver.js +1 -5
- package/tidb-serverless/driver.js.map +1 -1
- package/tidb-serverless/session.cjs +5 -15
- package/tidb-serverless/session.cjs.map +1 -1
- package/tidb-serverless/session.d.cts +2 -12
- package/tidb-serverless/session.d.ts +2 -12
- package/tidb-serverless/session.js +5 -15
- package/tidb-serverless/session.js.map +1 -1
- package/utils.cjs +0 -22
- package/utils.cjs.map +1 -1
- package/utils.d.cts +0 -3
- package/utils.d.ts +0 -3
- package/utils.js +0 -11
- package/utils.js.map +1 -1
- package/vercel-postgres/driver.cjs +2 -9
- package/vercel-postgres/driver.cjs.map +1 -1
- package/vercel-postgres/driver.d.cts +0 -2
- package/vercel-postgres/driver.d.ts +0 -2
- package/vercel-postgres/driver.js +2 -9
- package/vercel-postgres/driver.js.map +1 -1
- package/vercel-postgres/session.cjs +7 -21
- package/vercel-postgres/session.cjs.map +1 -1
- package/vercel-postgres/session.d.cts +2 -12
- package/vercel-postgres/session.d.ts +2 -12
- package/vercel-postgres/session.js +7 -21
- 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 +2 -7
- package/xata-http/driver.cjs.map +1 -1
- package/xata-http/driver.d.cts +0 -2
- package/xata-http/driver.d.ts +0 -2
- package/xata-http/driver.js +2 -7
- package/xata-http/driver.js.map +1 -1
- package/xata-http/session.cjs +7 -21
- package/xata-http/session.cjs.map +1 -1
- package/xata-http/session.d.cts +2 -12
- package/xata-http/session.d.ts +2 -12
- package/xata-http/session.js +7 -21
- package/xata-http/session.js.map +1 -1
- package/cache/core/cache.cjs +0 -47
- package/cache/core/cache.cjs.map +0 -1
- package/cache/core/cache.d.cts +0 -35
- package/cache/core/cache.d.ts +0 -35
- package/cache/core/cache.js +0 -22
- package/cache/core/cache.js.map +0 -1
- package/cache/core/index.cjs +0 -23
- package/cache/core/index.cjs.map +0 -1
- package/cache/core/index.d.cts +0 -1
- package/cache/core/index.d.ts +0 -1
- package/cache/core/index.js +0 -2
- package/cache/core/index.js.map +0 -1
- package/cache/core/types.cjs +0 -17
- package/cache/core/types.cjs.map +0 -1
- package/cache/core/types.d.cts +0 -33
- package/cache/core/types.d.ts +0 -33
- package/cache/core/types.js +0 -1
- package/cache/core/types.js.map +0 -1
- package/cache/upstash/cache.cjs +0 -148
- package/cache/upstash/cache.cjs.map +0 -1
- package/cache/upstash/cache.d.cts +0 -29
- package/cache/upstash/cache.d.ts +0 -29
- package/cache/upstash/cache.js +0 -123
- package/cache/upstash/cache.js.map +0 -1
- package/cache/upstash/index.cjs +0 -23
- package/cache/upstash/index.cjs.map +0 -1
- package/cache/upstash/index.d.cts +0 -1
- package/cache/upstash/index.d.ts +0 -1
- package/cache/upstash/index.js +0 -2
- package/cache/upstash/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/gel-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { GelDialect } from '~/gel-core/dialect.ts';\nimport type { IndexColumn } from '~/gel-core/indexes.ts';\nimport type {\n\tGelPreparedQuery,\n\tGelQueryResultHKT,\n\tGelQueryResultKind,\n\tGelSession,\n\tPreparedQueryConfig,\n} from '~/gel-core/session.ts';\nimport type { GelTable, TableConfig } from '~/gel-core/table.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 } from '~/sql/sql.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport type { InferInsertModel } from '~/table.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { tracer } from '~/tracing.ts';\nimport { haveSameKeys, type NeonAuthToken, orderSelectedFields } from '~/utils.ts';\nimport type { AnyGelColumn, GelColumn } 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 { GelUpdateSetSource } from './update.ts';\n\nexport interface GelInsertConfig<TTable extends GelTable = GelTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | GelInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL;\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n\toverridingSystemValue_?: boolean;\n}\n\nexport type GelInsertValue<TTable extends GelTable<TableConfig>, OverrideT extends boolean = false> =\n\t& {\n\t\t[Key in keyof InferInsertModel<TTable, { dbColumnNames: false; override: OverrideT }>]:\n\t\t\t| InferInsertModel<TTable, { dbColumnNames: false; override: OverrideT }>[Key]\n\t\t\t| SQL\n\t\t\t| Placeholder;\n\t}\n\t& {};\n\nexport type GelInsertSelectQueryBuilder<TTable extends GelTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnyGelColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class GelInsertBuilder<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\n\tOverrideT extends boolean = false,\n> {\n\tstatic readonly [entityKind]: string = 'GelInsertBuilder';\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: GelSession,\n\t\tprivate dialect: GelDialect,\n\t\tprivate withList?: Subquery[],\n\t\tprivate overridingSystemValue_?: boolean,\n\t) {}\n\n\tprivate authToken?: NeonAuthToken;\n\t/** @internal */\n\tsetToken(token?: NeonAuthToken) {\n\t\tthis.authToken = token;\n\t\treturn this;\n\t}\n\n\toverridingSystemValue(): Omit<GelInsertBuilder<TTable, TQueryResult, true>, 'overridingSystemValue'> {\n\t\tthis.overridingSystemValue_ = true;\n\t\treturn this as any;\n\t}\n\n\tvalues(value: GelInsertValue<TTable, OverrideT>): GelInsertBase<TTable, TQueryResult>;\n\tvalues(values: GelInsertValue<TTable, OverrideT>[]): GelInsertBase<TTable, TQueryResult>;\n\tvalues(\n\t\tvalues: GelInsertValue<TTable, OverrideT> | GelInsertValue<TTable, OverrideT>[],\n\t): GelInsertBase<TTable, TQueryResult> {\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\treturn new GelInsertBase(\n\t\t\tthis.table,\n\t\t\tmappedValues,\n\t\t\tthis.session,\n\t\t\tthis.dialect,\n\t\t\tthis.withList,\n\t\t\tfalse,\n\t\t\tthis.overridingSystemValue_,\n\t\t);\n\t}\n\n\tselect(selectQuery: (qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: SQL): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| GelInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable> | SQL),\n\t): GelInsertBase<TTable, TQueryResult> {\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 GelInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type GelInsertWithout<T extends AnyGelInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tGelInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['queryResult'],\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 GelInsertReturning<\n\tT extends AnyGelInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = GelInsertBase<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tSelectResultFields<TSelectedFields>,\n\tTDynamic,\n\tT['_']['excludedMethods']\n>;\n\nexport type GelInsertReturningAll<T extends AnyGelInsert, TDynamic extends boolean> = GelInsertBase<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['table']['$inferSelect'],\n\tTDynamic,\n\tT['_']['excludedMethods']\n>;\n\nexport interface GelInsertOnConflictDoUpdateConfig<T extends AnyGelInsert> {\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: GelUpdateSetSource<T['_']['table']>;\n}\n\nexport type GelInsertPrepare<T extends AnyGelInsert> = GelPreparedQuery<\n\tPreparedQueryConfig & {\n\t\texecute: T['_']['returning'] extends undefined ? GelQueryResultKind<T['_']['queryResult'], never>\n\t\t\t: T['_']['returning'][];\n\t}\n>;\n\nexport type GelInsertDynamic<T extends AnyGelInsert> = GelInsert<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['returning']\n>;\n\nexport type AnyGelInsert = GelInsertBase<any, any, any, any, any>;\n\nexport type GelInsert<\n\tTTable extends GelTable = GelTable,\n\tTQueryResult extends GelQueryResultHKT = GelQueryResultHKT,\n\tTReturning extends Record<string, unknown> | undefined = Record<string, unknown> | undefined,\n> = GelInsertBase<TTable, TQueryResult, TReturning, true, never>;\n\nexport interface GelInsertBase<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\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 ? GelQueryResultKind<TQueryResult, never> : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[], 'gel'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\treadonly dialect: 'gel';\n\t\treadonly table: TTable;\n\t\treadonly queryResult: TQueryResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[];\n\t};\n}\n\nexport class GelInsertBase<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\n\tTReturning extends Record<string, unknown> | undefined = 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 ? GelQueryResultKind<TQueryResult, never> : TReturning[]>\n\timplements\n\t\tRunnableQuery<TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[], 'gel'>,\n\t\tSQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'GelInsert';\n\n\tprivate config: GelInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: GelInsertConfig['values'],\n\t\tprivate session: GelSession,\n\t\tprivate dialect: GelDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t\toverridingSystemValue_?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select, overridingSystemValue_ };\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(): GelInsertWithout<GelInsertReturningAll<this, TDynamic>, TDynamic, 'returning'>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): GelInsertWithout<GelInsertReturning<this, TDynamic, TSelectedFields>, TDynamic, 'returning'>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[Table.Symbol.Columns],\n\t): GelInsertWithout<AnyGelInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<GelColumn>(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\t// TODO not supported\n\t// onConflictDoNothing(\n\t// \tconfig: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {},\n\t// ): GelInsertWithout<this, TDynamic, 'onConflictDoNothing' | 'onConflictDoUpdate'> {\n\t// \tif (config.target === undefined) {\n\t// \t\tthis.config.onConflict = sql`do nothing`;\n\t// \t} else {\n\t// \t\tlet targetColumn = '';\n\t// \t\ttargetColumn = Array.isArray(config.target)\n\t// \t\t\t? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(',')\n\t// \t\t\t: this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));\n\n\t// \t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t// \t\tthis.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;\n\t// \t}\n\t// \treturn this as any;\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 * targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\t// TODO not supported\n\t// onConflictDoUpdate(\n\t// \tconfig: GelInsertOnConflictDoUpdateConfig<this>,\n\t// ): GelInsertWithout<this, TDynamic, 'onConflictDoNothing' | 'onConflictDoUpdate'> {\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\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 setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t// \tlet targetColumn = '';\n\t// \ttargetColumn = Array.isArray(config.target)\n\t// \t\t? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(',')\n\t// \t\t: this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));\n\t// \tthis.config.onConflict = sql`(${\n\t// \t\tsql.raw(targetColumn)\n\t// \t})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;\n\t// \treturn this as any;\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(name?: string): GelInsertPrepare<this> {\n\t\treturn tracer.startActiveSpan('drizzle.prepareQuery', () => {\n\t\t\treturn this.session.prepareQuery<\n\t\t\t\tPreparedQueryConfig & {\n\t\t\t\t\texecute: TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[];\n\t\t\t\t}\n\t\t\t>(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true, undefined, {\n\t\t\t\ttype: 'insert',\n\t\t\t\ttables: extractUsedTable(this.config.table),\n\t\t\t});\n\t\t});\n\t}\n\n\tprepare(name: string): GelInsertPrepare<this> {\n\t\treturn this._prepare(name);\n\t}\n\n\toverride execute: ReturnType<this['prepare']>['execute'] = (placeholderValues) => {\n\t\treturn tracer.startActiveSpan('drizzle.operation', () => {\n\t\t\treturn this._prepare().execute(placeholderValues);\n\t\t});\n\t};\n\n\t$dynamic(): GelInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"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","names":["import_utils"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/gel-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { GelDialect } from '~/gel-core/dialect.ts';\nimport type { IndexColumn } from '~/gel-core/indexes.ts';\nimport type {\n\tGelPreparedQuery,\n\tGelQueryResultHKT,\n\tGelQueryResultKind,\n\tGelSession,\n\tPreparedQueryConfig,\n} from '~/gel-core/session.ts';\nimport type { GelTable, TableConfig } from '~/gel-core/table.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 } from '~/sql/sql.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport type { InferInsertModel } from '~/table.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { tracer } from '~/tracing.ts';\nimport { haveSameKeys, type NeonAuthToken, orderSelectedFields } from '~/utils.ts';\nimport type { AnyGelColumn, GelColumn } from '../columns/common.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { GelUpdateSetSource } from './update.ts';\n\nexport interface GelInsertConfig<TTable extends GelTable = GelTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | GelInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL;\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n\toverridingSystemValue_?: boolean;\n}\n\nexport type GelInsertValue<TTable extends GelTable<TableConfig>, OverrideT extends boolean = false> =\n\t& {\n\t\t[Key in keyof InferInsertModel<TTable, { dbColumnNames: false; override: OverrideT }>]:\n\t\t\t| InferInsertModel<TTable, { dbColumnNames: false; override: OverrideT }>[Key]\n\t\t\t| SQL\n\t\t\t| Placeholder;\n\t}\n\t& {};\n\nexport type GelInsertSelectQueryBuilder<TTable extends GelTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnyGelColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class GelInsertBuilder<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\n\tOverrideT extends boolean = false,\n> {\n\tstatic readonly [entityKind]: string = 'GelInsertBuilder';\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: GelSession,\n\t\tprivate dialect: GelDialect,\n\t\tprivate withList?: Subquery[],\n\t\tprivate overridingSystemValue_?: boolean,\n\t) {}\n\n\tprivate authToken?: NeonAuthToken;\n\t/** @internal */\n\tsetToken(token?: NeonAuthToken) {\n\t\tthis.authToken = token;\n\t\treturn this;\n\t}\n\n\toverridingSystemValue(): Omit<GelInsertBuilder<TTable, TQueryResult, true>, 'overridingSystemValue'> {\n\t\tthis.overridingSystemValue_ = true;\n\t\treturn this as any;\n\t}\n\n\tvalues(value: GelInsertValue<TTable, OverrideT>): GelInsertBase<TTable, TQueryResult>;\n\tvalues(values: GelInsertValue<TTable, OverrideT>[]): GelInsertBase<TTable, TQueryResult>;\n\tvalues(\n\t\tvalues: GelInsertValue<TTable, OverrideT> | GelInsertValue<TTable, OverrideT>[],\n\t): GelInsertBase<TTable, TQueryResult> {\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\treturn new GelInsertBase(\n\t\t\tthis.table,\n\t\t\tmappedValues,\n\t\t\tthis.session,\n\t\t\tthis.dialect,\n\t\t\tthis.withList,\n\t\t\tfalse,\n\t\t\tthis.overridingSystemValue_,\n\t\t);\n\t}\n\n\tselect(selectQuery: (qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: SQL): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| GelInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable> | SQL),\n\t): GelInsertBase<TTable, TQueryResult> {\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 GelInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type GelInsertWithout<T extends AnyGelInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tGelInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['queryResult'],\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 GelInsertReturning<\n\tT extends AnyGelInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = GelInsertBase<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tSelectResultFields<TSelectedFields>,\n\tTDynamic,\n\tT['_']['excludedMethods']\n>;\n\nexport type GelInsertReturningAll<T extends AnyGelInsert, TDynamic extends boolean> = GelInsertBase<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['table']['$inferSelect'],\n\tTDynamic,\n\tT['_']['excludedMethods']\n>;\n\nexport interface GelInsertOnConflictDoUpdateConfig<T extends AnyGelInsert> {\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: GelUpdateSetSource<T['_']['table']>;\n}\n\nexport type GelInsertPrepare<T extends AnyGelInsert> = GelPreparedQuery<\n\tPreparedQueryConfig & {\n\t\texecute: T['_']['returning'] extends undefined ? GelQueryResultKind<T['_']['queryResult'], never>\n\t\t\t: T['_']['returning'][];\n\t}\n>;\n\nexport type GelInsertDynamic<T extends AnyGelInsert> = GelInsert<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['returning']\n>;\n\nexport type AnyGelInsert = GelInsertBase<any, any, any, any, any>;\n\nexport type GelInsert<\n\tTTable extends GelTable = GelTable,\n\tTQueryResult extends GelQueryResultHKT = GelQueryResultHKT,\n\tTReturning extends Record<string, unknown> | undefined = Record<string, unknown> | undefined,\n> = GelInsertBase<TTable, TQueryResult, TReturning, true, never>;\n\nexport interface GelInsertBase<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\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 ? GelQueryResultKind<TQueryResult, never> : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[], 'gel'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\treadonly dialect: 'gel';\n\t\treadonly table: TTable;\n\t\treadonly queryResult: TQueryResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[];\n\t};\n}\n\nexport class GelInsertBase<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\n\tTReturning extends Record<string, unknown> | undefined = 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 ? GelQueryResultKind<TQueryResult, never> : TReturning[]>\n\timplements\n\t\tRunnableQuery<TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[], 'gel'>,\n\t\tSQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'GelInsert';\n\n\tprivate config: GelInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: GelInsertConfig['values'],\n\t\tprivate session: GelSession,\n\t\tprivate dialect: GelDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t\toverridingSystemValue_?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select, overridingSystemValue_ };\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(): GelInsertWithout<GelInsertReturningAll<this, TDynamic>, TDynamic, 'returning'>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): GelInsertWithout<GelInsertReturning<this, TDynamic, TSelectedFields>, TDynamic, 'returning'>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[Table.Symbol.Columns],\n\t): GelInsertWithout<AnyGelInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<GelColumn>(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\t// TODO not supported\n\t// onConflictDoNothing(\n\t// \tconfig: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {},\n\t// ): GelInsertWithout<this, TDynamic, 'onConflictDoNothing' | 'onConflictDoUpdate'> {\n\t// \tif (config.target === undefined) {\n\t// \t\tthis.config.onConflict = sql`do nothing`;\n\t// \t} else {\n\t// \t\tlet targetColumn = '';\n\t// \t\ttargetColumn = Array.isArray(config.target)\n\t// \t\t\t? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(',')\n\t// \t\t\t: this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));\n\n\t// \t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t// \t\tthis.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;\n\t// \t}\n\t// \treturn this as any;\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 * targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\t// TODO not supported\n\t// onConflictDoUpdate(\n\t// \tconfig: GelInsertOnConflictDoUpdateConfig<this>,\n\t// ): GelInsertWithout<this, TDynamic, 'onConflictDoNothing' | 'onConflictDoUpdate'> {\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\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 setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t// \tlet targetColumn = '';\n\t// \ttargetColumn = Array.isArray(config.target)\n\t// \t\t? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(',')\n\t// \t\t: this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));\n\t// \tthis.config.onConflict = sql`(${\n\t// \t\tsql.raw(targetColumn)\n\t// \t})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;\n\t// \treturn this as any;\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(name?: string): GelInsertPrepare<this> {\n\t\treturn tracer.startActiveSpan('drizzle.prepareQuery', () => {\n\t\t\treturn this.session.prepareQuery<\n\t\t\t\tPreparedQueryConfig & {\n\t\t\t\t\texecute: TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[];\n\t\t\t\t}\n\t\t\t>(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true);\n\t\t});\n\t}\n\n\tprepare(name: string): GelInsertPrepare<this> {\n\t\treturn this._prepare(name);\n\t}\n\n\toverride execute: ReturnType<this['prepare']>['execute'] = (placeholderValues) => {\n\t\treturn tracer.startActiveSpan('drizzle.operation', () => {\n\t\t\treturn this._prepare().execute(placeholderValues);\n\t\t});\n\t};\n\n\t$dynamic(): GelInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"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","names":[]}
|
|
@@ -4,7 +4,6 @@ import { Param, SQL } from "../../sql/sql.js";
|
|
|
4
4
|
import { Columns, Table } from "../../table.js";
|
|
5
5
|
import { tracer } from "../../tracing.js";
|
|
6
6
|
import { haveSameKeys, orderSelectedFields } from "../../utils.js";
|
|
7
|
-
import { extractUsedTable } from "../utils.js";
|
|
8
7
|
import { QueryBuilder } from "./query-builder.js";
|
|
9
8
|
class GelInsertBuilder {
|
|
10
9
|
constructor(table, session, dialect, withList, overridingSystemValue_) {
|
|
@@ -172,10 +171,7 @@ class GelInsertBase extends QueryPromise {
|
|
|
172
171
|
/** @internal */
|
|
173
172
|
_prepare(name) {
|
|
174
173
|
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
|
175
|
-
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true
|
|
176
|
-
type: "insert",
|
|
177
|
-
tables: extractUsedTable(this.config.table)
|
|
178
|
-
});
|
|
174
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true);
|
|
179
175
|
});
|
|
180
176
|
}
|
|
181
177
|
prepare(name) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/gel-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { GelDialect } from '~/gel-core/dialect.ts';\nimport type { IndexColumn } from '~/gel-core/indexes.ts';\nimport type {\n\tGelPreparedQuery,\n\tGelQueryResultHKT,\n\tGelQueryResultKind,\n\tGelSession,\n\tPreparedQueryConfig,\n} from '~/gel-core/session.ts';\nimport type { GelTable, TableConfig } from '~/gel-core/table.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 } from '~/sql/sql.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport type { InferInsertModel } from '~/table.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { tracer } from '~/tracing.ts';\nimport { haveSameKeys, type NeonAuthToken, orderSelectedFields } from '~/utils.ts';\nimport type { AnyGelColumn, GelColumn } 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 { GelUpdateSetSource } from './update.ts';\n\nexport interface GelInsertConfig<TTable extends GelTable = GelTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | GelInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL;\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n\toverridingSystemValue_?: boolean;\n}\n\nexport type GelInsertValue<TTable extends GelTable<TableConfig>, OverrideT extends boolean = false> =\n\t& {\n\t\t[Key in keyof InferInsertModel<TTable, { dbColumnNames: false; override: OverrideT }>]:\n\t\t\t| InferInsertModel<TTable, { dbColumnNames: false; override: OverrideT }>[Key]\n\t\t\t| SQL\n\t\t\t| Placeholder;\n\t}\n\t& {};\n\nexport type GelInsertSelectQueryBuilder<TTable extends GelTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnyGelColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class GelInsertBuilder<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\n\tOverrideT extends boolean = false,\n> {\n\tstatic readonly [entityKind]: string = 'GelInsertBuilder';\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: GelSession,\n\t\tprivate dialect: GelDialect,\n\t\tprivate withList?: Subquery[],\n\t\tprivate overridingSystemValue_?: boolean,\n\t) {}\n\n\tprivate authToken?: NeonAuthToken;\n\t/** @internal */\n\tsetToken(token?: NeonAuthToken) {\n\t\tthis.authToken = token;\n\t\treturn this;\n\t}\n\n\toverridingSystemValue(): Omit<GelInsertBuilder<TTable, TQueryResult, true>, 'overridingSystemValue'> {\n\t\tthis.overridingSystemValue_ = true;\n\t\treturn this as any;\n\t}\n\n\tvalues(value: GelInsertValue<TTable, OverrideT>): GelInsertBase<TTable, TQueryResult>;\n\tvalues(values: GelInsertValue<TTable, OverrideT>[]): GelInsertBase<TTable, TQueryResult>;\n\tvalues(\n\t\tvalues: GelInsertValue<TTable, OverrideT> | GelInsertValue<TTable, OverrideT>[],\n\t): GelInsertBase<TTable, TQueryResult> {\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\treturn new GelInsertBase(\n\t\t\tthis.table,\n\t\t\tmappedValues,\n\t\t\tthis.session,\n\t\t\tthis.dialect,\n\t\t\tthis.withList,\n\t\t\tfalse,\n\t\t\tthis.overridingSystemValue_,\n\t\t);\n\t}\n\n\tselect(selectQuery: (qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: SQL): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| GelInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable> | SQL),\n\t): GelInsertBase<TTable, TQueryResult> {\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 GelInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type GelInsertWithout<T extends AnyGelInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tGelInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['queryResult'],\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 GelInsertReturning<\n\tT extends AnyGelInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = GelInsertBase<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tSelectResultFields<TSelectedFields>,\n\tTDynamic,\n\tT['_']['excludedMethods']\n>;\n\nexport type GelInsertReturningAll<T extends AnyGelInsert, TDynamic extends boolean> = GelInsertBase<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['table']['$inferSelect'],\n\tTDynamic,\n\tT['_']['excludedMethods']\n>;\n\nexport interface GelInsertOnConflictDoUpdateConfig<T extends AnyGelInsert> {\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: GelUpdateSetSource<T['_']['table']>;\n}\n\nexport type GelInsertPrepare<T extends AnyGelInsert> = GelPreparedQuery<\n\tPreparedQueryConfig & {\n\t\texecute: T['_']['returning'] extends undefined ? GelQueryResultKind<T['_']['queryResult'], never>\n\t\t\t: T['_']['returning'][];\n\t}\n>;\n\nexport type GelInsertDynamic<T extends AnyGelInsert> = GelInsert<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['returning']\n>;\n\nexport type AnyGelInsert = GelInsertBase<any, any, any, any, any>;\n\nexport type GelInsert<\n\tTTable extends GelTable = GelTable,\n\tTQueryResult extends GelQueryResultHKT = GelQueryResultHKT,\n\tTReturning extends Record<string, unknown> | undefined = Record<string, unknown> | undefined,\n> = GelInsertBase<TTable, TQueryResult, TReturning, true, never>;\n\nexport interface GelInsertBase<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\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 ? GelQueryResultKind<TQueryResult, never> : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[], 'gel'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\treadonly dialect: 'gel';\n\t\treadonly table: TTable;\n\t\treadonly queryResult: TQueryResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[];\n\t};\n}\n\nexport class GelInsertBase<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\n\tTReturning extends Record<string, unknown> | undefined = 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 ? GelQueryResultKind<TQueryResult, never> : TReturning[]>\n\timplements\n\t\tRunnableQuery<TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[], 'gel'>,\n\t\tSQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'GelInsert';\n\n\tprivate config: GelInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: GelInsertConfig['values'],\n\t\tprivate session: GelSession,\n\t\tprivate dialect: GelDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t\toverridingSystemValue_?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select, overridingSystemValue_ };\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(): GelInsertWithout<GelInsertReturningAll<this, TDynamic>, TDynamic, 'returning'>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): GelInsertWithout<GelInsertReturning<this, TDynamic, TSelectedFields>, TDynamic, 'returning'>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[Table.Symbol.Columns],\n\t): GelInsertWithout<AnyGelInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<GelColumn>(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\t// TODO not supported\n\t// onConflictDoNothing(\n\t// \tconfig: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {},\n\t// ): GelInsertWithout<this, TDynamic, 'onConflictDoNothing' | 'onConflictDoUpdate'> {\n\t// \tif (config.target === undefined) {\n\t// \t\tthis.config.onConflict = sql`do nothing`;\n\t// \t} else {\n\t// \t\tlet targetColumn = '';\n\t// \t\ttargetColumn = Array.isArray(config.target)\n\t// \t\t\t? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(',')\n\t// \t\t\t: this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));\n\n\t// \t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t// \t\tthis.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;\n\t// \t}\n\t// \treturn this as any;\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 * targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\t// TODO not supported\n\t// onConflictDoUpdate(\n\t// \tconfig: GelInsertOnConflictDoUpdateConfig<this>,\n\t// ): GelInsertWithout<this, TDynamic, 'onConflictDoNothing' | 'onConflictDoUpdate'> {\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\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 setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t// \tlet targetColumn = '';\n\t// \ttargetColumn = Array.isArray(config.target)\n\t// \t\t? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(',')\n\t// \t\t: this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));\n\t// \tthis.config.onConflict = sql`(${\n\t// \t\tsql.raw(targetColumn)\n\t// \t})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;\n\t// \treturn this as any;\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(name?: string): GelInsertPrepare<this> {\n\t\treturn tracer.startActiveSpan('drizzle.prepareQuery', () => {\n\t\t\treturn this.session.prepareQuery<\n\t\t\t\tPreparedQueryConfig & {\n\t\t\t\t\texecute: TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[];\n\t\t\t\t}\n\t\t\t>(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true, undefined, {\n\t\t\t\ttype: 'insert',\n\t\t\t\ttables: extractUsedTable(this.config.table),\n\t\t\t});\n\t\t});\n\t}\n\n\tprepare(name: string): GelInsertPrepare<this> {\n\t\treturn this._prepare(name);\n\t}\n\n\toverride execute: ReturnType<this['prepare']>['execute'] = (placeholderValues) => {\n\t\treturn tracer.startActiveSpan('drizzle.operation', () => {\n\t\t\treturn this._prepare().execute(placeholderValues);\n\t\t});\n\t};\n\n\t$dynamic(): GelInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"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","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/gel-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { GelDialect } from '~/gel-core/dialect.ts';\nimport type { IndexColumn } from '~/gel-core/indexes.ts';\nimport type {\n\tGelPreparedQuery,\n\tGelQueryResultHKT,\n\tGelQueryResultKind,\n\tGelSession,\n\tPreparedQueryConfig,\n} from '~/gel-core/session.ts';\nimport type { GelTable, TableConfig } from '~/gel-core/table.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 } from '~/sql/sql.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport type { InferInsertModel } from '~/table.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { tracer } from '~/tracing.ts';\nimport { haveSameKeys, type NeonAuthToken, orderSelectedFields } from '~/utils.ts';\nimport type { AnyGelColumn, GelColumn } from '../columns/common.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { GelUpdateSetSource } from './update.ts';\n\nexport interface GelInsertConfig<TTable extends GelTable = GelTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | GelInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL;\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n\toverridingSystemValue_?: boolean;\n}\n\nexport type GelInsertValue<TTable extends GelTable<TableConfig>, OverrideT extends boolean = false> =\n\t& {\n\t\t[Key in keyof InferInsertModel<TTable, { dbColumnNames: false; override: OverrideT }>]:\n\t\t\t| InferInsertModel<TTable, { dbColumnNames: false; override: OverrideT }>[Key]\n\t\t\t| SQL\n\t\t\t| Placeholder;\n\t}\n\t& {};\n\nexport type GelInsertSelectQueryBuilder<TTable extends GelTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnyGelColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class GelInsertBuilder<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\n\tOverrideT extends boolean = false,\n> {\n\tstatic readonly [entityKind]: string = 'GelInsertBuilder';\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: GelSession,\n\t\tprivate dialect: GelDialect,\n\t\tprivate withList?: Subquery[],\n\t\tprivate overridingSystemValue_?: boolean,\n\t) {}\n\n\tprivate authToken?: NeonAuthToken;\n\t/** @internal */\n\tsetToken(token?: NeonAuthToken) {\n\t\tthis.authToken = token;\n\t\treturn this;\n\t}\n\n\toverridingSystemValue(): Omit<GelInsertBuilder<TTable, TQueryResult, true>, 'overridingSystemValue'> {\n\t\tthis.overridingSystemValue_ = true;\n\t\treturn this as any;\n\t}\n\n\tvalues(value: GelInsertValue<TTable, OverrideT>): GelInsertBase<TTable, TQueryResult>;\n\tvalues(values: GelInsertValue<TTable, OverrideT>[]): GelInsertBase<TTable, TQueryResult>;\n\tvalues(\n\t\tvalues: GelInsertValue<TTable, OverrideT> | GelInsertValue<TTable, OverrideT>[],\n\t): GelInsertBase<TTable, TQueryResult> {\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\treturn new GelInsertBase(\n\t\t\tthis.table,\n\t\t\tmappedValues,\n\t\t\tthis.session,\n\t\t\tthis.dialect,\n\t\t\tthis.withList,\n\t\t\tfalse,\n\t\t\tthis.overridingSystemValue_,\n\t\t);\n\t}\n\n\tselect(selectQuery: (qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: SQL): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| GelInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable> | SQL),\n\t): GelInsertBase<TTable, TQueryResult> {\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 GelInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type GelInsertWithout<T extends AnyGelInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tGelInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['queryResult'],\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 GelInsertReturning<\n\tT extends AnyGelInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = GelInsertBase<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tSelectResultFields<TSelectedFields>,\n\tTDynamic,\n\tT['_']['excludedMethods']\n>;\n\nexport type GelInsertReturningAll<T extends AnyGelInsert, TDynamic extends boolean> = GelInsertBase<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['table']['$inferSelect'],\n\tTDynamic,\n\tT['_']['excludedMethods']\n>;\n\nexport interface GelInsertOnConflictDoUpdateConfig<T extends AnyGelInsert> {\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: GelUpdateSetSource<T['_']['table']>;\n}\n\nexport type GelInsertPrepare<T extends AnyGelInsert> = GelPreparedQuery<\n\tPreparedQueryConfig & {\n\t\texecute: T['_']['returning'] extends undefined ? GelQueryResultKind<T['_']['queryResult'], never>\n\t\t\t: T['_']['returning'][];\n\t}\n>;\n\nexport type GelInsertDynamic<T extends AnyGelInsert> = GelInsert<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['returning']\n>;\n\nexport type AnyGelInsert = GelInsertBase<any, any, any, any, any>;\n\nexport type GelInsert<\n\tTTable extends GelTable = GelTable,\n\tTQueryResult extends GelQueryResultHKT = GelQueryResultHKT,\n\tTReturning extends Record<string, unknown> | undefined = Record<string, unknown> | undefined,\n> = GelInsertBase<TTable, TQueryResult, TReturning, true, never>;\n\nexport interface GelInsertBase<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\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 ? GelQueryResultKind<TQueryResult, never> : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[], 'gel'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\treadonly dialect: 'gel';\n\t\treadonly table: TTable;\n\t\treadonly queryResult: TQueryResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[];\n\t};\n}\n\nexport class GelInsertBase<\n\tTTable extends GelTable,\n\tTQueryResult extends GelQueryResultHKT,\n\tTReturning extends Record<string, unknown> | undefined = 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 ? GelQueryResultKind<TQueryResult, never> : TReturning[]>\n\timplements\n\t\tRunnableQuery<TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[], 'gel'>,\n\t\tSQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'GelInsert';\n\n\tprivate config: GelInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: GelInsertConfig['values'],\n\t\tprivate session: GelSession,\n\t\tprivate dialect: GelDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t\toverridingSystemValue_?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select, overridingSystemValue_ };\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(): GelInsertWithout<GelInsertReturningAll<this, TDynamic>, TDynamic, 'returning'>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): GelInsertWithout<GelInsertReturning<this, TDynamic, TSelectedFields>, TDynamic, 'returning'>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[Table.Symbol.Columns],\n\t): GelInsertWithout<AnyGelInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<GelColumn>(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\t// TODO not supported\n\t// onConflictDoNothing(\n\t// \tconfig: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {},\n\t// ): GelInsertWithout<this, TDynamic, 'onConflictDoNothing' | 'onConflictDoUpdate'> {\n\t// \tif (config.target === undefined) {\n\t// \t\tthis.config.onConflict = sql`do nothing`;\n\t// \t} else {\n\t// \t\tlet targetColumn = '';\n\t// \t\ttargetColumn = Array.isArray(config.target)\n\t// \t\t\t? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(',')\n\t// \t\t\t: this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));\n\n\t// \t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t// \t\tthis.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;\n\t// \t}\n\t// \treturn this as any;\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 * targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\t// TODO not supported\n\t// onConflictDoUpdate(\n\t// \tconfig: GelInsertOnConflictDoUpdateConfig<this>,\n\t// ): GelInsertWithout<this, TDynamic, 'onConflictDoNothing' | 'onConflictDoUpdate'> {\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\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 setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t// \tlet targetColumn = '';\n\t// \ttargetColumn = Array.isArray(config.target)\n\t// \t\t? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(',')\n\t// \t\t: this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));\n\t// \tthis.config.onConflict = sql`(${\n\t// \t\tsql.raw(targetColumn)\n\t// \t})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;\n\t// \treturn this as any;\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(name?: string): GelInsertPrepare<this> {\n\t\treturn tracer.startActiveSpan('drizzle.prepareQuery', () => {\n\t\t\treturn this.session.prepareQuery<\n\t\t\t\tPreparedQueryConfig & {\n\t\t\t\t\texecute: TReturning extends undefined ? GelQueryResultKind<TQueryResult, never> : TReturning[];\n\t\t\t\t}\n\t\t\t>(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true);\n\t\t});\n\t}\n\n\tprepare(name: string): GelInsertPrepare<this> {\n\t\treturn this._prepare(name);\n\t}\n\n\toverride execute: ReturnType<this['prepare']>['execute'] = (placeholderValues) => {\n\t\treturn tracer.startActiveSpan('drizzle.operation', () => {\n\t\t\treturn this._prepare().execute(placeholderValues);\n\t\t});\n\t};\n\n\t$dynamic(): GelInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"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","names":[]}
|
|
@@ -41,7 +41,6 @@ var import_tracing = require("../../tracing.cjs");
|
|
|
41
41
|
var import_utils = require("../../utils.cjs");
|
|
42
42
|
var import_utils2 = require("../../utils.cjs");
|
|
43
43
|
var import_view_common = require("../../view-common.cjs");
|
|
44
|
-
var import_utils3 = require("../utils.cjs");
|
|
45
44
|
class GelSelectBuilder {
|
|
46
45
|
static [import_entity.entityKind] = "GelSelectBuilder";
|
|
47
46
|
fields;
|
|
@@ -106,8 +105,6 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
106
105
|
isPartialSelect;
|
|
107
106
|
session;
|
|
108
107
|
dialect;
|
|
109
|
-
cacheConfig = void 0;
|
|
110
|
-
usedTables = /* @__PURE__ */ new Set();
|
|
111
108
|
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
|
|
112
109
|
super();
|
|
113
110
|
this.config = {
|
|
@@ -121,27 +118,18 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
121
118
|
this.session = session;
|
|
122
119
|
this.dialect = dialect;
|
|
123
120
|
this._ = {
|
|
124
|
-
selectedFields: fields
|
|
125
|
-
config: this.config
|
|
121
|
+
selectedFields: fields
|
|
126
122
|
};
|
|
127
123
|
this.tableName = (0, import_utils.getTableLikeName)(table);
|
|
128
124
|
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
|
129
|
-
for (const item of (0, import_utils3.extractUsedTable)(table))
|
|
130
|
-
this.usedTables.add(item);
|
|
131
125
|
}
|
|
132
|
-
|
|
133
|
-
getUsedTables() {
|
|
134
|
-
return [...this.usedTables];
|
|
135
|
-
}
|
|
136
|
-
createJoin(joinType) {
|
|
126
|
+
createJoin(joinType, lateral) {
|
|
137
127
|
return (table, on) => {
|
|
138
128
|
const baseTableName = this.tableName;
|
|
139
129
|
const tableName = (0, import_utils.getTableLikeName)(table);
|
|
140
130
|
if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
|
|
141
131
|
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
142
132
|
}
|
|
143
|
-
for (const item of (0, import_utils3.extractUsedTable)(table))
|
|
144
|
-
this.usedTables.add(item);
|
|
145
133
|
if (!this.isPartialSelect) {
|
|
146
134
|
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") {
|
|
147
135
|
this.config.fields = {
|
|
@@ -164,7 +152,7 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
164
152
|
if (!this.config.joins) {
|
|
165
153
|
this.config.joins = [];
|
|
166
154
|
}
|
|
167
|
-
this.config.joins.push({ on, table, joinType, alias: tableName });
|
|
155
|
+
this.config.joins.push({ on, table, joinType, alias: tableName, lateral });
|
|
168
156
|
if (typeof tableName === "string") {
|
|
169
157
|
switch (joinType) {
|
|
170
158
|
case "left": {
|
|
@@ -178,6 +166,7 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
178
166
|
this.joinsNotNullableMap[tableName] = true;
|
|
179
167
|
break;
|
|
180
168
|
}
|
|
169
|
+
case "cross":
|
|
181
170
|
case "inner": {
|
|
182
171
|
this.joinsNotNullableMap[tableName] = true;
|
|
183
172
|
break;
|
|
@@ -208,12 +197,12 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
208
197
|
*
|
|
209
198
|
* ```ts
|
|
210
199
|
* // Select all users and their pets
|
|
211
|
-
* const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
|
|
200
|
+
* const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()
|
|
212
201
|
* .from(users)
|
|
213
202
|
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
214
203
|
*
|
|
215
204
|
* // Select userId and petId
|
|
216
|
-
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
205
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
217
206
|
* userId: users.id,
|
|
218
207
|
* petId: pets.id,
|
|
219
208
|
* })
|
|
@@ -221,7 +210,20 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
221
210
|
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
222
211
|
* ```
|
|
223
212
|
*/
|
|
224
|
-
leftJoin = this.createJoin("left");
|
|
213
|
+
leftJoin = this.createJoin("left", false);
|
|
214
|
+
/**
|
|
215
|
+
* Executes a `left join lateral` operation by adding subquery to the current query.
|
|
216
|
+
*
|
|
217
|
+
* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
|
|
218
|
+
*
|
|
219
|
+
* Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
|
|
220
|
+
*
|
|
221
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join-lateral}
|
|
222
|
+
*
|
|
223
|
+
* @param table the subquery to join.
|
|
224
|
+
* @param on the `on` clause.
|
|
225
|
+
*/
|
|
226
|
+
leftJoinLateral = this.createJoin("left", true);
|
|
225
227
|
/**
|
|
226
228
|
* Executes a `right join` operation by adding another table to the current query.
|
|
227
229
|
*
|
|
@@ -236,12 +238,12 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
236
238
|
*
|
|
237
239
|
* ```ts
|
|
238
240
|
* // Select all users and their pets
|
|
239
|
-
* const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
|
|
241
|
+
* const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()
|
|
240
242
|
* .from(users)
|
|
241
243
|
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
242
244
|
*
|
|
243
245
|
* // Select userId and petId
|
|
244
|
-
* const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
|
|
246
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({
|
|
245
247
|
* userId: users.id,
|
|
246
248
|
* petId: pets.id,
|
|
247
249
|
* })
|
|
@@ -249,7 +251,7 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
249
251
|
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
250
252
|
* ```
|
|
251
253
|
*/
|
|
252
|
-
rightJoin = this.createJoin("right");
|
|
254
|
+
rightJoin = this.createJoin("right", false);
|
|
253
255
|
/**
|
|
254
256
|
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
|
255
257
|
*
|
|
@@ -264,12 +266,12 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
264
266
|
*
|
|
265
267
|
* ```ts
|
|
266
268
|
* // Select all users and their pets
|
|
267
|
-
* const usersWithPets: { user: User; pets: Pet }[] = await db.select()
|
|
269
|
+
* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
|
|
268
270
|
* .from(users)
|
|
269
271
|
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
270
272
|
*
|
|
271
273
|
* // Select userId and petId
|
|
272
|
-
* const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
|
|
274
|
+
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
273
275
|
* userId: users.id,
|
|
274
276
|
* petId: pets.id,
|
|
275
277
|
* })
|
|
@@ -277,7 +279,20 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
277
279
|
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
278
280
|
* ```
|
|
279
281
|
*/
|
|
280
|
-
innerJoin = this.createJoin("inner");
|
|
282
|
+
innerJoin = this.createJoin("inner", false);
|
|
283
|
+
/**
|
|
284
|
+
* Executes an `inner join lateral` operation, creating a new table by combining rows from two queries that have matching values.
|
|
285
|
+
*
|
|
286
|
+
* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
|
|
287
|
+
*
|
|
288
|
+
* Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
|
|
289
|
+
*
|
|
290
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join-lateral}
|
|
291
|
+
*
|
|
292
|
+
* @param table the subquery to join.
|
|
293
|
+
* @param on the `on` clause.
|
|
294
|
+
*/
|
|
295
|
+
innerJoinLateral = this.createJoin("inner", true);
|
|
281
296
|
/**
|
|
282
297
|
* Executes a `full join` operation by combining rows from two tables into a new table.
|
|
283
298
|
*
|
|
@@ -292,12 +307,12 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
292
307
|
*
|
|
293
308
|
* ```ts
|
|
294
309
|
* // Select all users and their pets
|
|
295
|
-
* const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
|
|
310
|
+
* const usersWithPets: { user: User | null; pets: Pet | null; }[] = await db.select()
|
|
296
311
|
* .from(users)
|
|
297
312
|
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
298
313
|
*
|
|
299
314
|
* // Select userId and petId
|
|
300
|
-
* const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
|
|
315
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number | null; }[] = await db.select({
|
|
301
316
|
* userId: users.id,
|
|
302
317
|
* petId: pets.id,
|
|
303
318
|
* })
|
|
@@ -305,7 +320,46 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
305
320
|
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
306
321
|
* ```
|
|
307
322
|
*/
|
|
308
|
-
fullJoin = this.createJoin("full");
|
|
323
|
+
fullJoin = this.createJoin("full", false);
|
|
324
|
+
/**
|
|
325
|
+
* Executes a `cross join` operation by combining rows from two tables into a new table.
|
|
326
|
+
*
|
|
327
|
+
* Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.
|
|
328
|
+
*
|
|
329
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}
|
|
330
|
+
*
|
|
331
|
+
* @param table the table to join.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
*
|
|
335
|
+
* ```ts
|
|
336
|
+
* // Select all users, each user with every pet
|
|
337
|
+
* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
|
|
338
|
+
* .from(users)
|
|
339
|
+
* .crossJoin(pets)
|
|
340
|
+
*
|
|
341
|
+
* // Select userId and petId
|
|
342
|
+
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
343
|
+
* userId: users.id,
|
|
344
|
+
* petId: pets.id,
|
|
345
|
+
* })
|
|
346
|
+
* .from(users)
|
|
347
|
+
* .crossJoin(pets)
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
crossJoin = this.createJoin("cross", false);
|
|
351
|
+
/**
|
|
352
|
+
* Executes a `cross join lateral` operation by combining rows from two queries into a new table.
|
|
353
|
+
*
|
|
354
|
+
* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
|
|
355
|
+
*
|
|
356
|
+
* Calling this method retrieves all rows from both main and joined queries, merging all rows from each query.
|
|
357
|
+
*
|
|
358
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#cross-join-lateral}
|
|
359
|
+
*
|
|
360
|
+
* @param table the query to join.
|
|
361
|
+
*/
|
|
362
|
+
crossJoinLateral = this.createJoin("cross", true);
|
|
309
363
|
createSetOperator(type, isAll) {
|
|
310
364
|
return (rightSelection) => {
|
|
311
365
|
const rightSelect = typeof rightSelection === "function" ? rightSelection(getGelSetOperators()) : rightSelection;
|
|
@@ -693,14 +747,8 @@ class GelSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
|
|
693
747
|
return rest;
|
|
694
748
|
}
|
|
695
749
|
as(alias) {
|
|
696
|
-
const usedTables = [];
|
|
697
|
-
usedTables.push(...(0, import_utils3.extractUsedTable)(this.config.table));
|
|
698
|
-
if (this.config.joins) {
|
|
699
|
-
for (const it of this.config.joins)
|
|
700
|
-
usedTables.push(...(0, import_utils3.extractUsedTable)(it.table));
|
|
701
|
-
}
|
|
702
750
|
return new Proxy(
|
|
703
|
-
new import_subquery.Subquery(this.getSQL(), this.config.fields, alias
|
|
751
|
+
new import_subquery.Subquery(this.getSQL(), this.config.fields, alias),
|
|
704
752
|
new import_selection_proxy.SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
|
705
753
|
);
|
|
706
754
|
}
|
|
@@ -719,24 +767,17 @@ class GelSelectBase extends GelSelectQueryBuilderBase {
|
|
|
719
767
|
static [import_entity.entityKind] = "GelSelect";
|
|
720
768
|
/** @internal */
|
|
721
769
|
_prepare(name) {
|
|
722
|
-
const { session, config, dialect, joinsNotNullableMap
|
|
770
|
+
const { session, config, dialect, joinsNotNullableMap } = this;
|
|
723
771
|
if (!session) {
|
|
724
772
|
throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
|
725
773
|
}
|
|
726
774
|
return import_tracing.tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
|
727
775
|
const fieldsList = (0, import_utils2.orderSelectedFields)(config.fields);
|
|
728
|
-
const query = session.prepareQuery(dialect.sqlToQuery(this.getSQL()), fieldsList, name, true
|
|
729
|
-
type: "select",
|
|
730
|
-
tables: [...usedTables]
|
|
731
|
-
}, cacheConfig);
|
|
776
|
+
const query = session.prepareQuery(dialect.sqlToQuery(this.getSQL()), fieldsList, name, true);
|
|
732
777
|
query.joinsNotNullableMap = joinsNotNullableMap;
|
|
733
778
|
return query;
|
|
734
779
|
});
|
|
735
780
|
}
|
|
736
|
-
$withCache(config) {
|
|
737
|
-
this.cacheConfig = config === void 0 ? { config: {}, enable: true, autoInvalidate: true } : config === false ? { enable: false } : { enable: true, autoInvalidate: true, ...config };
|
|
738
|
-
return this;
|
|
739
|
-
}
|
|
740
781
|
/**
|
|
741
782
|
* Create a prepared statement for this query. This allows
|
|
742
783
|
* the database to remember this query for the given session
|