drizzle-orm 1.0.0-beta.21 → 1.0.0-beta.21-4fa69ab
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_relations.cjs.map +1 -1
- package/_relations.d.cts +2 -13
- package/_relations.d.ts +2 -13
- package/_relations.js.map +1 -1
- package/aws-data-api/common/index.cjs +2 -0
- package/aws-data-api/common/index.cjs.map +1 -1
- package/aws-data-api/common/index.js +2 -0
- package/aws-data-api/common/index.js.map +1 -1
- package/aws-data-api/pg/driver.cjs +93 -20
- package/aws-data-api/pg/driver.cjs.map +1 -1
- package/aws-data-api/pg/driver.d.cts +17 -13
- package/aws-data-api/pg/driver.d.ts +16 -12
- package/aws-data-api/pg/driver.js +93 -20
- package/aws-data-api/pg/driver.js.map +1 -1
- package/aws-data-api/pg/index.cjs +1 -1
- package/aws-data-api/pg/index.d.cts +3 -3
- package/aws-data-api/pg/index.d.ts +3 -3
- package/aws-data-api/pg/index.js +3 -3
- package/aws-data-api/pg/migrator.cjs.map +1 -1
- package/aws-data-api/pg/migrator.d.cts +1 -1
- package/aws-data-api/pg/migrator.d.ts +1 -1
- package/aws-data-api/pg/migrator.js.map +1 -1
- package/aws-data-api/pg/session.cjs +44 -113
- package/aws-data-api/pg/session.cjs.map +1 -1
- package/aws-data-api/pg/session.d.cts +12 -42
- package/aws-data-api/pg/session.d.ts +12 -42
- package/aws-data-api/pg/session.js +46 -114
- package/aws-data-api/pg/session.js.map +1 -1
- package/better-sqlite3/driver.cjs +5 -2
- package/better-sqlite3/driver.cjs.map +1 -1
- package/better-sqlite3/driver.d.ts +1 -1
- package/better-sqlite3/driver.js +5 -2
- package/better-sqlite3/driver.js.map +1 -1
- package/better-sqlite3/session.cjs +15 -14
- package/better-sqlite3/session.cjs.map +1 -1
- package/better-sqlite3/session.d.cts +10 -6
- package/better-sqlite3/session.d.ts +10 -6
- package/better-sqlite3/session.js +16 -15
- package/better-sqlite3/session.js.map +1 -1
- package/bun-sql/driver.cjs.map +1 -1
- package/bun-sql/driver.d.cts +7 -6
- package/bun-sql/driver.d.ts +7 -6
- package/bun-sql/driver.js.map +1 -1
- package/bun-sql/index.cjs +0 -1
- package/bun-sql/index.d.cts +2 -2
- package/bun-sql/index.d.ts +2 -2
- package/bun-sql/index.js +2 -2
- package/bun-sql/migrator.cjs.map +1 -1
- package/bun-sql/migrator.d.cts +2 -2
- package/bun-sql/migrator.d.ts +2 -2
- package/bun-sql/migrator.js.map +1 -1
- package/bun-sql/mysql/driver.cjs +4 -3
- package/bun-sql/mysql/driver.cjs.map +1 -1
- package/bun-sql/mysql/driver.js +3 -2
- package/bun-sql/mysql/driver.js.map +1 -1
- package/bun-sql/mysql/session.cjs +36 -23
- package/bun-sql/mysql/session.cjs.map +1 -1
- package/bun-sql/mysql/session.d.cts +10 -4
- package/bun-sql/mysql/session.d.ts +11 -5
- package/bun-sql/mysql/session.js +37 -24
- package/bun-sql/mysql/session.js.map +1 -1
- package/bun-sql/postgres/driver.cjs +143 -19
- package/bun-sql/postgres/driver.cjs.map +1 -1
- package/bun-sql/postgres/driver.d.cts +10 -6
- package/bun-sql/postgres/driver.d.ts +10 -6
- package/bun-sql/postgres/driver.js +143 -19
- package/bun-sql/postgres/driver.js.map +1 -1
- package/bun-sql/postgres/index.cjs +1 -1
- package/bun-sql/postgres/index.d.cts +3 -3
- package/bun-sql/postgres/index.d.ts +3 -3
- package/bun-sql/postgres/index.js +3 -3
- package/bun-sql/postgres/migrator.cjs.map +1 -1
- package/bun-sql/postgres/migrator.d.cts +1 -1
- package/bun-sql/postgres/migrator.d.ts +1 -1
- package/bun-sql/postgres/migrator.js.map +1 -1
- package/bun-sql/postgres/session.cjs +16 -111
- package/bun-sql/postgres/session.cjs.map +1 -1
- package/bun-sql/postgres/session.d.cts +11 -33
- package/bun-sql/postgres/session.d.ts +10 -32
- package/bun-sql/postgres/session.js +17 -111
- package/bun-sql/postgres/session.js.map +1 -1
- package/bun-sql/session.cjs +0 -1
- package/bun-sql/session.d.cts +2 -2
- package/bun-sql/session.d.ts +2 -2
- package/bun-sql/session.js +2 -2
- package/bun-sql/sqlite/driver.cjs +4 -3
- package/bun-sql/sqlite/driver.cjs.map +1 -1
- package/bun-sql/sqlite/driver.d.ts +1 -1
- package/bun-sql/sqlite/driver.js +3 -2
- package/bun-sql/sqlite/driver.js.map +1 -1
- package/bun-sql/sqlite/session.cjs +17 -16
- package/bun-sql/sqlite/session.cjs.map +1 -1
- package/bun-sql/sqlite/session.d.cts +9 -6
- package/bun-sql/sqlite/session.d.ts +9 -6
- package/bun-sql/sqlite/session.js +18 -17
- package/bun-sql/sqlite/session.js.map +1 -1
- package/bun-sqlite/driver.cjs +5 -2
- package/bun-sqlite/driver.cjs.map +1 -1
- package/bun-sqlite/driver.d.ts +1 -1
- package/bun-sqlite/driver.js +5 -2
- package/bun-sqlite/driver.js.map +1 -1
- package/bun-sqlite/session.cjs +15 -14
- package/bun-sqlite/session.cjs.map +1 -1
- package/bun-sqlite/session.d.cts +10 -6
- package/bun-sqlite/session.d.ts +10 -6
- package/bun-sqlite/session.js +16 -15
- package/bun-sqlite/session.js.map +1 -1
- package/cache/core/cache-effect.d.cts +1 -1
- package/cache/core/cache-effect.d.ts +1 -1
- package/cache/upstash/cache.d.cts +1 -1
- package/cache/upstash/cache.d.ts +1 -1
- package/cockroach/driver.cjs +9 -3
- package/cockroach/driver.cjs.map +1 -1
- package/cockroach/driver.d.cts +1 -0
- package/cockroach/driver.d.ts +2 -1
- package/cockroach/driver.js +9 -3
- package/cockroach/driver.js.map +1 -1
- package/cockroach/session.cjs +7 -9
- package/cockroach/session.cjs.map +1 -1
- package/cockroach/session.d.cts +5 -3
- package/cockroach/session.d.ts +6 -4
- package/cockroach/session.js +8 -10
- package/cockroach/session.js.map +1 -1
- package/cockroach-core/columns/bigint.cjs +4 -4
- package/cockroach-core/columns/bigint.cjs.map +1 -1
- package/cockroach-core/columns/bigint.d.cts +2 -2
- package/cockroach-core/columns/bigint.d.ts +2 -2
- package/cockroach-core/columns/bigint.js +4 -4
- package/cockroach-core/columns/bigint.js.map +1 -1
- package/cockroach-core/columns/common.cjs +4 -4
- package/cockroach-core/columns/common.cjs.map +1 -1
- package/cockroach-core/columns/common.d.cts +2 -2
- package/cockroach-core/columns/common.d.ts +2 -2
- package/cockroach-core/columns/common.js +4 -4
- package/cockroach-core/columns/common.js.map +1 -1
- package/cockroach-core/columns/custom.cjs +4 -4
- package/cockroach-core/columns/custom.cjs.map +1 -1
- package/cockroach-core/columns/custom.d.cts +2 -2
- package/cockroach-core/columns/custom.d.ts +2 -2
- package/cockroach-core/columns/custom.js +4 -4
- package/cockroach-core/columns/custom.js.map +1 -1
- package/cockroach-core/columns/date.cjs +6 -6
- package/cockroach-core/columns/date.cjs.map +1 -1
- package/cockroach-core/columns/date.d.cts +3 -3
- package/cockroach-core/columns/date.d.ts +3 -3
- package/cockroach-core/columns/date.js +6 -6
- package/cockroach-core/columns/date.js.map +1 -1
- package/cockroach-core/columns/decimal.cjs +4 -4
- package/cockroach-core/columns/decimal.cjs.map +1 -1
- package/cockroach-core/columns/decimal.d.cts +2 -2
- package/cockroach-core/columns/decimal.d.ts +2 -2
- package/cockroach-core/columns/decimal.js +4 -4
- package/cockroach-core/columns/decimal.js.map +1 -1
- package/cockroach-core/columns/float.cjs +2 -2
- package/cockroach-core/columns/float.cjs.map +1 -1
- package/cockroach-core/columns/float.d.cts +1 -1
- package/cockroach-core/columns/float.d.ts +1 -1
- package/cockroach-core/columns/float.js +2 -2
- package/cockroach-core/columns/float.js.map +1 -1
- package/cockroach-core/columns/geometry.cjs +8 -8
- package/cockroach-core/columns/geometry.cjs.map +1 -1
- package/cockroach-core/columns/geometry.d.cts +5 -5
- package/cockroach-core/columns/geometry.d.ts +5 -5
- package/cockroach-core/columns/geometry.js +8 -8
- package/cockroach-core/columns/geometry.js.map +1 -1
- package/cockroach-core/columns/integer.cjs +2 -2
- package/cockroach-core/columns/integer.cjs.map +1 -1
- package/cockroach-core/columns/integer.d.cts +1 -1
- package/cockroach-core/columns/integer.d.ts +1 -1
- package/cockroach-core/columns/integer.js +2 -2
- package/cockroach-core/columns/integer.js.map +1 -1
- package/cockroach-core/columns/jsonb.cjs +4 -4
- package/cockroach-core/columns/jsonb.cjs.map +1 -1
- package/cockroach-core/columns/jsonb.d.cts +2 -2
- package/cockroach-core/columns/jsonb.d.ts +2 -2
- package/cockroach-core/columns/jsonb.js +4 -4
- package/cockroach-core/columns/jsonb.js.map +1 -1
- package/cockroach-core/columns/vector.cjs +4 -4
- package/cockroach-core/columns/vector.cjs.map +1 -1
- package/cockroach-core/columns/vector.d.cts +2 -2
- package/cockroach-core/columns/vector.d.ts +2 -2
- package/cockroach-core/columns/vector.js +4 -4
- package/cockroach-core/columns/vector.js.map +1 -1
- package/cockroach-core/db.cjs +1 -1
- package/cockroach-core/db.cjs.map +1 -1
- package/cockroach-core/db.js +1 -1
- package/cockroach-core/db.js.map +1 -1
- package/cockroach-core/dialect.cjs +1 -1
- package/cockroach-core/dialect.d.ts +1 -1
- package/cockroach-core/dialect.js +1 -1
- package/cockroach-core/query-builders/delete.cjs +6 -2
- package/cockroach-core/query-builders/delete.cjs.map +1 -1
- package/cockroach-core/query-builders/delete.d.cts +1 -1
- package/cockroach-core/query-builders/delete.d.ts +1 -1
- package/cockroach-core/query-builders/delete.js +6 -2
- package/cockroach-core/query-builders/delete.js.map +1 -1
- package/cockroach-core/query-builders/insert.cjs +6 -2
- package/cockroach-core/query-builders/insert.cjs.map +1 -1
- package/cockroach-core/query-builders/insert.js +6 -2
- package/cockroach-core/query-builders/insert.js.map +1 -1
- package/cockroach-core/query-builders/query.cjs +2 -2
- package/cockroach-core/query-builders/query.cjs.map +1 -1
- package/cockroach-core/query-builders/query.js +2 -2
- package/cockroach-core/query-builders/query.js.map +1 -1
- package/cockroach-core/query-builders/raw.cjs +0 -4
- package/cockroach-core/query-builders/raw.cjs.map +1 -1
- package/cockroach-core/query-builders/raw.js +0 -4
- package/cockroach-core/query-builders/raw.js.map +1 -1
- package/cockroach-core/query-builders/refresh-materialized-view.cjs +2 -2
- package/cockroach-core/query-builders/refresh-materialized-view.cjs.map +1 -1
- package/cockroach-core/query-builders/refresh-materialized-view.js +2 -2
- package/cockroach-core/query-builders/refresh-materialized-view.js.map +1 -1
- package/cockroach-core/query-builders/select.cjs +6 -2
- package/cockroach-core/query-builders/select.cjs.map +1 -1
- package/cockroach-core/query-builders/select.js +6 -2
- package/cockroach-core/query-builders/select.js.map +1 -1
- package/cockroach-core/query-builders/update.cjs +6 -2
- package/cockroach-core/query-builders/update.cjs.map +1 -1
- package/cockroach-core/query-builders/update.js +6 -2
- package/cockroach-core/query-builders/update.js.map +1 -1
- package/cockroach-core/session.cjs +2 -2
- package/cockroach-core/session.cjs.map +1 -1
- package/cockroach-core/session.d.cts +1 -1
- package/cockroach-core/session.d.ts +1 -1
- package/cockroach-core/session.js +2 -2
- package/cockroach-core/session.js.map +1 -1
- package/cockroach-core/table.cjs +1 -1
- package/cockroach-core/table.cjs.map +1 -1
- package/cockroach-core/table.js +1 -1
- package/cockroach-core/table.js.map +1 -1
- package/codecs.cjs +77 -0
- package/codecs.cjs.map +1 -0
- package/codecs.d.cts +68 -0
- package/codecs.d.ts +68 -0
- package/codecs.js +74 -0
- package/codecs.js.map +1 -0
- package/column.cjs +10 -5
- package/column.cjs.map +1 -1
- package/column.d.cts +3 -3
- package/column.d.ts +3 -3
- package/column.js +10 -5
- package/column.js.map +1 -1
- package/d1/driver.cjs +3 -2
- package/d1/driver.cjs.map +1 -1
- package/d1/driver.d.ts +1 -1
- package/d1/driver.js +3 -2
- package/d1/driver.js.map +1 -1
- package/d1/session.cjs +16 -14
- package/d1/session.cjs.map +1 -1
- package/d1/session.d.cts +9 -6
- package/d1/session.d.ts +9 -6
- package/d1/session.js +17 -15
- package/d1/session.js.map +1 -1
- package/durable-sqlite/driver.cjs +5 -2
- package/durable-sqlite/driver.cjs.map +1 -1
- package/durable-sqlite/driver.d.ts +1 -1
- package/durable-sqlite/driver.js +5 -2
- package/durable-sqlite/driver.js.map +1 -1
- package/durable-sqlite/session.cjs +15 -14
- package/durable-sqlite/session.cjs.map +1 -1
- package/durable-sqlite/session.d.cts +10 -6
- package/durable-sqlite/session.d.ts +10 -6
- package/durable-sqlite/session.js +16 -15
- package/durable-sqlite/session.js.map +1 -1
- package/effect-postgres/driver.cjs +99 -13
- package/effect-postgres/driver.cjs.map +1 -1
- package/effect-postgres/driver.d.cts +12 -8
- package/effect-postgres/driver.d.ts +12 -8
- package/effect-postgres/driver.js +99 -13
- package/effect-postgres/driver.js.map +1 -1
- package/effect-postgres/index.cjs +1 -1
- package/effect-postgres/index.d.cts +3 -3
- package/effect-postgres/index.d.ts +3 -3
- package/effect-postgres/index.js +3 -3
- package/effect-postgres/migrator.cjs.map +1 -1
- package/effect-postgres/migrator.d.cts +1 -1
- package/effect-postgres/migrator.d.ts +1 -1
- package/effect-postgres/migrator.js.map +1 -1
- package/effect-postgres/session.cjs +12 -71
- package/effect-postgres/session.cjs.map +1 -1
- package/effect-postgres/session.d.cts +14 -31
- package/effect-postgres/session.d.ts +16 -33
- package/effect-postgres/session.js +13 -71
- package/effect-postgres/session.js.map +1 -1
- package/expo-sqlite/driver.cjs +5 -2
- package/expo-sqlite/driver.cjs.map +1 -1
- package/expo-sqlite/driver.d.ts +1 -1
- package/expo-sqlite/driver.js +5 -2
- package/expo-sqlite/driver.js.map +1 -1
- package/expo-sqlite/session.cjs +15 -14
- package/expo-sqlite/session.cjs.map +1 -1
- package/expo-sqlite/session.d.cts +10 -6
- package/expo-sqlite/session.d.ts +10 -6
- package/expo-sqlite/session.js +16 -15
- package/expo-sqlite/session.js.map +1 -1
- package/gel/driver.cjs +4 -2
- package/gel/driver.cjs.map +1 -1
- package/gel/driver.d.cts +1 -0
- package/gel/driver.d.ts +2 -1
- package/gel/driver.js +4 -2
- package/gel/driver.js.map +1 -1
- package/gel/session.cjs +12 -12
- package/gel/session.cjs.map +1 -1
- package/gel/session.d.cts +8 -5
- package/gel/session.d.ts +9 -6
- package/gel/session.js +13 -13
- package/gel/session.js.map +1 -1
- package/gel-core/columns/bigintT.cjs +2 -2
- package/gel-core/columns/bigintT.cjs.map +1 -1
- package/gel-core/columns/bigintT.d.cts +1 -1
- package/gel-core/columns/bigintT.d.ts +1 -1
- package/gel-core/columns/bigintT.js +2 -2
- package/gel-core/columns/bigintT.js.map +1 -1
- package/gel-core/columns/common.cjs +2 -2
- package/gel-core/columns/common.cjs.map +1 -1
- package/gel-core/columns/common.d.cts +1 -1
- package/gel-core/columns/common.d.ts +1 -1
- package/gel-core/columns/common.js +2 -2
- package/gel-core/columns/common.js.map +1 -1
- package/gel-core/columns/custom.cjs +4 -4
- package/gel-core/columns/custom.cjs.map +1 -1
- package/gel-core/columns/custom.d.cts +2 -2
- package/gel-core/columns/custom.d.ts +2 -2
- package/gel-core/columns/custom.js +4 -4
- package/gel-core/columns/custom.js.map +1 -1
- package/gel-core/columns/double-precision.cjs +2 -2
- package/gel-core/columns/double-precision.cjs.map +1 -1
- package/gel-core/columns/double-precision.d.cts +1 -1
- package/gel-core/columns/double-precision.d.ts +1 -1
- package/gel-core/columns/double-precision.js +2 -2
- package/gel-core/columns/double-precision.js.map +1 -1
- package/gel-core/columns/timestamptz.cjs +2 -2
- package/gel-core/columns/timestamptz.cjs.map +1 -1
- package/gel-core/columns/timestamptz.d.cts +1 -1
- package/gel-core/columns/timestamptz.d.ts +1 -1
- package/gel-core/columns/timestamptz.js +2 -2
- package/gel-core/columns/timestamptz.js.map +1 -1
- package/gel-core/db.cjs +1 -1
- package/gel-core/db.cjs.map +1 -1
- package/gel-core/db.d.ts +1 -1
- package/gel-core/db.js +1 -1
- package/gel-core/db.js.map +1 -1
- package/gel-core/query-builders/_query.cjs +2 -2
- package/gel-core/query-builders/_query.cjs.map +1 -1
- package/gel-core/query-builders/_query.js +2 -2
- package/gel-core/query-builders/_query.js.map +1 -1
- package/gel-core/query-builders/delete.cjs +2 -2
- package/gel-core/query-builders/delete.cjs.map +1 -1
- package/gel-core/query-builders/delete.js +2 -2
- package/gel-core/query-builders/delete.js.map +1 -1
- package/gel-core/query-builders/insert.cjs +2 -2
- package/gel-core/query-builders/insert.cjs.map +1 -1
- package/gel-core/query-builders/insert.js +2 -2
- package/gel-core/query-builders/insert.js.map +1 -1
- package/gel-core/query-builders/query.cjs +13 -5
- package/gel-core/query-builders/query.cjs.map +1 -1
- package/gel-core/query-builders/query.d.ts +1 -1
- package/gel-core/query-builders/query.js +14 -6
- package/gel-core/query-builders/query.js.map +1 -1
- package/gel-core/query-builders/raw.cjs +0 -4
- package/gel-core/query-builders/raw.cjs.map +1 -1
- package/gel-core/query-builders/raw.js +0 -4
- package/gel-core/query-builders/raw.js.map +1 -1
- package/gel-core/query-builders/refresh-materialized-view.cjs +2 -2
- package/gel-core/query-builders/refresh-materialized-view.cjs.map +1 -1
- package/gel-core/query-builders/refresh-materialized-view.js +2 -2
- package/gel-core/query-builders/refresh-materialized-view.js.map +1 -1
- package/gel-core/query-builders/select.cjs +6 -2
- package/gel-core/query-builders/select.cjs.map +1 -1
- package/gel-core/query-builders/select.js +6 -2
- package/gel-core/query-builders/select.js.map +1 -1
- package/gel-core/query-builders/update.cjs +2 -2
- package/gel-core/query-builders/update.cjs.map +1 -1
- package/gel-core/query-builders/update.js +2 -2
- package/gel-core/query-builders/update.js.map +1 -1
- package/gel-core/session.cjs +2 -2
- package/gel-core/session.cjs.map +1 -1
- package/gel-core/session.d.cts +3 -3
- package/gel-core/session.d.ts +3 -3
- package/gel-core/session.js +2 -2
- package/gel-core/session.js.map +1 -1
- package/gel-core/table.cjs +1 -1
- package/gel-core/table.cjs.map +1 -1
- package/gel-core/table.js +1 -1
- package/gel-core/table.js.map +1 -1
- package/index.cjs +6 -0
- package/index.d.cts +6 -6
- package/index.d.ts +6 -6
- package/index.js +4 -4
- package/libsql/driver-core.cjs +3 -2
- package/libsql/driver-core.cjs.map +1 -1
- package/libsql/driver-core.d.ts +1 -1
- package/libsql/driver-core.js +3 -2
- package/libsql/driver-core.js.map +1 -1
- package/libsql/session.cjs +13 -14
- package/libsql/session.cjs.map +1 -1
- package/libsql/session.d.cts +9 -6
- package/libsql/session.d.ts +9 -6
- package/libsql/session.js +14 -15
- package/libsql/session.js.map +1 -1
- package/mssql-core/columns/bigint.cjs +2 -2
- package/mssql-core/columns/bigint.cjs.map +1 -1
- package/mssql-core/columns/bigint.d.cts +1 -1
- package/mssql-core/columns/bigint.d.ts +1 -1
- package/mssql-core/columns/bigint.js +2 -2
- package/mssql-core/columns/bigint.js.map +1 -1
- package/mssql-core/columns/custom.cjs +4 -4
- package/mssql-core/columns/custom.cjs.map +1 -1
- package/mssql-core/columns/custom.d.cts +2 -2
- package/mssql-core/columns/custom.d.ts +2 -2
- package/mssql-core/columns/custom.js +4 -4
- package/mssql-core/columns/custom.js.map +1 -1
- package/mssql-core/columns/date.cjs +4 -4
- package/mssql-core/columns/date.cjs.map +1 -1
- package/mssql-core/columns/date.d.cts +2 -2
- package/mssql-core/columns/date.d.ts +2 -2
- package/mssql-core/columns/date.js +4 -4
- package/mssql-core/columns/date.js.map +1 -1
- package/mssql-core/columns/datetime.cjs +2 -2
- package/mssql-core/columns/datetime.cjs.map +1 -1
- package/mssql-core/columns/datetime.d.cts +1 -1
- package/mssql-core/columns/datetime.d.ts +1 -1
- package/mssql-core/columns/datetime.js +2 -2
- package/mssql-core/columns/datetime.js.map +1 -1
- package/mssql-core/columns/datetime2.cjs +2 -2
- package/mssql-core/columns/datetime2.cjs.map +1 -1
- package/mssql-core/columns/datetime2.d.cts +1 -1
- package/mssql-core/columns/datetime2.d.ts +1 -1
- package/mssql-core/columns/datetime2.js +2 -2
- package/mssql-core/columns/datetime2.js.map +1 -1
- package/mssql-core/columns/datetimeoffset.cjs +2 -2
- package/mssql-core/columns/datetimeoffset.cjs.map +1 -1
- package/mssql-core/columns/datetimeoffset.d.cts +1 -1
- package/mssql-core/columns/datetimeoffset.d.ts +1 -1
- package/mssql-core/columns/datetimeoffset.js +2 -2
- package/mssql-core/columns/datetimeoffset.js.map +1 -1
- package/mssql-core/columns/decimal.cjs +4 -4
- package/mssql-core/columns/decimal.cjs.map +1 -1
- package/mssql-core/columns/decimal.d.cts +2 -2
- package/mssql-core/columns/decimal.d.ts +2 -2
- package/mssql-core/columns/decimal.js +4 -4
- package/mssql-core/columns/decimal.js.map +1 -1
- package/mssql-core/columns/numeric.cjs +4 -4
- package/mssql-core/columns/numeric.cjs.map +1 -1
- package/mssql-core/columns/numeric.d.cts +2 -2
- package/mssql-core/columns/numeric.d.ts +2 -2
- package/mssql-core/columns/numeric.js +4 -4
- package/mssql-core/columns/numeric.js.map +1 -1
- package/mssql-core/columns/smallint.cjs +2 -2
- package/mssql-core/columns/smallint.cjs.map +1 -1
- package/mssql-core/columns/smallint.d.cts +1 -1
- package/mssql-core/columns/smallint.d.ts +1 -1
- package/mssql-core/columns/smallint.js +2 -2
- package/mssql-core/columns/smallint.js.map +1 -1
- package/mssql-core/columns/time.cjs +2 -2
- package/mssql-core/columns/time.cjs.map +1 -1
- package/mssql-core/columns/time.d.cts +1 -1
- package/mssql-core/columns/time.d.ts +1 -1
- package/mssql-core/columns/time.js +2 -2
- package/mssql-core/columns/time.js.map +1 -1
- package/mssql-core/columns/tinyint.cjs +2 -2
- package/mssql-core/columns/tinyint.cjs.map +1 -1
- package/mssql-core/columns/tinyint.d.cts +1 -1
- package/mssql-core/columns/tinyint.d.ts +1 -1
- package/mssql-core/columns/tinyint.js +2 -2
- package/mssql-core/columns/tinyint.js.map +1 -1
- package/mssql-core/columns/varchar.cjs +4 -4
- package/mssql-core/columns/varchar.cjs.map +1 -1
- package/mssql-core/columns/varchar.d.cts +2 -2
- package/mssql-core/columns/varchar.d.ts +2 -2
- package/mssql-core/columns/varchar.js +4 -4
- package/mssql-core/columns/varchar.js.map +1 -1
- package/mssql-core/dialect.cjs +1 -1
- package/mssql-core/dialect.d.ts +1 -1
- package/mssql-core/dialect.js +1 -1
- package/mssql-core/query-builders/select.cjs +4 -0
- package/mssql-core/query-builders/select.cjs.map +1 -1
- package/mssql-core/query-builders/select.js +4 -0
- package/mssql-core/query-builders/select.js.map +1 -1
- package/mssql-core/query-builders/update.d.ts +1 -1
- package/mssql-core/table.cjs +1 -1
- package/mssql-core/table.cjs.map +1 -1
- package/mssql-core/table.js +1 -1
- package/mssql-core/table.js.map +1 -1
- package/mysql-core/columns/bigint.cjs +8 -8
- package/mysql-core/columns/bigint.cjs.map +1 -1
- package/mysql-core/columns/bigint.d.cts +4 -4
- package/mysql-core/columns/bigint.d.ts +4 -4
- package/mysql-core/columns/bigint.js +8 -8
- package/mysql-core/columns/bigint.js.map +1 -1
- package/mysql-core/columns/binary.cjs +2 -2
- package/mysql-core/columns/binary.cjs.map +1 -1
- package/mysql-core/columns/binary.d.cts +1 -1
- package/mysql-core/columns/binary.d.ts +1 -1
- package/mysql-core/columns/binary.js +2 -2
- package/mysql-core/columns/binary.js.map +1 -1
- package/mysql-core/columns/blob.cjs +4 -4
- package/mysql-core/columns/blob.cjs.map +1 -1
- package/mysql-core/columns/blob.d.cts +2 -2
- package/mysql-core/columns/blob.d.ts +2 -2
- package/mysql-core/columns/blob.js +4 -4
- package/mysql-core/columns/blob.js.map +1 -1
- package/mysql-core/columns/boolean.cjs +2 -2
- package/mysql-core/columns/boolean.cjs.map +1 -1
- package/mysql-core/columns/boolean.d.cts +1 -1
- package/mysql-core/columns/boolean.d.ts +1 -1
- package/mysql-core/columns/boolean.js +2 -2
- package/mysql-core/columns/boolean.js.map +1 -1
- package/mysql-core/columns/custom.cjs +4 -4
- package/mysql-core/columns/custom.cjs.map +1 -1
- package/mysql-core/columns/custom.d.cts +2 -2
- package/mysql-core/columns/custom.d.ts +2 -2
- package/mysql-core/columns/custom.js +4 -4
- package/mysql-core/columns/custom.js.map +1 -1
- package/mysql-core/columns/date.cjs +4 -4
- package/mysql-core/columns/date.cjs.map +1 -1
- package/mysql-core/columns/date.d.cts +2 -2
- package/mysql-core/columns/date.d.ts +2 -2
- package/mysql-core/columns/date.js +4 -4
- package/mysql-core/columns/date.js.map +1 -1
- package/mysql-core/columns/datetime.cjs +8 -8
- package/mysql-core/columns/datetime.cjs.map +1 -1
- package/mysql-core/columns/datetime.d.cts +4 -4
- package/mysql-core/columns/datetime.d.ts +4 -4
- package/mysql-core/columns/datetime.js +8 -8
- package/mysql-core/columns/datetime.js.map +1 -1
- package/mysql-core/columns/decimal.cjs +4 -4
- package/mysql-core/columns/decimal.cjs.map +1 -1
- package/mysql-core/columns/decimal.d.cts +2 -2
- package/mysql-core/columns/decimal.d.ts +2 -2
- package/mysql-core/columns/decimal.js +4 -4
- package/mysql-core/columns/decimal.js.map +1 -1
- package/mysql-core/columns/float.cjs +2 -2
- package/mysql-core/columns/float.cjs.map +1 -1
- package/mysql-core/columns/float.d.cts +1 -1
- package/mysql-core/columns/float.d.ts +1 -1
- package/mysql-core/columns/float.js +2 -2
- package/mysql-core/columns/float.js.map +1 -1
- package/mysql-core/columns/int.cjs +2 -2
- package/mysql-core/columns/int.cjs.map +1 -1
- package/mysql-core/columns/int.d.cts +1 -1
- package/mysql-core/columns/int.d.ts +1 -1
- package/mysql-core/columns/int.js +2 -2
- package/mysql-core/columns/int.js.map +1 -1
- package/mysql-core/columns/json.cjs +2 -2
- package/mysql-core/columns/json.cjs.map +1 -1
- package/mysql-core/columns/json.d.cts +1 -1
- package/mysql-core/columns/json.d.ts +1 -1
- package/mysql-core/columns/json.js +2 -2
- package/mysql-core/columns/json.js.map +1 -1
- package/mysql-core/columns/mediumint.cjs +2 -2
- package/mysql-core/columns/mediumint.cjs.map +1 -1
- package/mysql-core/columns/mediumint.d.cts +1 -1
- package/mysql-core/columns/mediumint.d.ts +1 -1
- package/mysql-core/columns/mediumint.js +2 -2
- package/mysql-core/columns/mediumint.js.map +1 -1
- package/mysql-core/columns/serial.cjs +2 -2
- package/mysql-core/columns/serial.cjs.map +1 -1
- package/mysql-core/columns/serial.d.cts +1 -1
- package/mysql-core/columns/serial.d.ts +1 -1
- package/mysql-core/columns/serial.js +2 -2
- package/mysql-core/columns/serial.js.map +1 -1
- package/mysql-core/columns/smallint.cjs +2 -2
- package/mysql-core/columns/smallint.cjs.map +1 -1
- package/mysql-core/columns/smallint.d.cts +1 -1
- package/mysql-core/columns/smallint.d.ts +1 -1
- package/mysql-core/columns/smallint.js +2 -2
- package/mysql-core/columns/smallint.js.map +1 -1
- package/mysql-core/columns/time.cjs +2 -2
- package/mysql-core/columns/time.cjs.map +1 -1
- package/mysql-core/columns/time.d.cts +1 -1
- package/mysql-core/columns/time.d.ts +1 -1
- package/mysql-core/columns/time.js +2 -2
- package/mysql-core/columns/time.js.map +1 -1
- package/mysql-core/columns/timestamp.cjs +8 -8
- package/mysql-core/columns/timestamp.cjs.map +1 -1
- package/mysql-core/columns/timestamp.d.cts +4 -4
- package/mysql-core/columns/timestamp.d.ts +4 -4
- package/mysql-core/columns/timestamp.js +8 -8
- package/mysql-core/columns/timestamp.js.map +1 -1
- package/mysql-core/columns/tinyint.cjs +2 -2
- package/mysql-core/columns/tinyint.cjs.map +1 -1
- package/mysql-core/columns/tinyint.d.cts +1 -1
- package/mysql-core/columns/tinyint.d.ts +1 -1
- package/mysql-core/columns/tinyint.js +2 -2
- package/mysql-core/columns/tinyint.js.map +1 -1
- package/mysql-core/columns/varbinary.cjs +2 -2
- package/mysql-core/columns/varbinary.cjs.map +1 -1
- package/mysql-core/columns/varbinary.d.cts +1 -1
- package/mysql-core/columns/varbinary.d.ts +1 -1
- package/mysql-core/columns/varbinary.js +2 -2
- package/mysql-core/columns/varbinary.js.map +1 -1
- package/mysql-core/columns/year.cjs +2 -2
- package/mysql-core/columns/year.cjs.map +1 -1
- package/mysql-core/columns/year.d.cts +1 -1
- package/mysql-core/columns/year.d.ts +1 -1
- package/mysql-core/columns/year.js +2 -2
- package/mysql-core/columns/year.js.map +1 -1
- package/mysql-core/db.d.ts +1 -1
- package/mysql-core/dialect.cjs +1 -1
- package/mysql-core/dialect.d.ts +1 -1
- package/mysql-core/dialect.js +1 -1
- package/mysql-core/query-builders/query.cjs +13 -5
- package/mysql-core/query-builders/query.cjs.map +1 -1
- package/mysql-core/query-builders/query.d.ts +1 -1
- package/mysql-core/query-builders/query.js +13 -5
- package/mysql-core/query-builders/query.js.map +1 -1
- package/mysql-core/query-builders/select.cjs +4 -0
- package/mysql-core/query-builders/select.cjs.map +1 -1
- package/mysql-core/query-builders/select.js +4 -0
- package/mysql-core/query-builders/select.js.map +1 -1
- package/mysql-core/session.cjs +1 -2
- package/mysql-core/session.cjs.map +1 -1
- package/mysql-core/session.d.cts +3 -4
- package/mysql-core/session.d.ts +3 -4
- package/mysql-core/session.js +1 -2
- package/mysql-core/session.js.map +1 -1
- package/mysql-core/table.cjs +1 -1
- package/mysql-core/table.cjs.map +1 -1
- package/mysql-core/table.js +1 -1
- package/mysql-core/table.js.map +1 -1
- package/mysql-proxy/driver.cjs +5 -2
- package/mysql-proxy/driver.cjs.map +1 -1
- package/mysql-proxy/driver.js +5 -2
- package/mysql-proxy/driver.js.map +1 -1
- package/mysql-proxy/session.cjs +25 -18
- package/mysql-proxy/session.cjs.map +1 -1
- package/mysql-proxy/session.d.cts +11 -4
- package/mysql-proxy/session.d.ts +12 -5
- package/mysql-proxy/session.js +26 -19
- package/mysql-proxy/session.js.map +1 -1
- package/mysql2/driver.cjs +3 -2
- package/mysql2/driver.cjs.map +1 -1
- package/mysql2/driver.d.cts +1 -0
- package/mysql2/driver.d.ts +3 -2
- package/mysql2/driver.js +3 -2
- package/mysql2/driver.js.map +1 -1
- package/mysql2/session.cjs +48 -38
- package/mysql2/session.cjs.map +1 -1
- package/mysql2/session.d.cts +11 -4
- package/mysql2/session.d.ts +12 -5
- package/mysql2/session.js +49 -39
- package/mysql2/session.js.map +1 -1
- package/neon-http/driver.cjs +34 -65
- package/neon-http/driver.cjs.map +1 -1
- package/neon-http/driver.d.cts +15 -19
- package/neon-http/driver.d.ts +16 -20
- package/neon-http/driver.js +34 -64
- package/neon-http/driver.js.map +1 -1
- package/neon-http/index.cjs +2 -4
- package/neon-http/index.d.cts +3 -3
- package/neon-http/index.d.ts +3 -3
- package/neon-http/index.js +3 -3
- package/neon-http/migrator.cjs +1 -1
- package/neon-http/migrator.cjs.map +1 -1
- package/neon-http/migrator.d.cts +1 -1
- package/neon-http/migrator.d.ts +1 -1
- package/neon-http/migrator.js +1 -1
- package/neon-http/migrator.js.map +1 -1
- package/neon-http/session.cjs +27 -116
- package/neon-http/session.cjs.map +1 -1
- package/neon-http/session.d.cts +10 -38
- package/neon-http/session.d.ts +10 -38
- package/neon-http/session.js +29 -116
- package/neon-http/session.js.map +1 -1
- package/neon-serverless/driver.cjs +14 -32
- package/neon-serverless/driver.cjs.map +1 -1
- package/neon-serverless/driver.d.cts +12 -17
- package/neon-serverless/driver.d.ts +13 -18
- package/neon-serverless/driver.js +14 -31
- package/neon-serverless/driver.js.map +1 -1
- package/neon-serverless/index.cjs +2 -3
- package/neon-serverless/index.d.cts +3 -3
- package/neon-serverless/index.d.ts +3 -3
- package/neon-serverless/index.js +3 -3
- package/neon-serverless/migrator.cjs.map +1 -1
- package/neon-serverless/migrator.d.cts +1 -1
- package/neon-serverless/migrator.d.ts +1 -1
- package/neon-serverless/migrator.js.map +1 -1
- package/neon-serverless/session.cjs +32 -108
- package/neon-serverless/session.cjs.map +1 -1
- package/neon-serverless/session.d.cts +9 -32
- package/neon-serverless/session.d.ts +9 -32
- package/neon-serverless/session.js +34 -109
- package/neon-serverless/session.js.map +1 -1
- package/netlify-db/driver.cjs +36 -43
- package/netlify-db/driver.cjs.map +1 -1
- package/netlify-db/driver.d.cts +29 -29
- package/netlify-db/driver.d.ts +31 -31
- package/netlify-db/driver.js +35 -42
- package/netlify-db/driver.js.map +1 -1
- package/netlify-db/index.cjs +3 -2
- package/netlify-db/index.d.cts +3 -3
- package/netlify-db/index.d.ts +3 -3
- package/netlify-db/index.js +2 -2
- package/netlify-db/migrator.cjs.map +1 -1
- package/netlify-db/migrator.d.cts +1 -1
- package/netlify-db/migrator.d.ts +1 -1
- package/netlify-db/migrator.js.map +1 -1
- package/netlify-db/session.cjs +61 -39
- package/netlify-db/session.cjs.map +1 -1
- package/netlify-db/session.d.cts +22 -23
- package/netlify-db/session.d.ts +23 -24
- package/netlify-db/session.js +63 -41
- package/netlify-db/session.js.map +1 -1
- package/node-mssql/driver.cjs +9 -3
- package/node-mssql/driver.cjs.map +1 -1
- package/node-mssql/driver.d.cts +1 -0
- package/node-mssql/driver.d.ts +2 -1
- package/node-mssql/driver.js +9 -3
- package/node-mssql/driver.js.map +1 -1
- package/node-mssql/session.cjs +6 -4
- package/node-mssql/session.cjs.map +1 -1
- package/node-mssql/session.d.cts +4 -1
- package/node-mssql/session.d.ts +5 -2
- package/node-mssql/session.js +7 -5
- package/node-mssql/session.js.map +1 -1
- package/node-postgres/driver.cjs +15 -18
- package/node-postgres/driver.cjs.map +1 -1
- package/node-postgres/driver.d.cts +11 -6
- package/node-postgres/driver.d.ts +12 -7
- package/node-postgres/driver.js +15 -18
- package/node-postgres/driver.js.map +1 -1
- package/node-postgres/index.cjs +2 -2
- package/node-postgres/index.d.cts +3 -3
- package/node-postgres/index.d.ts +3 -3
- package/node-postgres/index.js +3 -3
- package/node-postgres/migrator.cjs.map +1 -1
- package/node-postgres/migrator.d.cts +1 -1
- package/node-postgres/migrator.d.ts +1 -1
- package/node-postgres/migrator.js.map +1 -1
- package/node-postgres/session.cjs +32 -125
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.d.cts +10 -30
- package/node-postgres/session.d.ts +9 -29
- package/node-postgres/session.js +34 -126
- package/node-postgres/session.js.map +1 -1
- package/node-sqlite/driver.cjs +1 -1
- package/node-sqlite/driver.d.ts +1 -1
- package/node-sqlite/driver.js +1 -1
- package/node-sqlite/session.cjs +4 -9
- package/node-sqlite/session.cjs.map +1 -1
- package/node-sqlite/session.d.cts +3 -4
- package/node-sqlite/session.d.ts +4 -5
- package/node-sqlite/session.js +4 -9
- package/node-sqlite/session.js.map +1 -1
- package/op-sqlite/driver.cjs +3 -2
- package/op-sqlite/driver.cjs.map +1 -1
- package/op-sqlite/driver.d.ts +1 -1
- package/op-sqlite/driver.js +3 -2
- package/op-sqlite/driver.js.map +1 -1
- package/op-sqlite/session.cjs +17 -15
- package/op-sqlite/session.cjs.map +1 -1
- package/op-sqlite/session.d.cts +10 -6
- package/op-sqlite/session.d.ts +10 -6
- package/op-sqlite/session.js +18 -16
- package/op-sqlite/session.js.map +1 -1
- package/operations.d.cts +3 -0
- package/operations.d.ts +3 -0
- package/package.json +43 -31
- package/pg-core/{utils/array.cjs → array.cjs} +1 -1
- package/pg-core/array.cjs.map +1 -0
- package/pg-core/{utils/array.d.cts → array.d.cts} +1 -1
- package/pg-core/{utils/array.d.ts → array.d.ts} +1 -1
- package/pg-core/{utils/array.js → array.js} +1 -1
- package/pg-core/array.js.map +1 -0
- package/pg-core/async/count.cjs +2 -9
- package/pg-core/async/count.cjs.map +1 -1
- package/pg-core/async/count.js +2 -9
- package/pg-core/async/count.js.map +1 -1
- package/pg-core/async/db.cjs +8 -28
- package/pg-core/async/db.cjs.map +1 -1
- package/pg-core/async/db.d.cts +5 -13
- package/pg-core/async/db.d.ts +6 -14
- package/pg-core/async/db.js +8 -28
- package/pg-core/async/db.js.map +1 -1
- package/pg-core/async/delete.cjs +7 -12
- package/pg-core/async/delete.cjs.map +1 -1
- package/pg-core/async/delete.js +7 -12
- package/pg-core/async/delete.js.map +1 -1
- package/pg-core/async/insert.cjs +7 -12
- package/pg-core/async/insert.cjs.map +1 -1
- package/pg-core/async/insert.js +7 -12
- package/pg-core/async/insert.js.map +1 -1
- package/pg-core/async/query.cjs +8 -14
- package/pg-core/async/query.cjs.map +1 -1
- package/pg-core/async/query.js +8 -14
- package/pg-core/async/query.js.map +1 -1
- package/pg-core/async/refresh-materialized-view.cjs +1 -9
- package/pg-core/async/refresh-materialized-view.cjs.map +1 -1
- package/pg-core/async/refresh-materialized-view.js +1 -9
- package/pg-core/async/refresh-materialized-view.js.map +1 -1
- package/pg-core/async/select.cjs +4 -13
- package/pg-core/async/select.cjs.map +1 -1
- package/pg-core/async/select.js +4 -13
- package/pg-core/async/select.js.map +1 -1
- package/pg-core/async/session.cjs +44 -20
- package/pg-core/async/session.cjs.map +1 -1
- package/pg-core/async/session.d.cts +25 -31
- package/pg-core/async/session.d.ts +26 -32
- package/pg-core/async/session.js +45 -21
- package/pg-core/async/session.js.map +1 -1
- package/pg-core/async/update.cjs +11 -15
- package/pg-core/async/update.cjs.map +1 -1
- package/pg-core/async/update.js +11 -15
- package/pg-core/async/update.js.map +1 -1
- package/pg-core/codecs.cjs +156 -0
- package/pg-core/codecs.cjs.map +1 -0
- package/pg-core/codecs.d.cts +27 -0
- package/pg-core/codecs.d.ts +27 -0
- package/pg-core/codecs.js +148 -0
- package/pg-core/codecs.js.map +1 -0
- package/pg-core/columns/bigint.cjs +10 -9
- package/pg-core/columns/bigint.cjs.map +1 -1
- package/pg-core/columns/bigint.d.cts +2 -3
- package/pg-core/columns/bigint.d.ts +2 -3
- package/pg-core/columns/bigint.js +10 -9
- package/pg-core/columns/bigint.js.map +1 -1
- package/pg-core/columns/bigserial.cjs +6 -6
- package/pg-core/columns/bigserial.cjs.map +1 -1
- package/pg-core/columns/bigserial.d.cts +1 -2
- package/pg-core/columns/bigserial.d.ts +1 -2
- package/pg-core/columns/bigserial.js +6 -6
- package/pg-core/columns/bigserial.js.map +1 -1
- package/pg-core/columns/boolean.cjs +2 -0
- package/pg-core/columns/boolean.cjs.map +1 -1
- package/pg-core/columns/boolean.js +2 -0
- package/pg-core/columns/boolean.js.map +1 -1
- package/pg-core/columns/bytea.cjs +2 -8
- package/pg-core/columns/bytea.cjs.map +1 -1
- package/pg-core/columns/bytea.d.cts +0 -1
- package/pg-core/columns/bytea.d.ts +0 -1
- package/pg-core/columns/bytea.js +2 -8
- package/pg-core/columns/bytea.js.map +1 -1
- package/pg-core/columns/char.cjs +2 -0
- package/pg-core/columns/char.cjs.map +1 -1
- package/pg-core/columns/char.js +2 -0
- package/pg-core/columns/char.js.map +1 -1
- package/pg-core/columns/cidr.cjs +2 -0
- package/pg-core/columns/cidr.cjs.map +1 -1
- package/pg-core/columns/cidr.js +2 -0
- package/pg-core/columns/cidr.js.map +1 -1
- package/pg-core/columns/common.cjs +10 -8
- package/pg-core/columns/common.cjs.map +1 -1
- package/pg-core/columns/common.d.cts +34 -39
- package/pg-core/columns/common.d.ts +34 -39
- package/pg-core/columns/common.js +10 -8
- package/pg-core/columns/common.js.map +1 -1
- package/pg-core/columns/custom.cjs +16 -46
- package/pg-core/columns/custom.cjs.map +1 -1
- package/pg-core/columns/custom.d.cts +17 -8
- package/pg-core/columns/custom.d.ts +17 -8
- package/pg-core/columns/custom.js +16 -46
- package/pg-core/columns/custom.js.map +1 -1
- package/pg-core/columns/date.cjs +11 -12
- package/pg-core/columns/date.cjs.map +1 -1
- package/pg-core/columns/date.d.cts +3 -4
- package/pg-core/columns/date.d.ts +3 -4
- package/pg-core/columns/date.js +11 -12
- package/pg-core/columns/date.js.map +1 -1
- package/pg-core/columns/double-precision.cjs +2 -4
- package/pg-core/columns/double-precision.cjs.map +1 -1
- package/pg-core/columns/double-precision.d.cts +0 -1
- package/pg-core/columns/double-precision.d.ts +0 -1
- package/pg-core/columns/double-precision.js +2 -4
- package/pg-core/columns/double-precision.js.map +1 -1
- package/pg-core/columns/enum.cjs +4 -0
- package/pg-core/columns/enum.cjs.map +1 -1
- package/pg-core/columns/enum.js +4 -0
- package/pg-core/columns/enum.js.map +1 -1
- package/pg-core/columns/index.d.cts +2 -2
- package/pg-core/columns/index.d.ts +2 -2
- package/pg-core/columns/inet.cjs +2 -0
- package/pg-core/columns/inet.cjs.map +1 -1
- package/pg-core/columns/inet.js +2 -0
- package/pg-core/columns/inet.js.map +1 -1
- package/pg-core/columns/integer.cjs +2 -4
- package/pg-core/columns/integer.cjs.map +1 -1
- package/pg-core/columns/integer.d.cts +0 -1
- package/pg-core/columns/integer.d.ts +0 -1
- package/pg-core/columns/integer.js +2 -4
- package/pg-core/columns/integer.js.map +1 -1
- package/pg-core/columns/interval.cjs +2 -0
- package/pg-core/columns/interval.cjs.map +1 -1
- package/pg-core/columns/interval.js +2 -0
- package/pg-core/columns/interval.js.map +1 -1
- package/pg-core/columns/json.cjs +2 -11
- package/pg-core/columns/json.cjs.map +1 -1
- package/pg-core/columns/json.d.cts +0 -2
- package/pg-core/columns/json.d.ts +0 -2
- package/pg-core/columns/json.js +2 -11
- package/pg-core/columns/json.js.map +1 -1
- package/pg-core/columns/jsonb.cjs +2 -11
- package/pg-core/columns/jsonb.cjs.map +1 -1
- package/pg-core/columns/jsonb.d.cts +0 -2
- package/pg-core/columns/jsonb.d.ts +0 -2
- package/pg-core/columns/jsonb.js +2 -11
- package/pg-core/columns/jsonb.js.map +1 -1
- package/pg-core/columns/line.cjs +12 -8
- package/pg-core/columns/line.cjs.map +1 -1
- package/pg-core/columns/line.d.cts +5 -5
- package/pg-core/columns/line.d.ts +5 -5
- package/pg-core/columns/line.js +12 -8
- package/pg-core/columns/line.js.map +1 -1
- package/pg-core/columns/macaddr.cjs +2 -0
- package/pg-core/columns/macaddr.cjs.map +1 -1
- package/pg-core/columns/macaddr.js +2 -0
- package/pg-core/columns/macaddr.js.map +1 -1
- package/pg-core/columns/macaddr8.cjs +2 -0
- package/pg-core/columns/macaddr8.cjs.map +1 -1
- package/pg-core/columns/macaddr8.js +2 -0
- package/pg-core/columns/macaddr8.js.map +1 -1
- package/pg-core/columns/numeric.cjs +12 -15
- package/pg-core/columns/numeric.cjs.map +1 -1
- package/pg-core/columns/numeric.d.cts +4 -5
- package/pg-core/columns/numeric.d.ts +4 -5
- package/pg-core/columns/numeric.js +12 -15
- package/pg-core/columns/numeric.js.map +1 -1
- package/pg-core/columns/point.cjs +19 -21
- package/pg-core/columns/point.cjs.map +1 -1
- package/pg-core/columns/point.d.cts +5 -11
- package/pg-core/columns/point.d.ts +5 -11
- package/pg-core/columns/point.js +19 -21
- package/pg-core/columns/point.js.map +1 -1
- package/pg-core/columns/postgis_extension/geometry.cjs +12 -9
- package/pg-core/columns/postgis_extension/geometry.cjs.map +1 -1
- package/pg-core/columns/postgis_extension/geometry.d.cts +5 -5
- package/pg-core/columns/postgis_extension/geometry.d.ts +5 -5
- package/pg-core/columns/postgis_extension/geometry.js +12 -9
- package/pg-core/columns/postgis_extension/geometry.js.map +1 -1
- package/pg-core/columns/real.cjs +2 -4
- package/pg-core/columns/real.cjs.map +1 -1
- package/pg-core/columns/real.d.cts +0 -1
- package/pg-core/columns/real.d.ts +0 -1
- package/pg-core/columns/real.js +2 -4
- package/pg-core/columns/real.js.map +1 -1
- package/pg-core/columns/serial.cjs +2 -0
- package/pg-core/columns/serial.cjs.map +1 -1
- package/pg-core/columns/serial.js +2 -0
- package/pg-core/columns/serial.js.map +1 -1
- package/pg-core/columns/smallint.cjs +2 -4
- package/pg-core/columns/smallint.cjs.map +1 -1
- package/pg-core/columns/smallint.d.cts +0 -1
- package/pg-core/columns/smallint.d.ts +0 -1
- package/pg-core/columns/smallint.js +2 -4
- package/pg-core/columns/smallint.js.map +1 -1
- package/pg-core/columns/smallserial.cjs +2 -0
- package/pg-core/columns/smallserial.cjs.map +1 -1
- package/pg-core/columns/smallserial.js +2 -0
- package/pg-core/columns/smallserial.js.map +1 -1
- package/pg-core/columns/text.cjs +2 -0
- package/pg-core/columns/text.cjs.map +1 -1
- package/pg-core/columns/text.js +2 -0
- package/pg-core/columns/text.js.map +1 -1
- package/pg-core/columns/time.cjs +2 -0
- package/pg-core/columns/time.cjs.map +1 -1
- package/pg-core/columns/time.js +2 -0
- package/pg-core/columns/time.js.map +1 -1
- package/pg-core/columns/timestamp.cjs +13 -14
- package/pg-core/columns/timestamp.cjs.map +1 -1
- package/pg-core/columns/timestamp.d.cts +3 -4
- package/pg-core/columns/timestamp.d.ts +3 -4
- package/pg-core/columns/timestamp.js +13 -14
- package/pg-core/columns/timestamp.js.map +1 -1
- package/pg-core/columns/uuid.cjs +2 -0
- package/pg-core/columns/uuid.cjs.map +1 -1
- package/pg-core/columns/uuid.js +2 -0
- package/pg-core/columns/uuid.js.map +1 -1
- package/pg-core/columns/varchar.cjs +2 -0
- package/pg-core/columns/varchar.cjs.map +1 -1
- package/pg-core/columns/varchar.js +2 -0
- package/pg-core/columns/varchar.js.map +1 -1
- package/pg-core/columns/vector_extension/bit.cjs +2 -0
- package/pg-core/columns/vector_extension/bit.cjs.map +1 -1
- package/pg-core/columns/vector_extension/bit.js +2 -0
- package/pg-core/columns/vector_extension/bit.js.map +1 -1
- package/pg-core/columns/vector_extension/halfvec.cjs +6 -4
- package/pg-core/columns/vector_extension/halfvec.cjs.map +1 -1
- package/pg-core/columns/vector_extension/halfvec.d.cts +2 -2
- package/pg-core/columns/vector_extension/halfvec.d.ts +2 -2
- package/pg-core/columns/vector_extension/halfvec.js +6 -4
- package/pg-core/columns/vector_extension/halfvec.js.map +1 -1
- package/pg-core/columns/vector_extension/sparsevec.cjs +2 -0
- package/pg-core/columns/vector_extension/sparsevec.cjs.map +1 -1
- package/pg-core/columns/vector_extension/sparsevec.js +2 -0
- package/pg-core/columns/vector_extension/sparsevec.js.map +1 -1
- package/pg-core/columns/vector_extension/vector.cjs +6 -4
- package/pg-core/columns/vector_extension/vector.cjs.map +1 -1
- package/pg-core/columns/vector_extension/vector.d.cts +2 -2
- package/pg-core/columns/vector_extension/vector.d.ts +2 -2
- package/pg-core/columns/vector_extension/vector.js +6 -4
- package/pg-core/columns/vector_extension/vector.js.map +1 -1
- package/pg-core/dialect.cjs +73 -226
- package/pg-core/dialect.cjs.map +1 -1
- package/pg-core/dialect.d.cts +27 -34
- package/pg-core/dialect.d.ts +27 -34
- package/pg-core/dialect.js +78 -230
- package/pg-core/dialect.js.map +1 -1
- package/pg-core/effect/count.cjs +1 -1
- package/pg-core/effect/count.cjs.map +1 -1
- package/pg-core/effect/count.d.cts +2 -2
- package/pg-core/effect/count.d.ts +2 -2
- package/pg-core/effect/count.js +1 -1
- package/pg-core/effect/count.js.map +1 -1
- package/pg-core/effect/db.cjs +9 -18
- package/pg-core/effect/db.cjs.map +1 -1
- package/pg-core/effect/db.d.cts +7 -11
- package/pg-core/effect/db.d.ts +6 -10
- package/pg-core/effect/db.js +9 -18
- package/pg-core/effect/db.js.map +1 -1
- package/pg-core/effect/delete.cjs +7 -5
- package/pg-core/effect/delete.cjs.map +1 -1
- package/pg-core/effect/delete.d.cts +1 -1
- package/pg-core/effect/delete.d.ts +1 -1
- package/pg-core/effect/delete.js +7 -5
- package/pg-core/effect/delete.js.map +1 -1
- package/pg-core/effect/insert.cjs +7 -5
- package/pg-core/effect/insert.cjs.map +1 -1
- package/pg-core/effect/insert.d.cts +1 -1
- package/pg-core/effect/insert.d.ts +1 -1
- package/pg-core/effect/insert.js +7 -5
- package/pg-core/effect/insert.js.map +1 -1
- package/pg-core/effect/query.cjs +7 -6
- package/pg-core/effect/query.cjs.map +1 -1
- package/pg-core/effect/query.d.cts +1 -1
- package/pg-core/effect/query.d.ts +1 -1
- package/pg-core/effect/query.js +7 -6
- package/pg-core/effect/query.js.map +1 -1
- package/pg-core/effect/refresh-materialized-view.cjs +1 -2
- package/pg-core/effect/refresh-materialized-view.cjs.map +1 -1
- package/pg-core/effect/refresh-materialized-view.d.cts +1 -1
- package/pg-core/effect/refresh-materialized-view.d.ts +1 -1
- package/pg-core/effect/refresh-materialized-view.js +1 -2
- package/pg-core/effect/refresh-materialized-view.js.map +1 -1
- package/pg-core/effect/select.cjs +3 -5
- package/pg-core/effect/select.cjs.map +1 -1
- package/pg-core/effect/select.d.cts +1 -1
- package/pg-core/effect/select.d.ts +1 -1
- package/pg-core/effect/select.js +3 -5
- package/pg-core/effect/select.js.map +1 -1
- package/pg-core/effect/session.cjs +28 -17
- package/pg-core/effect/session.cjs.map +1 -1
- package/pg-core/effect/session.d.cts +24 -28
- package/pg-core/effect/session.d.ts +25 -29
- package/pg-core/effect/session.js +29 -18
- package/pg-core/effect/session.js.map +1 -1
- package/pg-core/effect/update.cjs +8 -8
- package/pg-core/effect/update.cjs.map +1 -1
- package/pg-core/effect/update.d.cts +1 -1
- package/pg-core/effect/update.d.ts +1 -1
- package/pg-core/effect/update.js +8 -8
- package/pg-core/effect/update.js.map +1 -1
- package/pg-core/index.cjs +4 -4
- package/pg-core/index.d.cts +4 -4
- package/pg-core/index.d.ts +4 -4
- package/pg-core/index.js +1 -1
- package/pg-core/query-builders/delete.cjs +6 -2
- package/pg-core/query-builders/delete.cjs.map +1 -1
- package/pg-core/query-builders/delete.d.cts +2 -0
- package/pg-core/query-builders/delete.d.ts +2 -0
- package/pg-core/query-builders/delete.js +6 -2
- package/pg-core/query-builders/delete.js.map +1 -1
- package/pg-core/query-builders/insert.cjs +7 -2
- package/pg-core/query-builders/insert.cjs.map +1 -1
- package/pg-core/query-builders/insert.d.cts +2 -0
- package/pg-core/query-builders/insert.d.ts +2 -0
- package/pg-core/query-builders/insert.js +7 -2
- package/pg-core/query-builders/insert.js.map +1 -1
- package/pg-core/query-builders/query-builder.cjs +2 -1
- package/pg-core/query-builders/query-builder.cjs.map +1 -1
- package/pg-core/query-builders/query-builder.js +2 -1
- package/pg-core/query-builders/query-builder.js.map +1 -1
- package/pg-core/query-builders/query.cjs +0 -1
- package/pg-core/query-builders/query.cjs.map +1 -1
- package/pg-core/query-builders/query.d.cts +2 -1
- package/pg-core/query-builders/query.d.ts +2 -1
- package/pg-core/query-builders/query.js +0 -1
- package/pg-core/query-builders/query.js.map +1 -1
- package/pg-core/query-builders/raw.cjs +0 -4
- package/pg-core/query-builders/raw.cjs.map +1 -1
- package/pg-core/query-builders/raw.js +0 -4
- package/pg-core/query-builders/raw.js.map +1 -1
- package/pg-core/query-builders/select.cjs +6 -2
- package/pg-core/query-builders/select.cjs.map +1 -1
- package/pg-core/query-builders/select.d.cts +1 -0
- package/pg-core/query-builders/select.d.ts +1 -0
- package/pg-core/query-builders/select.js +6 -2
- package/pg-core/query-builders/select.js.map +1 -1
- package/pg-core/query-builders/select.types.d.cts +1 -0
- package/pg-core/query-builders/select.types.d.ts +1 -0
- package/pg-core/query-builders/update.cjs +6 -2
- package/pg-core/query-builders/update.cjs.map +1 -1
- package/pg-core/query-builders/update.d.cts +2 -0
- package/pg-core/query-builders/update.d.ts +2 -0
- package/pg-core/query-builders/update.js +6 -2
- package/pg-core/query-builders/update.js.map +1 -1
- package/pg-core/session.cjs +3 -5
- package/pg-core/session.cjs.map +1 -1
- package/pg-core/session.d.cts +4 -7
- package/pg-core/session.d.ts +4 -7
- package/pg-core/session.js +3 -5
- package/pg-core/session.js.map +1 -1
- package/pg-core/table.cjs +1 -1
- package/pg-core/table.cjs.map +1 -1
- package/pg-core/table.js +1 -1
- package/pg-core/table.js.map +1 -1
- package/pg-core/utils.cjs.map +1 -1
- package/pg-core/utils.d.cts +7 -1
- package/pg-core/utils.d.ts +7 -1
- package/pg-core/utils.js.map +1 -1
- package/pg-core/view.cjs +2 -2
- package/pg-core/view.cjs.map +1 -1
- package/pg-core/view.js +2 -2
- package/pg-core/view.js.map +1 -1
- package/pg-proxy/driver.cjs +10 -15
- package/pg-proxy/driver.cjs.map +1 -1
- package/pg-proxy/driver.d.cts +6 -3
- package/pg-proxy/driver.d.ts +6 -3
- package/pg-proxy/driver.js +10 -14
- package/pg-proxy/driver.js.map +1 -1
- package/pg-proxy/index.cjs +0 -2
- package/pg-proxy/index.d.cts +2 -2
- package/pg-proxy/index.d.ts +2 -2
- package/pg-proxy/index.js +2 -2
- package/pg-proxy/migrator.cjs.map +1 -1
- package/pg-proxy/migrator.d.cts +1 -1
- package/pg-proxy/migrator.d.ts +1 -1
- package/pg-proxy/migrator.js.map +1 -1
- package/pg-proxy/session.cjs +8 -84
- package/pg-proxy/session.cjs.map +1 -1
- package/pg-proxy/session.d.cts +9 -32
- package/pg-proxy/session.d.ts +9 -32
- package/pg-proxy/session.js +10 -84
- package/pg-proxy/session.js.map +1 -1
- package/pglite/driver.cjs +71 -33
- package/pglite/driver.cjs.map +1 -1
- package/pglite/driver.d.cts +12 -17
- package/pglite/driver.d.ts +13 -18
- package/pglite/driver.js +71 -32
- package/pglite/driver.js.map +1 -1
- package/pglite/index.cjs +2 -3
- package/pglite/index.d.cts +3 -3
- package/pglite/index.d.ts +3 -3
- package/pglite/index.js +3 -3
- package/pglite/migrator.cjs.map +1 -1
- package/pglite/migrator.d.cts +1 -1
- package/pglite/migrator.d.ts +1 -1
- package/pglite/migrator.js.map +1 -1
- package/pglite/session.cjs +24 -85
- package/pglite/session.cjs.map +1 -1
- package/pglite/session.d.cts +9 -30
- package/pglite/session.d.ts +9 -30
- package/pglite/session.js +26 -86
- package/pglite/session.js.map +1 -1
- package/planetscale-serverless/driver.cjs +3 -2
- package/planetscale-serverless/driver.cjs.map +1 -1
- package/planetscale-serverless/driver.d.cts +1 -0
- package/planetscale-serverless/driver.d.ts +1 -0
- package/planetscale-serverless/driver.js +3 -2
- package/planetscale-serverless/driver.js.map +1 -1
- package/planetscale-serverless/session.cjs +26 -19
- package/planetscale-serverless/session.cjs.map +1 -1
- package/planetscale-serverless/session.d.cts +12 -6
- package/planetscale-serverless/session.d.ts +13 -7
- package/planetscale-serverless/session.js +27 -20
- package/planetscale-serverless/session.js.map +1 -1
- package/postgres-js/driver.cjs +124 -19
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.d.cts +10 -6
- package/postgres-js/driver.d.ts +10 -6
- package/postgres-js/driver.js +124 -19
- package/postgres-js/driver.js.map +1 -1
- package/postgres-js/index.cjs +2 -2
- package/postgres-js/index.d.cts +3 -3
- package/postgres-js/index.d.ts +3 -3
- package/postgres-js/index.js +3 -3
- package/postgres-js/migrator.cjs.map +1 -1
- package/postgres-js/migrator.d.cts +1 -1
- package/postgres-js/migrator.d.ts +1 -1
- package/postgres-js/migrator.js.map +1 -1
- package/postgres-js/session.cjs +16 -111
- package/postgres-js/session.cjs.map +1 -1
- package/postgres-js/session.d.cts +10 -31
- package/postgres-js/session.d.ts +9 -30
- package/postgres-js/session.js +17 -111
- package/postgres-js/session.js.map +1 -1
- package/prisma/mysql/session.cjs +2 -1
- package/prisma/mysql/session.cjs.map +1 -1
- package/prisma/mysql/session.d.cts +1 -0
- package/prisma/mysql/session.d.ts +2 -1
- package/prisma/mysql/session.js +2 -1
- package/prisma/mysql/session.js.map +1 -1
- package/prisma/pg/driver.cjs +9 -3
- package/prisma/pg/driver.cjs.map +1 -1
- package/prisma/pg/driver.d.cts +7 -3
- package/prisma/pg/driver.d.ts +7 -3
- package/prisma/pg/driver.js +9 -4
- package/prisma/pg/driver.js.map +1 -1
- package/prisma/pg/index.cjs +2 -2
- package/prisma/pg/index.d.cts +3 -3
- package/prisma/pg/index.d.ts +3 -3
- package/prisma/pg/index.js +3 -3
- package/prisma/pg/session.cjs +1 -25
- package/prisma/pg/session.cjs.map +1 -1
- package/prisma/pg/session.d.cts +3 -15
- package/prisma/pg/session.d.ts +2 -14
- package/prisma/pg/session.js +2 -25
- package/prisma/pg/session.js.map +1 -1
- package/prisma/sqlite/session.cjs +0 -3
- package/prisma/sqlite/session.cjs.map +1 -1
- package/prisma/sqlite/session.d.cts +0 -1
- package/prisma/sqlite/session.d.ts +1 -2
- package/prisma/sqlite/session.js +0 -3
- package/prisma/sqlite/session.js.map +1 -1
- package/query-builders/query-builder.cjs +4 -0
- package/query-builders/query-builder.cjs.map +1 -1
- package/query-builders/query-builder.js +4 -0
- package/query-builders/query-builder.js.map +1 -1
- package/relations.cjs +84 -23
- package/relations.cjs.map +1 -1
- package/relations.d.cts +41 -16
- package/relations.d.ts +41 -16
- package/relations.js +83 -24
- package/relations.js.map +1 -1
- package/row-mappers/index.cjs +1 -1
- package/row-mappers/index.cjs.map +1 -1
- package/row-mappers/index.js +1 -1
- package/row-mappers/index.js.map +1 -1
- package/singlestore/driver.cjs +4 -2
- package/singlestore/driver.cjs.map +1 -1
- package/singlestore/driver.d.cts +2 -1
- package/singlestore/driver.d.ts +3 -2
- package/singlestore/driver.js +4 -2
- package/singlestore/driver.js.map +1 -1
- package/singlestore/session.cjs +16 -6
- package/singlestore/session.cjs.map +1 -1
- package/singlestore/session.d.cts +8 -4
- package/singlestore/session.d.ts +8 -4
- package/singlestore/session.js +17 -7
- package/singlestore/session.js.map +1 -1
- package/singlestore-core/columns/bigint.cjs +4 -4
- package/singlestore-core/columns/bigint.cjs.map +1 -1
- package/singlestore-core/columns/bigint.d.cts +2 -2
- package/singlestore-core/columns/bigint.d.ts +2 -2
- package/singlestore-core/columns/bigint.js +4 -4
- package/singlestore-core/columns/bigint.js.map +1 -1
- package/singlestore-core/columns/binary.cjs +2 -2
- package/singlestore-core/columns/binary.cjs.map +1 -1
- package/singlestore-core/columns/binary.d.cts +1 -1
- package/singlestore-core/columns/binary.d.ts +1 -1
- package/singlestore-core/columns/binary.js +2 -2
- package/singlestore-core/columns/binary.js.map +1 -1
- package/singlestore-core/columns/boolean.cjs +2 -2
- package/singlestore-core/columns/boolean.cjs.map +1 -1
- package/singlestore-core/columns/boolean.d.cts +1 -1
- package/singlestore-core/columns/boolean.d.ts +1 -1
- package/singlestore-core/columns/boolean.js +2 -2
- package/singlestore-core/columns/boolean.js.map +1 -1
- package/singlestore-core/columns/custom.cjs +4 -4
- package/singlestore-core/columns/custom.cjs.map +1 -1
- package/singlestore-core/columns/custom.d.cts +2 -2
- package/singlestore-core/columns/custom.d.ts +2 -2
- package/singlestore-core/columns/custom.js +4 -4
- package/singlestore-core/columns/custom.js.map +1 -1
- package/singlestore-core/columns/date.cjs +2 -2
- package/singlestore-core/columns/date.cjs.map +1 -1
- package/singlestore-core/columns/date.d.cts +1 -1
- package/singlestore-core/columns/date.d.ts +1 -1
- package/singlestore-core/columns/date.js +2 -2
- package/singlestore-core/columns/date.js.map +1 -1
- package/singlestore-core/columns/datetime.cjs +6 -6
- package/singlestore-core/columns/datetime.cjs.map +1 -1
- package/singlestore-core/columns/datetime.d.cts +3 -3
- package/singlestore-core/columns/datetime.d.ts +3 -3
- package/singlestore-core/columns/datetime.js +6 -6
- package/singlestore-core/columns/datetime.js.map +1 -1
- package/singlestore-core/columns/decimal.cjs +4 -4
- package/singlestore-core/columns/decimal.cjs.map +1 -1
- package/singlestore-core/columns/decimal.d.cts +2 -2
- package/singlestore-core/columns/decimal.d.ts +2 -2
- package/singlestore-core/columns/decimal.js +4 -4
- package/singlestore-core/columns/decimal.js.map +1 -1
- package/singlestore-core/columns/float.cjs +2 -2
- package/singlestore-core/columns/float.cjs.map +1 -1
- package/singlestore-core/columns/float.d.cts +1 -1
- package/singlestore-core/columns/float.d.ts +1 -1
- package/singlestore-core/columns/float.js +2 -2
- package/singlestore-core/columns/float.js.map +1 -1
- package/singlestore-core/columns/int.cjs +2 -2
- package/singlestore-core/columns/int.cjs.map +1 -1
- package/singlestore-core/columns/int.d.cts +1 -1
- package/singlestore-core/columns/int.d.ts +1 -1
- package/singlestore-core/columns/int.js +2 -2
- package/singlestore-core/columns/int.js.map +1 -1
- package/singlestore-core/columns/json.cjs +2 -2
- package/singlestore-core/columns/json.cjs.map +1 -1
- package/singlestore-core/columns/json.d.cts +1 -1
- package/singlestore-core/columns/json.d.ts +1 -1
- package/singlestore-core/columns/json.js +2 -2
- package/singlestore-core/columns/json.js.map +1 -1
- package/singlestore-core/columns/mediumint.cjs +2 -2
- package/singlestore-core/columns/mediumint.cjs.map +1 -1
- package/singlestore-core/columns/mediumint.d.cts +1 -1
- package/singlestore-core/columns/mediumint.d.ts +1 -1
- package/singlestore-core/columns/mediumint.js +2 -2
- package/singlestore-core/columns/mediumint.js.map +1 -1
- package/singlestore-core/columns/serial.cjs +2 -2
- package/singlestore-core/columns/serial.cjs.map +1 -1
- package/singlestore-core/columns/serial.d.cts +1 -1
- package/singlestore-core/columns/serial.d.ts +1 -1
- package/singlestore-core/columns/serial.js +2 -2
- package/singlestore-core/columns/serial.js.map +1 -1
- package/singlestore-core/columns/smallint.cjs +2 -2
- package/singlestore-core/columns/smallint.cjs.map +1 -1
- package/singlestore-core/columns/smallint.d.cts +1 -1
- package/singlestore-core/columns/smallint.d.ts +1 -1
- package/singlestore-core/columns/smallint.js +2 -2
- package/singlestore-core/columns/smallint.js.map +1 -1
- package/singlestore-core/columns/timestamp.cjs +6 -6
- package/singlestore-core/columns/timestamp.cjs.map +1 -1
- package/singlestore-core/columns/timestamp.d.cts +3 -3
- package/singlestore-core/columns/timestamp.d.ts +3 -3
- package/singlestore-core/columns/timestamp.js +6 -6
- package/singlestore-core/columns/timestamp.js.map +1 -1
- package/singlestore-core/columns/tinyint.cjs +2 -2
- package/singlestore-core/columns/tinyint.cjs.map +1 -1
- package/singlestore-core/columns/tinyint.d.cts +1 -1
- package/singlestore-core/columns/tinyint.d.ts +1 -1
- package/singlestore-core/columns/tinyint.js +2 -2
- package/singlestore-core/columns/tinyint.js.map +1 -1
- package/singlestore-core/columns/varbinary.cjs +2 -2
- package/singlestore-core/columns/varbinary.cjs.map +1 -1
- package/singlestore-core/columns/varbinary.d.cts +1 -1
- package/singlestore-core/columns/varbinary.d.ts +1 -1
- package/singlestore-core/columns/varbinary.js +2 -2
- package/singlestore-core/columns/varbinary.js.map +1 -1
- package/singlestore-core/columns/vector.cjs +8 -8
- package/singlestore-core/columns/vector.cjs.map +1 -1
- package/singlestore-core/columns/vector.d.cts +4 -4
- package/singlestore-core/columns/vector.d.ts +4 -4
- package/singlestore-core/columns/vector.js +8 -8
- package/singlestore-core/columns/vector.js.map +1 -1
- package/singlestore-core/columns/year.cjs +2 -2
- package/singlestore-core/columns/year.cjs.map +1 -1
- package/singlestore-core/columns/year.d.cts +1 -1
- package/singlestore-core/columns/year.d.ts +1 -1
- package/singlestore-core/columns/year.js +2 -2
- package/singlestore-core/columns/year.js.map +1 -1
- package/singlestore-core/db.d.ts +1 -1
- package/singlestore-core/dialect.cjs +1 -1
- package/singlestore-core/dialect.d.ts +1 -1
- package/singlestore-core/dialect.js +1 -1
- package/singlestore-core/query-builders/query.cjs +13 -5
- package/singlestore-core/query-builders/query.cjs.map +1 -1
- package/singlestore-core/query-builders/query.d.ts +1 -1
- package/singlestore-core/query-builders/query.js +13 -5
- package/singlestore-core/query-builders/query.js.map +1 -1
- package/singlestore-core/query-builders/select.cjs +4 -0
- package/singlestore-core/query-builders/select.cjs.map +1 -1
- package/singlestore-core/query-builders/select.js +4 -0
- package/singlestore-core/query-builders/select.js.map +1 -1
- package/singlestore-core/session.cjs.map +1 -1
- package/singlestore-core/session.d.cts +2 -2
- package/singlestore-core/session.d.ts +2 -2
- package/singlestore-core/session.js.map +1 -1
- package/singlestore-core/table.cjs +1 -1
- package/singlestore-core/table.cjs.map +1 -1
- package/singlestore-core/table.js +1 -1
- package/singlestore-core/table.js.map +1 -1
- package/singlestore-proxy/driver.cjs +5 -2
- package/singlestore-proxy/driver.cjs.map +1 -1
- package/singlestore-proxy/driver.js +5 -2
- package/singlestore-proxy/driver.js.map +1 -1
- package/singlestore-proxy/session.cjs +11 -6
- package/singlestore-proxy/session.cjs.map +1 -1
- package/singlestore-proxy/session.d.cts +9 -4
- package/singlestore-proxy/session.d.ts +9 -4
- package/singlestore-proxy/session.js +12 -7
- package/singlestore-proxy/session.js.map +1 -1
- package/sql/index.cjs +1 -0
- package/sql/index.d.cts +2 -2
- package/sql/index.d.ts +2 -2
- package/sql/index.js +2 -2
- package/sql/sql.cjs +32 -11
- package/sql/sql.cjs.map +1 -1
- package/sql/sql.d.cts +15 -5
- package/sql/sql.d.ts +15 -5
- package/sql/sql.js +32 -12
- package/sql/sql.js.map +1 -1
- package/sql-js/driver.cjs +5 -2
- package/sql-js/driver.cjs.map +1 -1
- package/sql-js/driver.d.ts +1 -1
- package/sql-js/driver.js +5 -2
- package/sql-js/driver.js.map +1 -1
- package/sql-js/session.cjs +14 -14
- package/sql-js/session.cjs.map +1 -1
- package/sql-js/session.d.cts +10 -6
- package/sql-js/session.d.ts +10 -6
- package/sql-js/session.js +15 -15
- package/sql-js/session.js.map +1 -1
- package/sqlite-cloud/driver.cjs +3 -2
- package/sqlite-cloud/driver.cjs.map +1 -1
- package/sqlite-cloud/driver.d.ts +1 -1
- package/sqlite-cloud/driver.js +3 -2
- package/sqlite-cloud/driver.js.map +1 -1
- package/sqlite-cloud/session.cjs +20 -19
- package/sqlite-cloud/session.cjs.map +1 -1
- package/sqlite-cloud/session.d.cts +9 -6
- package/sqlite-cloud/session.d.ts +9 -6
- package/sqlite-cloud/session.js +21 -20
- package/sqlite-cloud/session.js.map +1 -1
- package/sqlite-core/columns/blob.cjs +10 -10
- package/sqlite-core/columns/blob.cjs.map +1 -1
- package/sqlite-core/columns/blob.d.cts +5 -5
- package/sqlite-core/columns/blob.d.ts +5 -5
- package/sqlite-core/columns/blob.js +10 -10
- package/sqlite-core/columns/blob.js.map +1 -1
- package/sqlite-core/columns/custom.cjs +4 -4
- package/sqlite-core/columns/custom.cjs.map +1 -1
- package/sqlite-core/columns/custom.d.cts +2 -2
- package/sqlite-core/columns/custom.d.ts +2 -2
- package/sqlite-core/columns/custom.js +4 -4
- package/sqlite-core/columns/custom.js.map +1 -1
- package/sqlite-core/columns/integer.cjs +8 -8
- package/sqlite-core/columns/integer.cjs.map +1 -1
- package/sqlite-core/columns/integer.d.cts +4 -4
- package/sqlite-core/columns/integer.d.ts +4 -4
- package/sqlite-core/columns/integer.js +8 -8
- package/sqlite-core/columns/integer.js.map +1 -1
- package/sqlite-core/columns/numeric.cjs +4 -4
- package/sqlite-core/columns/numeric.cjs.map +1 -1
- package/sqlite-core/columns/numeric.d.cts +2 -2
- package/sqlite-core/columns/numeric.d.ts +2 -2
- package/sqlite-core/columns/numeric.js +4 -4
- package/sqlite-core/columns/numeric.js.map +1 -1
- package/sqlite-core/columns/text.cjs +4 -4
- package/sqlite-core/columns/text.cjs.map +1 -1
- package/sqlite-core/columns/text.d.cts +2 -2
- package/sqlite-core/columns/text.d.ts +2 -2
- package/sqlite-core/columns/text.js +4 -4
- package/sqlite-core/columns/text.js.map +1 -1
- package/sqlite-core/db.d.ts +1 -1
- package/sqlite-core/dialect.cjs +2 -2
- package/sqlite-core/dialect.d.ts +1 -1
- package/sqlite-core/dialect.js +2 -2
- package/sqlite-core/query-builders/_query.cjs +1 -1
- package/sqlite-core/query-builders/_query.cjs.map +1 -1
- package/sqlite-core/query-builders/_query.js +1 -1
- package/sqlite-core/query-builders/_query.js.map +1 -1
- package/sqlite-core/query-builders/delete.cjs +1 -1
- package/sqlite-core/query-builders/delete.cjs.map +1 -1
- package/sqlite-core/query-builders/delete.js +1 -1
- package/sqlite-core/query-builders/delete.js.map +1 -1
- package/sqlite-core/query-builders/insert.cjs +1 -1
- package/sqlite-core/query-builders/insert.cjs.map +1 -1
- package/sqlite-core/query-builders/insert.js +1 -1
- package/sqlite-core/query-builders/insert.js.map +1 -1
- package/sqlite-core/query-builders/query.cjs +13 -5
- package/sqlite-core/query-builders/query.cjs.map +1 -1
- package/sqlite-core/query-builders/query.d.ts +1 -1
- package/sqlite-core/query-builders/query.js +13 -5
- package/sqlite-core/query-builders/query.js.map +1 -1
- package/sqlite-core/query-builders/raw.cjs +0 -4
- package/sqlite-core/query-builders/raw.cjs.map +1 -1
- package/sqlite-core/query-builders/raw.js +0 -4
- package/sqlite-core/query-builders/raw.js.map +1 -1
- package/sqlite-core/query-builders/select.cjs +5 -1
- package/sqlite-core/query-builders/select.cjs.map +1 -1
- package/sqlite-core/query-builders/select.js +5 -1
- package/sqlite-core/query-builders/select.js.map +1 -1
- package/sqlite-core/query-builders/update.cjs +1 -1
- package/sqlite-core/query-builders/update.cjs.map +1 -1
- package/sqlite-core/query-builders/update.js +1 -1
- package/sqlite-core/query-builders/update.js.map +1 -1
- package/sqlite-core/session.cjs +8 -8
- package/sqlite-core/session.cjs.map +1 -1
- package/sqlite-core/session.d.cts +5 -5
- package/sqlite-core/session.d.ts +5 -5
- package/sqlite-core/session.js +8 -8
- package/sqlite-core/session.js.map +1 -1
- package/sqlite-core/table.cjs +1 -1
- package/sqlite-core/table.cjs.map +1 -1
- package/sqlite-core/table.js +1 -1
- package/sqlite-core/table.js.map +1 -1
- package/sqlite-proxy/driver.cjs +3 -2
- package/sqlite-proxy/driver.cjs.map +1 -1
- package/sqlite-proxy/driver.d.ts +1 -1
- package/sqlite-proxy/driver.js +3 -2
- package/sqlite-proxy/driver.js.map +1 -1
- package/sqlite-proxy/session.cjs +19 -16
- package/sqlite-proxy/session.cjs.map +1 -1
- package/sqlite-proxy/session.d.cts +11 -7
- package/sqlite-proxy/session.d.ts +11 -7
- package/sqlite-proxy/session.js +20 -17
- package/sqlite-proxy/session.js.map +1 -1
- package/table.d.cts +1 -1
- package/table.d.ts +1 -1
- package/tidb-serverless/driver.cjs +3 -2
- package/tidb-serverless/driver.cjs.map +1 -1
- package/tidb-serverless/driver.d.cts +1 -0
- package/tidb-serverless/driver.d.ts +1 -0
- package/tidb-serverless/driver.js +3 -2
- package/tidb-serverless/driver.js.map +1 -1
- package/tidb-serverless/session.cjs +24 -36
- package/tidb-serverless/session.cjs.map +1 -1
- package/tidb-serverless/session.d.cts +10 -4
- package/tidb-serverless/session.d.ts +11 -5
- package/tidb-serverless/session.js +25 -37
- package/tidb-serverless/session.js.map +1 -1
- package/tursodatabase/driver-core.cjs +3 -2
- package/tursodatabase/driver-core.cjs.map +1 -1
- package/tursodatabase/driver-core.d.ts +1 -1
- package/tursodatabase/driver-core.js +3 -2
- package/tursodatabase/driver-core.js.map +1 -1
- package/tursodatabase/session.cjs +19 -18
- package/tursodatabase/session.cjs.map +1 -1
- package/tursodatabase/session.d.cts +9 -6
- package/tursodatabase/session.d.ts +9 -6
- package/tursodatabase/session.js +20 -19
- package/tursodatabase/session.js.map +1 -1
- package/up-migrations/effect-pg.cjs +3 -3
- package/up-migrations/effect-pg.cjs.map +1 -1
- package/up-migrations/effect-pg.js +3 -3
- package/up-migrations/effect-pg.js.map +1 -1
- package/up-migrations/pg.cjs +3 -8
- package/up-migrations/pg.cjs.map +1 -1
- package/up-migrations/pg.d.cts +1 -1
- package/up-migrations/pg.d.ts +1 -1
- package/up-migrations/pg.js +3 -8
- package/up-migrations/pg.js.map +1 -1
- package/up-migrations/sqlite.d.ts +2 -2
- package/utils.cjs +128 -6
- package/utils.cjs.map +1 -1
- package/utils.d.cts +10 -3
- package/utils.d.ts +10 -3
- package/utils.js +126 -7
- package/utils.js.map +1 -1
- package/vercel-postgres/driver.cjs +14 -32
- package/vercel-postgres/driver.cjs.map +1 -1
- package/vercel-postgres/driver.d.cts +12 -17
- package/vercel-postgres/driver.d.ts +13 -18
- package/vercel-postgres/driver.js +14 -31
- package/vercel-postgres/driver.js.map +1 -1
- package/vercel-postgres/index.cjs +2 -3
- package/vercel-postgres/index.d.cts +3 -3
- package/vercel-postgres/index.d.ts +3 -3
- package/vercel-postgres/index.js +3 -3
- package/vercel-postgres/migrator.cjs.map +1 -1
- package/vercel-postgres/migrator.d.cts +1 -1
- package/vercel-postgres/migrator.d.ts +1 -1
- package/vercel-postgres/migrator.js.map +1 -1
- package/vercel-postgres/session.cjs +32 -110
- package/vercel-postgres/session.cjs.map +1 -1
- package/vercel-postgres/session.d.cts +9 -32
- package/vercel-postgres/session.d.ts +9 -32
- package/vercel-postgres/session.js +34 -111
- package/vercel-postgres/session.js.map +1 -1
- package/xata-http/driver.cjs +91 -31
- package/xata-http/driver.cjs.map +1 -1
- package/xata-http/driver.d.cts +10 -16
- package/xata-http/driver.d.ts +11 -17
- package/xata-http/driver.js +91 -30
- package/xata-http/driver.js.map +1 -1
- package/xata-http/index.cjs +2 -4
- package/xata-http/index.d.cts +3 -3
- package/xata-http/index.d.ts +3 -3
- package/xata-http/index.js +3 -3
- package/xata-http/migrator.cjs +1 -1
- package/xata-http/migrator.cjs.map +1 -1
- package/xata-http/migrator.d.cts +1 -1
- package/xata-http/migrator.d.ts +1 -1
- package/xata-http/migrator.js +1 -1
- package/xata-http/migrator.js.map +1 -1
- package/xata-http/session.cjs +23 -109
- package/xata-http/session.cjs.map +1 -1
- package/xata-http/session.d.cts +7 -33
- package/xata-http/session.d.ts +6 -32
- package/xata-http/session.js +25 -109
- package/xata-http/session.js.map +1 -1
- package/pg-core/query-builders/_query.cjs +0 -101
- package/pg-core/query-builders/_query.cjs.map +0 -1
- package/pg-core/query-builders/_query.d.cts +0 -55
- package/pg-core/query-builders/_query.d.ts +0 -55
- package/pg-core/query-builders/_query.js +0 -97
- package/pg-core/query-builders/_query.js.map +0 -1
- package/pg-core/utils/array.cjs.map +0 -1
- package/pg-core/utils/array.js.map +0 -1
- package/pg-core/utils/index.cjs +0 -6
- package/pg-core/utils/index.d.cts +0 -2
- package/pg-core/utils/index.d.ts +0 -2
- package/pg-core/utils/index.js +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-pg.cjs","names":["Effect","sql"],"sources":["../../src/up-migrations/effect-pg.ts"],"sourcesContent":["import { Effect } from 'effect';\nimport type { QueryEffectHKTBase } from '~/effect-core/query-effect.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { PgEffectSession } from '~/pg-core/effect/session.ts';\nimport { sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) => Effect.Effect<void, TEffectHKT['error'], TEffectHKT['context']>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: (migrationsSchema, migrationsTable, session, localMigrations) => {\n\t\treturn Effect.gen(function*() {\n\t\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t\t// 1. Read all existing DB migrations\n\t\t\t// Sort them by ids asc (order how they were applied)\n\t\t\tconst dbRows = yield* session.
|
|
1
|
+
{"version":3,"file":"effect-pg.cjs","names":["Effect","sql"],"sources":["../../src/up-migrations/effect-pg.ts"],"sourcesContent":["import { Effect } from 'effect';\nimport type { QueryEffectHKTBase } from '~/effect-core/query-effect.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { PgEffectSession } from '~/pg-core/effect/session.ts';\nimport { sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) => Effect.Effect<void, TEffectHKT['error'], TEffectHKT['context']>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: (migrationsSchema, migrationsTable, session, localMigrations) => {\n\t\treturn Effect.gen(function*() {\n\t\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t\t// 1. Read all existing DB migrations\n\t\t\t// Sort them by ids asc (order how they were applied)\n\t\t\tconst dbRows = yield* session.objects<{ id: number; hash: string; created_at: string }>(\n\t\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t\t);\n\n\t\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\t\tlocalMigrations.sort((a, b) =>\n\t\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t\t);\n\n\t\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\t\tfor (const lm of localMigrations) {\n\t\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t\t}\n\t\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\t\tbyHash.set(lm.hash, lm);\n\t\t\t}\n\n\t\t\t// 3. Match each DB row to a local migration\n\t\t\t// Priority: millis -> hash\n\t\t\tconst toApply: { id: number; name: string }[] = [];\n\t\t\tlet unmatchedIds: number[] = [];\n\n\t\t\tfor (const dbRow of dbRows) {\n\t\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\t\tmatched = candidates[0];\n\t\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t\t} else {\n\t\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t\t}\n\n\t\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t\t}\n\n\t\t\t// 4. Check for unmatched\n\t\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\t\tif (unmatchedIds.length > 0) {\n\t\t\t\tthrow Error(\n\t\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// 5. Create extra column and backfill names for matched migrations\n\t\t\tyield* session.transaction((tx) =>\n\t\t\t\tEffect.gen(function*() {\n\t\t\t\t\tyield* tx.execute(sql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`);\n\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t\t\t\t);\n\n\t\t\t\t\tfor (const backfillEntry of toApply) {\n\t\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${backfillEntry.name}, ${\n\t\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t\t} = NULL WHERE ${sql.identifier('id')} = ${backfillEntry.id}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport const upgradeIfNeeded: <TEffectHKT extends QueryEffectHKTBase>(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tsession: PgEffectSession<TEffectHKT>,\n\tlocalMigrations: MigrationMeta[],\n) => Effect.Effect<UpgradeResult, TEffectHKT['error'], TEffectHKT['context']> = Effect.fn('upgradeIfNeeded')(\n\tfunction*<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) {\n\t\t// Check if the table exists at all\n\t\tconst result = yield* session.objects(\n\t\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t\t);\n\n\t\tif (result.length === 0) {\n\t\t\treturn { newDb: true };\n\t\t}\n\n\t\t// Table exists, check table shape\n\t\tconst rows = yield* session.objects<{ schema: string; table_name: string; column_name: string; type: string }>(\n\t\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t\t);\n\n\t\tconst version = getVersion(rows.map((r) => r.column_name));\n\n\t\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\t\tconst upgradeFn = upgradeFunctions[v];\n\t\t\tif (!upgradeFn) {\n\t\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t\t}\n\t\t\tyield* upgradeFn(migrationsSchema, migrationsTable, session, localMigrations);\n\t\t}\n\n\t\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n\t},\n);\n"],"mappings":"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"}
|
|
@@ -14,7 +14,7 @@ function getVersion(columns) {
|
|
|
14
14
|
const upgradeFunctions = { 0: (migrationsSchema, migrationsTable, session, localMigrations) => {
|
|
15
15
|
return Effect.gen(function* () {
|
|
16
16
|
const table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;
|
|
17
|
-
const dbRows = yield* session.
|
|
17
|
+
const dbRows = yield* session.objects(sql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`);
|
|
18
18
|
localMigrations.sort((a, b) => a.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? "").localeCompare(b.name ?? ""));
|
|
19
19
|
const byMillis = /* @__PURE__ */ new Map();
|
|
20
20
|
const byHash = /* @__PURE__ */ new Map();
|
|
@@ -54,10 +54,10 @@ const upgradeFunctions = { 0: (migrationsSchema, migrationsTable, session, local
|
|
|
54
54
|
* Version 1: Extended schema (id, hash, created_at, name, applied_at)
|
|
55
55
|
*/
|
|
56
56
|
const upgradeIfNeeded = Effect.fn("upgradeIfNeeded")(function* (migrationsSchema, migrationsTable, session, localMigrations) {
|
|
57
|
-
if ((yield* session.
|
|
57
|
+
if ((yield* session.objects(sql`SELECT 1 FROM information_schema.tables
|
|
58
58
|
WHERE table_schema = ${migrationsSchema}
|
|
59
59
|
AND table_name = ${migrationsTable}`)).length === 0) return { newDb: true };
|
|
60
|
-
const version = getVersion((yield* session.
|
|
60
|
+
const version = getVersion((yield* session.objects(sql`SELECT
|
|
61
61
|
n.nspname AS "schema",
|
|
62
62
|
c.relname AS "table_name",
|
|
63
63
|
a.attname AS "column_name",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-pg.js","names":[],"sources":["../../src/up-migrations/effect-pg.ts"],"sourcesContent":["import { Effect } from 'effect';\nimport type { QueryEffectHKTBase } from '~/effect-core/query-effect.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { PgEffectSession } from '~/pg-core/effect/session.ts';\nimport { sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) => Effect.Effect<void, TEffectHKT['error'], TEffectHKT['context']>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: (migrationsSchema, migrationsTable, session, localMigrations) => {\n\t\treturn Effect.gen(function*() {\n\t\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t\t// 1. Read all existing DB migrations\n\t\t\t// Sort them by ids asc (order how they were applied)\n\t\t\tconst dbRows = yield* session.
|
|
1
|
+
{"version":3,"file":"effect-pg.js","names":[],"sources":["../../src/up-migrations/effect-pg.ts"],"sourcesContent":["import { Effect } from 'effect';\nimport type { QueryEffectHKTBase } from '~/effect-core/query-effect.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { PgEffectSession } from '~/pg-core/effect/session.ts';\nimport { sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) => Effect.Effect<void, TEffectHKT['error'], TEffectHKT['context']>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: (migrationsSchema, migrationsTable, session, localMigrations) => {\n\t\treturn Effect.gen(function*() {\n\t\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t\t// 1. Read all existing DB migrations\n\t\t\t// Sort them by ids asc (order how they were applied)\n\t\t\tconst dbRows = yield* session.objects<{ id: number; hash: string; created_at: string }>(\n\t\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t\t);\n\n\t\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\t\tlocalMigrations.sort((a, b) =>\n\t\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t\t);\n\n\t\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\t\tfor (const lm of localMigrations) {\n\t\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t\t}\n\t\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\t\tbyHash.set(lm.hash, lm);\n\t\t\t}\n\n\t\t\t// 3. Match each DB row to a local migration\n\t\t\t// Priority: millis -> hash\n\t\t\tconst toApply: { id: number; name: string }[] = [];\n\t\t\tlet unmatchedIds: number[] = [];\n\n\t\t\tfor (const dbRow of dbRows) {\n\t\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\t\tmatched = candidates[0];\n\t\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t\t} else {\n\t\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t\t}\n\n\t\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t\t}\n\n\t\t\t// 4. Check for unmatched\n\t\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\t\tif (unmatchedIds.length > 0) {\n\t\t\t\tthrow Error(\n\t\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// 5. Create extra column and backfill names for matched migrations\n\t\t\tyield* session.transaction((tx) =>\n\t\t\t\tEffect.gen(function*() {\n\t\t\t\t\tyield* tx.execute(sql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`);\n\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t\t\t\t);\n\n\t\t\t\t\tfor (const backfillEntry of toApply) {\n\t\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${backfillEntry.name}, ${\n\t\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t\t} = NULL WHERE ${sql.identifier('id')} = ${backfillEntry.id}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport const upgradeIfNeeded: <TEffectHKT extends QueryEffectHKTBase>(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tsession: PgEffectSession<TEffectHKT>,\n\tlocalMigrations: MigrationMeta[],\n) => Effect.Effect<UpgradeResult, TEffectHKT['error'], TEffectHKT['context']> = Effect.fn('upgradeIfNeeded')(\n\tfunction*<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) {\n\t\t// Check if the table exists at all\n\t\tconst result = yield* session.objects(\n\t\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t\t);\n\n\t\tif (result.length === 0) {\n\t\t\treturn { newDb: true };\n\t\t}\n\n\t\t// Table exists, check table shape\n\t\tconst rows = yield* session.objects<{ schema: string; table_name: string; column_name: string; type: string }>(\n\t\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t\t);\n\n\t\tconst version = getVersion(rows.map((r) => r.column_name));\n\n\t\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\t\tconst upgradeFn = upgradeFunctions[v];\n\t\t\tif (!upgradeFn) {\n\t\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t\t}\n\t\t\tyield* upgradeFn(migrationsSchema, migrationsTable, session, localMigrations);\n\t\t}\n\n\t\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n\t},\n);\n"],"mappings":"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"}
|
package/up-migrations/pg.cjs
CHANGED
|
@@ -8,18 +8,13 @@ function getVersion(columns) {
|
|
|
8
8
|
if (columns.includes("name")) return 1;
|
|
9
9
|
return 0;
|
|
10
10
|
}
|
|
11
|
-
async function execute(session, sql) {
|
|
12
|
-
const result = await session.execute(sql);
|
|
13
|
-
if ("rows" in result) return result.rows;
|
|
14
|
-
return result;
|
|
15
|
-
}
|
|
16
11
|
/**
|
|
17
12
|
* Map of upgrade functions. Each key is the version being upgraded FROM,
|
|
18
13
|
* and the function upgrades the table to the next version.
|
|
19
14
|
*/
|
|
20
15
|
const upgradeFunctions = { 0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {
|
|
21
16
|
const table = __sql_sql_ts.sql`${__sql_sql_ts.sql.identifier(migrationsSchema)}.${__sql_sql_ts.sql.identifier(migrationsTable)}`;
|
|
22
|
-
const dbRows = await
|
|
17
|
+
const dbRows = await db.session.objects(__sql_sql_ts.sql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`);
|
|
23
18
|
localMigrations.sort((a, b) => a.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? "").localeCompare(b.name ?? ""));
|
|
24
19
|
const byMillis = /* @__PURE__ */ new Map();
|
|
25
20
|
const byHash = /* @__PURE__ */ new Map();
|
|
@@ -62,10 +57,10 @@ const upgradeFunctions = { 0: async (migrationsSchema, migrationsTable, db, loca
|
|
|
62
57
|
* Version 1: Extended schema (id, hash, created_at, name, applied_at)
|
|
63
58
|
*/
|
|
64
59
|
async function upgradeIfNeeded(migrationsSchema, migrationsTable, db, localMigrations, mode = "transaction") {
|
|
65
|
-
if ((await
|
|
60
|
+
if ((await db.session.objects(__sql_sql_ts.sql`SELECT 1 FROM information_schema.tables
|
|
66
61
|
WHERE table_schema = ${migrationsSchema}
|
|
67
62
|
AND table_name = ${migrationsTable}`)).length === 0) return { newDb: true };
|
|
68
|
-
let version = getVersion((await
|
|
63
|
+
let version = getVersion((await db.session.objects(__sql_sql_ts.sql`SELECT
|
|
69
64
|
n.nspname AS "schema",
|
|
70
65
|
c.relname AS "table_name",
|
|
71
66
|
a.attname AS "column_name",
|
package/up-migrations/pg.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg.cjs","names":["sql"],"sources":["../../src/up-migrations/pg.ts"],"sourcesContent":["import type { TablesRelationalConfig } from '~/_relations.ts';\nimport type { BatchItem } from '~/batch.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { NeonHttpDatabase } from '~/neon-http/driver.ts';\nimport type { NeonHttpSession } from '~/neon-http/session.ts';\nimport type { PgAsyncDatabase } from '~/pg-core/async/db.ts';\nimport type { PgAsyncSession, PgAsyncTransaction } from '~/pg-core/async/session.ts';\nimport type { PgQueryResultHKT } from '~/pg-core/session.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport { type SQL, sql } from '~/sql/sql.ts';\nimport type { XataHttpSession } from '~/xata-http/session.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n// postgres.js returns array of objects\n// pg-proxy returns arrays of objects\n// node-postgres returns { rows: array of objects }\nasync function execute<T extends any[]>(\n\tsession:\n\t\t| PgAsyncSession\n\t\t| NeonHttpSession<Record<string, unknown>, AnyRelations, TablesRelationalConfig>\n\t\t| XataHttpSession<Record<string, unknown>, AnyRelations, TablesRelationalConfig>,\n\tsql: SQL,\n): Promise<T> {\n\tconst result: { rows: T } | T = await session.execute(sql);\n\tif ('rows' in result) return result.rows;\n\treturn result;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tdb: PgAsyncDatabase<PgQueryResultHKT, any, any, any>,\n\t\tlocalMigrations: MigrationMeta[],\n\t\tmode: 'transaction' | 'execute' | 'batch',\n\t) => Promise<void>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {\n\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t// 1. Read all existing DB migrations\n\t\t// Sort them by ids asc (order how they were applied)\n\t\tconst dbRows = await execute<{ id: number; hash: string; created_at: string }[]>(\n\t\t\tdb.session,\n\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t);\n\n\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\tlocalMigrations.sort((a, b) =>\n\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t);\n\n\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\tfor (const lm of localMigrations) {\n\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t}\n\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\tbyHash.set(lm.hash, lm);\n\t\t}\n\n\t\t// \t3. Match each DB row to a local migration\n\t\t// \tPriority: millis -> hash\n\t\tconst toApply: { id: number; name: string }[] = [];\n\t\tlet unmatchedIds: number[] = [];\n\n\t\tfor (const dbRow of dbRows) {\n\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\tmatched = candidates[0];\n\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t} else {\n\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t}\n\n\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t}\n\n\t\t// 4. Check for unmatched\n\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\tif (unmatchedIds.length > 0) {\n\t\t\tthrow Error(\n\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t);\n\t\t}\n\n\t\t// 5. Create extra column and backfill names for matched migrations\n\t\tconst sqls: SQL[] = [\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`,\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\tsql.identifier('applied_at')\n\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t];\n\t\tfor (const { id, name } of toApply) {\n\t\t\tsqls.push(\n\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${name}, ${sql.identifier('applied_at')} = NULL WHERE ${\n\t\t\t\t\tsql.identifier('id')\n\t\t\t\t} = ${id}`,\n\t\t\t);\n\t\t}\n\n\t\t// check if http\n\t\t// execute -> proxy, http drivers\n\t\t// transaction -> other\n\t\tif (mode === 'transaction') {\n\t\t\tawait db.transaction(async (tx: PgAsyncTransaction<any, any, any>) => {\n\t\t\t\tfor (const sql of sqls) {\n\t\t\t\t\tawait tx.execute(sql);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (mode === 'batch') {\n\t\t\tconst database = db as NeonHttpDatabase;\n\n\t\t\tawait database.batch(\n\t\t\t\tsqls.map((s) => database.execute(s)) as unknown as [BatchItem<'pg'>, ...BatchItem<'pg'>[]],\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const sql of sqls) {\n\t\t\t\tawait db.execute(sql);\n\t\t\t}\n\t\t}\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport async function upgradeIfNeeded(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tdb: PgAsyncDatabase<PgQueryResultHKT, any, any, any>,\n\tlocalMigrations: MigrationMeta[],\n\tmode: 'transaction' | 'execute' | 'batch' = 'transaction',\n): Promise<UpgradeResult> {\n\t// Check if the table exists at all\n\tconst result = await execute<{ '1': 1 }[]>(\n\t\tdb.session,\n\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t);\n\n\tif (result.length === 0) {\n\t\treturn { newDb: true };\n\t}\n\n\t// Table exists, check table shape\n\tconst rows = await execute<\n\t\t{ schema: string; table_name: string; column_name: string; type: string }[]\n\t>(\n\t\tdb.session,\n\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t);\n\n\tlet version = getVersion(rows.map((r) => r.column_name));\n\n\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\tconst upgradeFn = upgradeFunctions[v];\n\t\tif (!upgradeFn) {\n\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t}\n\t\tawait upgradeFn(migrationsSchema, migrationsTable, db, localMigrations, mode);\n\t}\n\n\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"pg.cjs","names":["sql"],"sources":["../../src/up-migrations/pg.ts"],"sourcesContent":["import type { BatchItem } from '~/batch.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { NeonHttpDatabase } from '~/neon-http/driver.ts';\nimport type { PgAsyncDatabase } from '~/pg-core/async/db.ts';\nimport type { PgAsyncTransaction } from '~/pg-core/async/session.ts';\nimport type { PgQueryResultHKT } from '~/pg-core/session.ts';\nimport { type SQL, sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tdb: PgAsyncDatabase<PgQueryResultHKT, any>,\n\t\tlocalMigrations: MigrationMeta[],\n\t\tmode: 'transaction' | 'execute' | 'batch',\n\t) => Promise<void>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {\n\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t// 1. Read all existing DB migrations\n\t\t// Sort them by ids asc (order how they were applied)\n\t\tconst dbRows = await db.session.objects<{ id: number; hash: string; created_at: string }>(\n\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t);\n\n\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\tlocalMigrations.sort((a, b) =>\n\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t);\n\n\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\tfor (const lm of localMigrations) {\n\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t}\n\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\tbyHash.set(lm.hash, lm);\n\t\t}\n\n\t\t// \t3. Match each DB row to a local migration\n\t\t// \tPriority: millis -> hash\n\t\tconst toApply: { id: number; name: string }[] = [];\n\t\tlet unmatchedIds: number[] = [];\n\n\t\tfor (const dbRow of dbRows) {\n\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\tmatched = candidates[0];\n\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t} else {\n\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t}\n\n\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t}\n\n\t\t// 4. Check for unmatched\n\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\tif (unmatchedIds.length > 0) {\n\t\t\tthrow Error(\n\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t);\n\t\t}\n\n\t\t// 5. Create extra column and backfill names for matched migrations\n\t\tconst sqls: SQL[] = [\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`,\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\tsql.identifier('applied_at')\n\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t];\n\t\tfor (const { id, name } of toApply) {\n\t\t\tsqls.push(\n\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${name}, ${sql.identifier('applied_at')} = NULL WHERE ${\n\t\t\t\t\tsql.identifier('id')\n\t\t\t\t} = ${id}`,\n\t\t\t);\n\t\t}\n\n\t\t// check if http\n\t\t// execute -> proxy, http drivers\n\t\t// transaction -> other\n\t\tif (mode === 'transaction') {\n\t\t\tawait db.transaction(async (tx: PgAsyncTransaction<any, any>) => {\n\t\t\t\tfor (const sql of sqls) {\n\t\t\t\t\tawait tx.execute(sql);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (mode === 'batch') {\n\t\t\tconst database = db as NeonHttpDatabase;\n\n\t\t\tawait database.batch(\n\t\t\t\tsqls.map((s) => database.execute(s)) as unknown as [BatchItem<'pg'>, ...BatchItem<'pg'>[]],\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const sql of sqls) {\n\t\t\t\tawait db.execute(sql);\n\t\t\t}\n\t\t}\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport async function upgradeIfNeeded(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tdb: PgAsyncDatabase<PgQueryResultHKT, any>,\n\tlocalMigrations: MigrationMeta[],\n\tmode: 'transaction' | 'execute' | 'batch' = 'transaction',\n): Promise<UpgradeResult> {\n\t// Check if the table exists at all\n\tconst result = await db.session.objects<{ '1': 1 }>(\n\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t);\n\n\tif (result.length === 0) {\n\t\treturn { newDb: true };\n\t}\n\n\t// Table exists, check table shape\n\tconst rows = await db.session.objects<\n\t\t{ schema: string; table_name: string; column_name: string; type: string }\n\t>(\n\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t);\n\n\tlet version = getVersion(rows.map((r) => r.column_name));\n\n\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\tconst upgradeFn = upgradeFunctions[v];\n\t\tif (!upgradeFn) {\n\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t}\n\t\tawait upgradeFn(migrationsSchema, migrationsTable, db, localMigrations, mode);\n\t}\n\n\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n}\n"],"mappings":"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"}
|
package/up-migrations/pg.d.cts
CHANGED
|
@@ -14,7 +14,7 @@ interface UpgradeResult {
|
|
|
14
14
|
* Version 0: Original schema (id, hash, created_at)
|
|
15
15
|
* Version 1: Extended schema (id, hash, created_at, name, applied_at)
|
|
16
16
|
*/
|
|
17
|
-
declare function upgradeIfNeeded(migrationsSchema: string, migrationsTable: string, db: PgAsyncDatabase<PgQueryResultHKT, any
|
|
17
|
+
declare function upgradeIfNeeded(migrationsSchema: string, migrationsTable: string, db: PgAsyncDatabase<PgQueryResultHKT, any>, localMigrations: MigrationMeta[], mode?: 'transaction' | 'execute' | 'batch'): Promise<UpgradeResult>;
|
|
18
18
|
//#endregion
|
|
19
19
|
export { upgradeIfNeeded };
|
|
20
20
|
//# sourceMappingURL=pg.d.cts.map
|
package/up-migrations/pg.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ interface UpgradeResult {
|
|
|
14
14
|
* Version 0: Original schema (id, hash, created_at)
|
|
15
15
|
* Version 1: Extended schema (id, hash, created_at, name, applied_at)
|
|
16
16
|
*/
|
|
17
|
-
declare function upgradeIfNeeded(migrationsSchema: string, migrationsTable: string, db: PgAsyncDatabase<PgQueryResultHKT, any
|
|
17
|
+
declare function upgradeIfNeeded(migrationsSchema: string, migrationsTable: string, db: PgAsyncDatabase<PgQueryResultHKT, any>, localMigrations: MigrationMeta[], mode?: 'transaction' | 'execute' | 'batch'): Promise<UpgradeResult>;
|
|
18
18
|
//#endregion
|
|
19
19
|
export { upgradeIfNeeded };
|
|
20
20
|
//# sourceMappingURL=pg.d.ts.map
|
package/up-migrations/pg.js
CHANGED
|
@@ -6,18 +6,13 @@ function getVersion(columns) {
|
|
|
6
6
|
if (columns.includes("name")) return 1;
|
|
7
7
|
return 0;
|
|
8
8
|
}
|
|
9
|
-
async function execute(session, sql) {
|
|
10
|
-
const result = await session.execute(sql);
|
|
11
|
-
if ("rows" in result) return result.rows;
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
9
|
/**
|
|
15
10
|
* Map of upgrade functions. Each key is the version being upgraded FROM,
|
|
16
11
|
* and the function upgrades the table to the next version.
|
|
17
12
|
*/
|
|
18
13
|
const upgradeFunctions = { 0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {
|
|
19
14
|
const table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;
|
|
20
|
-
const dbRows = await
|
|
15
|
+
const dbRows = await db.session.objects(sql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`);
|
|
21
16
|
localMigrations.sort((a, b) => a.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? "").localeCompare(b.name ?? ""));
|
|
22
17
|
const byMillis = /* @__PURE__ */ new Map();
|
|
23
18
|
const byHash = /* @__PURE__ */ new Map();
|
|
@@ -60,10 +55,10 @@ const upgradeFunctions = { 0: async (migrationsSchema, migrationsTable, db, loca
|
|
|
60
55
|
* Version 1: Extended schema (id, hash, created_at, name, applied_at)
|
|
61
56
|
*/
|
|
62
57
|
async function upgradeIfNeeded(migrationsSchema, migrationsTable, db, localMigrations, mode = "transaction") {
|
|
63
|
-
if ((await
|
|
58
|
+
if ((await db.session.objects(sql`SELECT 1 FROM information_schema.tables
|
|
64
59
|
WHERE table_schema = ${migrationsSchema}
|
|
65
60
|
AND table_name = ${migrationsTable}`)).length === 0) return { newDb: true };
|
|
66
|
-
let version = getVersion((await
|
|
61
|
+
let version = getVersion((await db.session.objects(sql`SELECT
|
|
67
62
|
n.nspname AS "schema",
|
|
68
63
|
c.relname AS "table_name",
|
|
69
64
|
a.attname AS "column_name",
|
package/up-migrations/pg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg.js","names":[],"sources":["../../src/up-migrations/pg.ts"],"sourcesContent":["import type { TablesRelationalConfig } from '~/_relations.ts';\nimport type { BatchItem } from '~/batch.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { NeonHttpDatabase } from '~/neon-http/driver.ts';\nimport type { NeonHttpSession } from '~/neon-http/session.ts';\nimport type { PgAsyncDatabase } from '~/pg-core/async/db.ts';\nimport type { PgAsyncSession, PgAsyncTransaction } from '~/pg-core/async/session.ts';\nimport type { PgQueryResultHKT } from '~/pg-core/session.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport { type SQL, sql } from '~/sql/sql.ts';\nimport type { XataHttpSession } from '~/xata-http/session.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n// postgres.js returns array of objects\n// pg-proxy returns arrays of objects\n// node-postgres returns { rows: array of objects }\nasync function execute<T extends any[]>(\n\tsession:\n\t\t| PgAsyncSession\n\t\t| NeonHttpSession<Record<string, unknown>, AnyRelations, TablesRelationalConfig>\n\t\t| XataHttpSession<Record<string, unknown>, AnyRelations, TablesRelationalConfig>,\n\tsql: SQL,\n): Promise<T> {\n\tconst result: { rows: T } | T = await session.execute(sql);\n\tif ('rows' in result) return result.rows;\n\treturn result;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tdb: PgAsyncDatabase<PgQueryResultHKT, any, any, any>,\n\t\tlocalMigrations: MigrationMeta[],\n\t\tmode: 'transaction' | 'execute' | 'batch',\n\t) => Promise<void>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {\n\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t// 1. Read all existing DB migrations\n\t\t// Sort them by ids asc (order how they were applied)\n\t\tconst dbRows = await execute<{ id: number; hash: string; created_at: string }[]>(\n\t\t\tdb.session,\n\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t);\n\n\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\tlocalMigrations.sort((a, b) =>\n\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t);\n\n\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\tfor (const lm of localMigrations) {\n\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t}\n\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\tbyHash.set(lm.hash, lm);\n\t\t}\n\n\t\t// \t3. Match each DB row to a local migration\n\t\t// \tPriority: millis -> hash\n\t\tconst toApply: { id: number; name: string }[] = [];\n\t\tlet unmatchedIds: number[] = [];\n\n\t\tfor (const dbRow of dbRows) {\n\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\tmatched = candidates[0];\n\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t} else {\n\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t}\n\n\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t}\n\n\t\t// 4. Check for unmatched\n\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\tif (unmatchedIds.length > 0) {\n\t\t\tthrow Error(\n\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t);\n\t\t}\n\n\t\t// 5. Create extra column and backfill names for matched migrations\n\t\tconst sqls: SQL[] = [\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`,\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\tsql.identifier('applied_at')\n\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t];\n\t\tfor (const { id, name } of toApply) {\n\t\t\tsqls.push(\n\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${name}, ${sql.identifier('applied_at')} = NULL WHERE ${\n\t\t\t\t\tsql.identifier('id')\n\t\t\t\t} = ${id}`,\n\t\t\t);\n\t\t}\n\n\t\t// check if http\n\t\t// execute -> proxy, http drivers\n\t\t// transaction -> other\n\t\tif (mode === 'transaction') {\n\t\t\tawait db.transaction(async (tx: PgAsyncTransaction<any, any, any>) => {\n\t\t\t\tfor (const sql of sqls) {\n\t\t\t\t\tawait tx.execute(sql);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (mode === 'batch') {\n\t\t\tconst database = db as NeonHttpDatabase;\n\n\t\t\tawait database.batch(\n\t\t\t\tsqls.map((s) => database.execute(s)) as unknown as [BatchItem<'pg'>, ...BatchItem<'pg'>[]],\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const sql of sqls) {\n\t\t\t\tawait db.execute(sql);\n\t\t\t}\n\t\t}\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport async function upgradeIfNeeded(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tdb: PgAsyncDatabase<PgQueryResultHKT, any, any, any>,\n\tlocalMigrations: MigrationMeta[],\n\tmode: 'transaction' | 'execute' | 'batch' = 'transaction',\n): Promise<UpgradeResult> {\n\t// Check if the table exists at all\n\tconst result = await execute<{ '1': 1 }[]>(\n\t\tdb.session,\n\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t);\n\n\tif (result.length === 0) {\n\t\treturn { newDb: true };\n\t}\n\n\t// Table exists, check table shape\n\tconst rows = await execute<\n\t\t{ schema: string; table_name: string; column_name: string; type: string }[]\n\t>(\n\t\tdb.session,\n\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t);\n\n\tlet version = getVersion(rows.map((r) => r.column_name));\n\n\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\tconst upgradeFn = upgradeFunctions[v];\n\t\tif (!upgradeFn) {\n\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t}\n\t\tawait upgradeFn(migrationsSchema, migrationsTable, db, localMigrations, mode);\n\t}\n\n\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"pg.js","names":[],"sources":["../../src/up-migrations/pg.ts"],"sourcesContent":["import type { BatchItem } from '~/batch.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { NeonHttpDatabase } from '~/neon-http/driver.ts';\nimport type { PgAsyncDatabase } from '~/pg-core/async/db.ts';\nimport type { PgAsyncTransaction } from '~/pg-core/async/session.ts';\nimport type { PgQueryResultHKT } from '~/pg-core/session.ts';\nimport { type SQL, sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tdb: PgAsyncDatabase<PgQueryResultHKT, any>,\n\t\tlocalMigrations: MigrationMeta[],\n\t\tmode: 'transaction' | 'execute' | 'batch',\n\t) => Promise<void>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {\n\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t// 1. Read all existing DB migrations\n\t\t// Sort them by ids asc (order how they were applied)\n\t\tconst dbRows = await db.session.objects<{ id: number; hash: string; created_at: string }>(\n\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t);\n\n\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\tlocalMigrations.sort((a, b) =>\n\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t);\n\n\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\tfor (const lm of localMigrations) {\n\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t}\n\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\tbyHash.set(lm.hash, lm);\n\t\t}\n\n\t\t// \t3. Match each DB row to a local migration\n\t\t// \tPriority: millis -> hash\n\t\tconst toApply: { id: number; name: string }[] = [];\n\t\tlet unmatchedIds: number[] = [];\n\n\t\tfor (const dbRow of dbRows) {\n\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\tmatched = candidates[0];\n\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t} else {\n\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t}\n\n\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t}\n\n\t\t// 4. Check for unmatched\n\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\tif (unmatchedIds.length > 0) {\n\t\t\tthrow Error(\n\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t);\n\t\t}\n\n\t\t// 5. Create extra column and backfill names for matched migrations\n\t\tconst sqls: SQL[] = [\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`,\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\tsql.identifier('applied_at')\n\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t];\n\t\tfor (const { id, name } of toApply) {\n\t\t\tsqls.push(\n\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${name}, ${sql.identifier('applied_at')} = NULL WHERE ${\n\t\t\t\t\tsql.identifier('id')\n\t\t\t\t} = ${id}`,\n\t\t\t);\n\t\t}\n\n\t\t// check if http\n\t\t// execute -> proxy, http drivers\n\t\t// transaction -> other\n\t\tif (mode === 'transaction') {\n\t\t\tawait db.transaction(async (tx: PgAsyncTransaction<any, any>) => {\n\t\t\t\tfor (const sql of sqls) {\n\t\t\t\t\tawait tx.execute(sql);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (mode === 'batch') {\n\t\t\tconst database = db as NeonHttpDatabase;\n\n\t\t\tawait database.batch(\n\t\t\t\tsqls.map((s) => database.execute(s)) as unknown as [BatchItem<'pg'>, ...BatchItem<'pg'>[]],\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const sql of sqls) {\n\t\t\t\tawait db.execute(sql);\n\t\t\t}\n\t\t}\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport async function upgradeIfNeeded(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tdb: PgAsyncDatabase<PgQueryResultHKT, any>,\n\tlocalMigrations: MigrationMeta[],\n\tmode: 'transaction' | 'execute' | 'batch' = 'transaction',\n): Promise<UpgradeResult> {\n\t// Check if the table exists at all\n\tconst result = await db.session.objects<{ '1': 1 }>(\n\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t);\n\n\tif (result.length === 0) {\n\t\treturn { newDb: true };\n\t}\n\n\t// Table exists, check table shape\n\tconst rows = await db.session.objects<\n\t\t{ schema: string; table_name: string; column_name: string; type: string }\n\t>(\n\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t);\n\n\tlet version = getVersion(rows.map((r) => r.column_name));\n\n\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\tconst upgradeFn = upgradeFunctions[v];\n\t\tif (!upgradeFn) {\n\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t}\n\t\tawait upgradeFn(migrationsSchema, migrationsTable, db, localMigrations, mode);\n\t}\n\n\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n}\n"],"mappings":"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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { TablesRelationalConfig } from "../_relations.js";
|
|
2
1
|
import { MigrationMeta } from "../migrator.js";
|
|
3
|
-
import {
|
|
2
|
+
import { TablesRelationalConfig } from "../_relations.js";
|
|
4
3
|
import { AnyRelations } from "../relations.js";
|
|
4
|
+
import { SQLiteSession } from "../sqlite-core/session.js";
|
|
5
5
|
import { SQLiteD1Session } from "../d1/session.js";
|
|
6
6
|
import { LibSQLSession } from "../libsql/session.js";
|
|
7
7
|
import { SQLiteCloudSession } from "../sqlite-cloud/session.js";
|
package/utils.cjs
CHANGED
|
@@ -10,7 +10,7 @@ const require_view_common = require('./view-common.cjs');
|
|
|
10
10
|
/** @internal */
|
|
11
11
|
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
12
12
|
const nullifyMap = {};
|
|
13
|
-
const result = columns.reduce((result, { path, field }, columnIndex) => {
|
|
13
|
+
const result = columns.reduce((result, { path, field, codec, arrayDimensions }, columnIndex) => {
|
|
14
14
|
let decoder;
|
|
15
15
|
if (require_entity.is(field, require_column.Column)) decoder = field;
|
|
16
16
|
else if (require_entity.is(field, require_sql_sql.SQL)) decoder = field.decoder;
|
|
@@ -22,7 +22,7 @@ function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
|
22
22
|
node = node[pathChunk];
|
|
23
23
|
} else {
|
|
24
24
|
const rawValue = row[columnIndex];
|
|
25
|
-
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
25
|
+
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(codec ? codec(rawValue, arrayDimensions) : rawValue);
|
|
26
26
|
if (joinsNotNullableMap && require_entity.is(field, require_column.Column) && path.length === 2) {
|
|
27
27
|
const objectName = path[0];
|
|
28
28
|
if (!(objectName in nullifyMap)) nullifyMap[objectName] = value === null ? require_table.getTableName(field.table) : false;
|
|
@@ -37,16 +37,122 @@ function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
|
37
37
|
return result;
|
|
38
38
|
}
|
|
39
39
|
/** @internal */
|
|
40
|
-
function
|
|
40
|
+
function makeJitQueryMapperInner(columns, joinsNotNullableMap) {
|
|
41
|
+
let fn = [];
|
|
42
|
+
if (joinsNotNullableMap) fn.push(`const nullifyMap = {};`);
|
|
43
|
+
const initializedPaths = /* @__PURE__ */ new Set();
|
|
44
|
+
for (const [idx, { path: pathArr, field, codec, arrayDimensions }] of columns.entries()) {
|
|
45
|
+
const pathPrefix = pathArr.slice(0, -1);
|
|
46
|
+
const path = pathArr.map((e) => `[${JSON.stringify(e)}]`).join("");
|
|
47
|
+
let processedPath;
|
|
48
|
+
for (const p of pathPrefix) {
|
|
49
|
+
processedPath = processedPath ? `${processedPath}[${JSON.stringify(p)}]` : `[${JSON.stringify(p)}]`;
|
|
50
|
+
if (initializedPaths.has(processedPath)) continue;
|
|
51
|
+
fn.push(`res${processedPath} = {};`);
|
|
52
|
+
initializedPaths.add(processedPath);
|
|
53
|
+
}
|
|
54
|
+
let decoder;
|
|
55
|
+
let decoderStr;
|
|
56
|
+
if (require_entity.is(field, require_column.Column)) {
|
|
57
|
+
decoder = field;
|
|
58
|
+
decoderStr = `this.columns[${idx}].field.mapFromDriverValue`;
|
|
59
|
+
} else if (require_entity.is(field, require_sql_sql.SQL)) {
|
|
60
|
+
decoder = field.decoder;
|
|
61
|
+
decoderStr = `this.columns[${idx}].field.decoder.mapFromDriverValue`;
|
|
62
|
+
} else if (require_entity.is(field, require_subquery.Subquery)) {
|
|
63
|
+
decoder = field._.sql.decoder;
|
|
64
|
+
decoderStr = `this.columns[${idx}].field._.sql.decoder.mapFromDriverValue`;
|
|
65
|
+
} else {
|
|
66
|
+
decoder = field.sql.decoder;
|
|
67
|
+
decoderStr = `this.columns[${idx}].field.sql.decoder.mapFromDriverValue`;
|
|
68
|
+
}
|
|
69
|
+
if (decoder.mapFromDriverValue.isNoop) decoderStr = "";
|
|
70
|
+
const rowStr = `rows[i][${idx}]`;
|
|
71
|
+
let decodedValue = rowStr;
|
|
72
|
+
if (codec) decodedValue = `this.columns[${idx}].codec(${decodedValue}, ${arrayDimensions})`;
|
|
73
|
+
if (decoderStr) decodedValue = `${decoderStr}(${decodedValue})`;
|
|
74
|
+
fn.push(` res${path} = ${rowStr} === null ? ${rowStr} : ${decodedValue};`);
|
|
75
|
+
if (joinsNotNullableMap && require_entity.is(field, require_column.Column) && pathArr.length === 2) {
|
|
76
|
+
const objectName = JSON.stringify(pathArr[0]);
|
|
77
|
+
fn.push(`if (!(${objectName} in nullifyMap)) {`, ` nullifyMap[${objectName}] = res${path} === null ? this.getTableName(this.columns[${idx}].field.table) : false;`, `} else if (typeof nullifyMap[${objectName}] === 'string' && nullifyMap[${objectName}] !== this.getTableName(this.columns[${idx}].field.table)) {`, ` nullifyMap[${objectName}] = false;`, `}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (joinsNotNullableMap) fn.push(`if(Object.keys(nullifyMap).length) {`, ` for (const [objectName, tableName] of Object.entries(nullifyMap)) {`, ` if (typeof tableName === 'string' && !this.joinsNotNullableMap[tableName]) {`, ` res[objectName] = null;`, ` }`, ` }`, `}`);
|
|
81
|
+
return fn.join("\n");
|
|
82
|
+
}
|
|
83
|
+
function makeJitQueryMapper(columns, joinsNotNullableMap) {
|
|
84
|
+
return new Function("rows", `const mapped = [];
|
|
85
|
+
for (let i = 0; i < rows.length; ++i) {
|
|
86
|
+
const res = {};
|
|
87
|
+
${makeJitQueryMapperInner(columns, joinsNotNullableMap)}
|
|
88
|
+
mapped[i] = res;
|
|
89
|
+
}
|
|
90
|
+
return mapped;
|
|
91
|
+
//# sourceURL=drizzle:jit-query-mapper`).bind({
|
|
92
|
+
getTableName: require_table.getTableName,
|
|
93
|
+
columns,
|
|
94
|
+
joinsNotNullableMap
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function makeDefaultQueryMapper(columns, joinsNotNullableMap) {
|
|
98
|
+
const interpretedData = columns.map(({ field, codec, arrayDimensions, path }) => {
|
|
99
|
+
let processNullifyMap;
|
|
100
|
+
let decoderSrc;
|
|
101
|
+
if (require_entity.is(field, require_column.Column)) {
|
|
102
|
+
decoderSrc = field;
|
|
103
|
+
if (joinsNotNullableMap && path.length === 2) {
|
|
104
|
+
const objectName = path[0];
|
|
105
|
+
processNullifyMap = (nullifyMap, value) => {
|
|
106
|
+
if (!(objectName in nullifyMap)) nullifyMap[objectName] = value === null ? require_table.getTableName(field.table) : false;
|
|
107
|
+
else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== require_table.getTableName(field.table)) nullifyMap[objectName] = false;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
} else if (require_entity.is(field, require_sql_sql.SQL)) decoderSrc = field.decoder;
|
|
111
|
+
else if (require_entity.is(field, require_subquery.Subquery)) decoderSrc = field._.sql.decoder;
|
|
112
|
+
else decoderSrc = field.sql.decoder;
|
|
113
|
+
let decoder;
|
|
114
|
+
if (decoderSrc.mapFromDriverValue.isNoop) decoder = codec ? (v) => codec(v, arrayDimensions) : void 0;
|
|
115
|
+
else decoder = codec ? (v) => decoderSrc.mapFromDriverValue(codec(v, arrayDimensions)) : (v) => decoderSrc.mapFromDriverValue(v);
|
|
116
|
+
return [decoder, processNullifyMap];
|
|
117
|
+
});
|
|
118
|
+
return ((rows) => rows.map((row) => {
|
|
119
|
+
const nullifyMap = {};
|
|
120
|
+
const result = columns.reduce((result, { path }, columnIndex) => {
|
|
121
|
+
let node = result;
|
|
122
|
+
for (const [pathChunkIndex, pathChunk] of path.entries()) if (pathChunkIndex < path.length - 1) {
|
|
123
|
+
if (!(pathChunk in node)) node[pathChunk] = {};
|
|
124
|
+
node = node[pathChunk];
|
|
125
|
+
} else {
|
|
126
|
+
const [decoder, processNullifyMap] = interpretedData[columnIndex];
|
|
127
|
+
const rawValue = row[columnIndex];
|
|
128
|
+
const value = node[pathChunk] = rawValue === null ? null : decoder ? decoder(rawValue) : rawValue;
|
|
129
|
+
processNullifyMap?.(nullifyMap, value);
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}, {});
|
|
133
|
+
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
134
|
+
for (const [objectName, tableName] of Object.entries(nullifyMap)) if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) result[objectName] = null;
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
/** @internal */
|
|
140
|
+
function orderSelectedFields(fields, pathPrefix, codecs) {
|
|
41
141
|
return Object.entries(fields).reduce((result, [name, field]) => {
|
|
42
142
|
if (typeof name !== "string") return result;
|
|
43
143
|
const newPath = pathPrefix ? [...pathPrefix, name] : [name];
|
|
44
|
-
if (require_entity.is(field, require_column.Column)
|
|
144
|
+
if (require_entity.is(field, require_column.Column)) result.push({
|
|
145
|
+
path: newPath,
|
|
146
|
+
field,
|
|
147
|
+
codec: codecs?.get(field, "normalize"),
|
|
148
|
+
arrayDimensions: field.dimensions
|
|
149
|
+
});
|
|
150
|
+
else if (require_entity.is(field, require_column.Column) || require_entity.is(field, require_sql_sql.SQL) || require_entity.is(field, require_sql_sql.SQL.Aliased) || require_entity.is(field, require_subquery.Subquery)) result.push({
|
|
45
151
|
path: newPath,
|
|
46
152
|
field
|
|
47
153
|
});
|
|
48
|
-
else if (require_entity.is(field, require_table.Table)) result.push(...orderSelectedFields(field[require_table.Table.Symbol.Columns], newPath));
|
|
49
|
-
else result.push(...orderSelectedFields(field, newPath));
|
|
154
|
+
else if (require_entity.is(field, require_table.Table)) result.push(...orderSelectedFields(field[require_table.Table.Symbol.Columns], newPath, codecs));
|
|
155
|
+
else result.push(...orderSelectedFields(field, newPath, codecs));
|
|
50
156
|
return result;
|
|
51
157
|
}, []);
|
|
52
158
|
}
|
|
@@ -134,6 +240,11 @@ function isConfig(data) {
|
|
|
134
240
|
if (type !== "object" && type !== "function" && type !== "undefined") return false;
|
|
135
241
|
return true;
|
|
136
242
|
}
|
|
243
|
+
if ("useJitMapper" in data) {
|
|
244
|
+
const type = typeof data["useJitMapper"];
|
|
245
|
+
if (type !== "boolean" && type !== "undefined") return false;
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
137
248
|
if (Object.keys(data).length === 0) return true;
|
|
138
249
|
return false;
|
|
139
250
|
}
|
|
@@ -164,11 +275,20 @@ const CONSTANTS = {
|
|
|
164
275
|
INT64_MAX: 9223372036854775807n,
|
|
165
276
|
INT64_UNSIGNED_MAX: 18446744073709551615n
|
|
166
277
|
};
|
|
278
|
+
function base64ToUint8Array(base64) {
|
|
279
|
+
if (!base64) return new Uint8Array(0);
|
|
280
|
+
const binary = atob(base64);
|
|
281
|
+
const len = binary.length;
|
|
282
|
+
const bytes = new Uint8Array(len);
|
|
283
|
+
for (let i = 0; i < len; ++i) bytes[i] = binary.charCodeAt(i);
|
|
284
|
+
return bytes;
|
|
285
|
+
}
|
|
167
286
|
|
|
168
287
|
//#endregion
|
|
169
288
|
exports.CONSTANTS = CONSTANTS;
|
|
170
289
|
exports.applyMixins = applyMixins;
|
|
171
290
|
exports.assertUnreachable = assertUnreachable;
|
|
291
|
+
exports.base64ToUint8Array = base64ToUint8Array;
|
|
172
292
|
exports.getColumnNameAndConfig = getColumnNameAndConfig;
|
|
173
293
|
exports.getColumns = getColumns;
|
|
174
294
|
exports.getTableColumns = getTableColumns;
|
|
@@ -177,6 +297,8 @@ exports.getViewSelectedFields = getViewSelectedFields;
|
|
|
177
297
|
exports.haveSameKeys = haveSameKeys;
|
|
178
298
|
exports.isConfig = isConfig;
|
|
179
299
|
exports.isWithEnum = isWithEnum;
|
|
300
|
+
exports.makeDefaultQueryMapper = makeDefaultQueryMapper;
|
|
301
|
+
exports.makeJitQueryMapper = makeJitQueryMapper;
|
|
180
302
|
exports.mapResultRow = mapResultRow;
|
|
181
303
|
exports.mapUpdateSet = mapUpdateSet;
|
|
182
304
|
exports.orderSelectedFields = orderSelectedFields;
|