@typesql/postgres 0.2.8 → 0.2.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @typesql/postgres
2
2
 
3
+ ## 0.2.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Breaking: TypeSQL is split into a dialect-neutral core and a PostgreSQL dialect. `@typesql/core` keeps what dialects share (`createSql`, queries, fragments, executors, row keys, transactions, migrations, the schema markers `Col`, `Nullable`, `Generated`, `View`, … and the type cache) and adds a dialect contract. PostgreSQL moves to `@typesql/core/postgres`: create a `sql` with `createSql<DB>(postgres, executor?)`, import `Json`, `PgCatalog`, `migrations()`, type maps and the function catalog from `@typesql/core/postgres` (which also re-exports the schema markers), and the engine types from `@typesql/core/postgres/engine` (was `@typesql/core/engine`). The Kysely, Drizzle and Prisma packages take the dialect the same way and read the schema from the client's type: `createSql(postgres, db)` (`createSql<DB>(postgres, db)` still picks a schema explicitly). `typesql introspect` and the Prisma generator import the column helpers from `@typesql/core/postgres` by default.
8
+
9
+ - Updated dependencies:
10
+ - @typesql/core@0.8.0
11
+
12
+ ## 0.2.9
13
+
14
+ ### Patch Changes
15
+
16
+ - Validate packages against PostgreSQL behavior and built outputs instead of hand-written test suites.
17
+
18
+ - Reorganize core internals and remove source comments and inline API documentation without changing SQL behavior.
19
+
20
+ - Updated dependencies:
21
+ - @typesql/core@0.7.6
22
+
3
23
  ## 0.2.8
4
24
 
5
25
  ### Patch Changes
package/README.md CHANGED
@@ -18,7 +18,6 @@ import type { DB } from "./schema";
18
18
  const sql = createSql<DB>(postgres(process.env.DATABASE_URL!));
19
19
 
20
20
  const posts = await sql("SELECT id, title FROM posts WHERE author_id = $1", 1).execute();
21
- // { id: string; title: string }[] (int8 is a string by default)
22
21
 
23
22
  await sql.transaction(async (tx) => {
24
23
  await tx("UPDATE posts SET title = upper(title) WHERE author_id = $1", 1).execute();
@@ -27,7 +26,7 @@ await sql.transaction(async (tx) => {
27
26
 
28
27
  If your connection parses `int8` to `bigint` (`types: { bigint: postgres.BigInt }`), pass `{ bigint: true }` as the second argument of `createSql`.
29
28
 
30
- [Open an example in the TypeScript Playground](https://www.typescriptlang.org/play/#code/PTAEBUE8AcFMGUCKAZUB3AlgFwBamgPYDOWA5gE6xEB0AVkaABQACWMVAjgDbCEkVUAlNVCIArrHIYqocmIB26bHiLdqCogEMAZrEZZYADywAaUADdNXCUUFnN8gCayCaIgCgQoTZVBs4zgBGkOg4mlj4xGSUNPT4PkRUAFygGPJYABypDJqgJFLypGYE5N6ggRikaRGYuKAAQpUAkunx5ERppKAE8tTu7hgAtoTkEf6woADeoADCBFxmAOKw8pLhsI5mAHJiXFyagVwTAL6g2uQEg6AARKzsqjwAxiWw1wDcA8MlEdOPlOvwbigU7nS43O5wB68KICIjvT4jMbsKagQFcYFnC5Xa58aJUeEDdKSbSaR4TAAi9Sm7gAkGJEu0UpNaTSMI4UstVuR1o4ADzXaoAFmuAD4PjSabBBpoMFwUnMuPyDMZReKaY4MERoPtIAB9eSaQawFI7PYHI5KoxYVUsv6wHm68IclZrAx865YIZULCG6BYABeNppx3FuKITJZbOdXJ5-OqGSDNM0YlwJV1Udm8zj6WFYpZnqwR3lWY9VsTPtI4czitLxgA2gBdIMh9zHfqOWCPfa+Z7yEigRyBFJot6gLy42GMHEwmJJEBcAiPKw4KLATTQaDXQTuXv9h6gAC8oDtAO4vMpIsYg8EHx3PX7YcP3jQMoiD0YtIABvAAKLIH8zOAqSbH42BHGYFYMAAYgASgA8gAspEJAMAA6gAEj+ME-qAAAkACMT4AIJbAAmkwkGCJ+Ji0tcDzXDRwhGJ2KZ6DenhgKAXEAHoAPz9F4cGKLkvarI8no9EodSfuMVbTBUVTpCkE4xNQjSkC0ETHNRqTpFkDjOM8ChYIwABUgjHpcEyBKSADW3gMAp1R9B2XY+BMu4RIO6nDme8mVNUKROa0xx5p55SVE+J4GGi571Je3mVGY-mKVgKRYHIJzseFRnpAwR6aC+2ARaQH40t+f4AUByapuQ6YgblJnmaARHwKAiiwYhyFYAwizwQAqgACg05E1SudVstR7hMYYLEGIw7FeFxoB8QJYAPNQGUOFo4kYJJmp5GogSwIpo5YIYm3cn2pISYoB25Fo5iwIQznuIVr6HVwl3bTde3yIwmhEJA8iPBRhgWQeIrUkmRVjIYZXlUN5JEeAOGPr+QEFkcT5iBukj6GBsAWRhWE4WNaZsk+BFTRKADsNE0jNc1seK4WKAVsN+PDLKfuSlWo6AnVIY+JPYcePgagaXDYJA+iaJWEOgAADDTTOPKxczGQt4pLTx-HHOx7jvhV-6AcBgvwcLURoZhYuQaAzBQ9TZh0dwW6jl4kgXOQ6Xywwjt+JotkyLkypYI27hAA) <!-- playground:postgres --> to hover the types and edit the SQL, with nothing to install.
29
+ [Open an example in the TypeScript Playground](https://www.typescriptlang.org/play/#code/JYWwDg9gTgLgBDAnmApnA3nAwhANgGjgHEUA7FKAQxhQBNCA5AV110oCNc0BfOAMygQQcAEQABJKgDOAR1wB6AMbQU8yFJgBzKCikiA3AChQkWBjiKd1FAGU5cXgKGiJyXXLUQN23QePhoeEk0TDtcB35BYRF1LR09I2NSGig+SkU0ABEAIQxDAEgmKQopAC48-PzgWnKScioaWgAeEWBkgBYRAD4jSpQQSmBccpxcFpoADxhu3vzaYCkwNkQAfVJKEBRy5lYOLnGUKZmC-MsUa1oV6lqyCgvx0F0YDbAYAC9j-O5e2LKKqpqxFuDToLTaMAAHJ98pQmDAABbQFbVEZ4MEdaEwYAwLiosYiSbTHonZ6aP6jA5TADaAF1Pt9DNxDIZaChFGwdBYIKQNHBaOxymEjMoefBZOEALwWKw0MJNHJdAAU-IAlIkRbzfnApZQAO6DMVyRUFAAGNgAogAZc1YAAqcGqhCxOJQTsoZLgADEAEoAeQAsnAtQB1AAS5u95rgABIAIzauAAQQYAE04IrSVIVSb8AUROKRLmVQA6Q5suEoRVq5ms9mUTka+D87LATSCuRNTDsVvg8rdzTghzExtwfsJs7WOUK5XsFuaQhdnvJcowKBMHjVkfKJjJKQJvUG0et435M1Wm322EIpGOrk7mCKgBUKqTNjgpC9fsDWqIfoAqgACnA2RpleiJQMitA5oYJZlooFZVokB7YnA4rFqulA8ukWLcoqlBSIgpCKOmMATC+EpdBUyFBBMJ6noBmSJraUZaha9rOlwCZMGAqBQBm2JcC+YYRlGYE3rQCZxtBlQAOy5vksETOWNCIQUI4fjq+ooaRdEmpk57MZ+AZBl4MB7sJkYWPW8zrLg2KIBm7pZgmAAM0mKcpKA4PeqncNWhjioqZ7WnaDoST6xkhuGlmZnAYiUVJhD5nIIjVkAA) <span data-playground="postgres"></span> to hover the types and edit the SQL, with nothing to install.
31
30
 
32
31
  ## Documentation
33
32
 
package/dist/client.d.ts CHANGED
@@ -1,41 +1,21 @@
1
1
  import type { Executor } from "@typesql/core";
2
2
  import type { SqlDriver } from "@typesql/core/adapter";
3
- /**
4
- * The shape of a resolved `sql.unsafe()` result the adapter relies on: an array with `count`
5
- * (`null` for statements without a count, such as DDL).
6
- */
7
3
  export type PostgresJsRows = readonly unknown[] & {
8
4
  readonly count: number | null;
9
5
  };
10
- /**
11
- * Anything with postgres.js' `unsafe(query, parameters)` method: the `Sql` instance,
12
- * a `TransactionSql` inside `begin`, a `ReservedSql`, or a fake in tests.
13
- */
14
6
  export interface PostgresJsQueryable {
15
7
  unsafe(query: string, parameters?: unknown[], options?: {
16
8
  readonly prepare: boolean;
17
9
  readonly simple: boolean;
18
10
  }): PromiseLike<PostgresJsRows>;
19
11
  }
20
- /** Anything with postgres.js' `begin(fn)`: the `Sql` instance or a `ReservedSql`. */
21
12
  export interface PostgresJsTransactable<Tx extends PostgresJsQueryable = PostgresJsQueryable> {
22
13
  begin(fn: (tx: Tx) => Promise<unknown>): Promise<unknown>;
23
14
  }
24
- /**
25
- * An `Executor` for core's `q.execute()`: runs queries through `sql.unsafe` and resolves to
26
- * `{ rows, rowCount }` (postgres.js' `.count`, so `q.executeCount()` works).
27
- */
28
15
  export declare function executor(sql: PostgresJsQueryable): Executor;
29
- /** How `createSql(sql)` runs queries and transactions. */
30
16
  export declare const driver: SqlDriver<PostgresJsQueryable>;
31
- /** Anything carrying an ordered list of DDL statements, e.g. a `migrations()` builder from core. */
32
17
  export interface MigrationSource {
33
18
  readonly statements: readonly string[];
34
19
  }
35
- /**
36
- * Run a migration's statements in order inside one transaction (`sql.begin`), all or nothing.
37
- * Each statement goes through `unsafe` without parameters (simple protocol), so scripts with
38
- * `$$`-quoted function bodies work.
39
- */
40
20
  export declare function migrate<Tx extends PostgresJsQueryable>(sql: PostgresJsTransactable<Tx>, m: MigrationSource): Promise<void>;
41
21
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,OAAO,EAAE,GAAG;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,MAAM,CACL,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,OAAO,EAAE,EACtB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;KAAE,GAC/D,WAAW,CAAC,cAAc,CAAC,CAAC;CAC/B;AAED,qFAAqF;AACrF,MAAM,WAAW,sBAAsB,CACtC,EAAE,SAAS,mBAAmB,GAAG,mBAAmB;IAEpD,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1D;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mB,GAAG,QAAQ,CAc3D;AAiBD,eAAO,MAAM,MAAM,EAAE,SAAS,CAAC,mBAAmB,CAA6B,CAAC;AAEhF,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED,wBAAsB,OAAO,CAAC,EAAE,SAAS,mBAAmB,EAC3D,GAAG,EAAE,sBAAsB,CAAC,EAAE,CAAC,EAC/B,CAAC,EAAE,eAAe,GAChB,OAAO,CAAC,IAAI,CAAC,CAIf"}
package/dist/client.js CHANGED
@@ -1,7 +1,3 @@
1
- /**
2
- * An `Executor` for core's `q.execute()`: runs queries through `sql.unsafe` and resolves to
3
- * `{ rows, rowCount }` (postgres.js' `.count`, so `q.executeCount()` works).
4
- */
5
1
  export function executor(sql) {
6
2
  const run = async (text, values) => {
7
3
  const result = await sql.unsafe(text, Array.from(values));
@@ -17,11 +13,6 @@ export function executor(sql) {
17
13
  },
18
14
  });
19
15
  }
20
- /**
21
- * Run `fn` inside a transaction: `tx.savepoint(fn)` on a `TransactionSql` (only those have it),
22
- * otherwise `sql.begin(fn)`. postgres.js issues BEGIN (or SAVEPOINT), runs the callback with a
23
- * transaction-bound `sql`, then COMMIT, or ROLLBACK and rethrow when the callback throws.
24
- */
25
16
  async function transaction(sql, _depth, fn) {
26
17
  const { savepoint, begin } = sql;
27
18
  if (savepoint)
@@ -30,13 +21,7 @@ async function transaction(sql, _depth, fn) {
30
21
  return (await begin.call(sql, fn));
31
22
  throw new Error("typesql: sql.transaction() needs a postgres.js Sql, ReservedSql or TransactionSql (with begin or savepoint)");
32
23
  }
33
- /** How `createSql(sql)` runs queries and transactions. */
34
24
  export const driver = { executor, transaction };
35
- /**
36
- * Run a migration's statements in order inside one transaction (`sql.begin`), all or nothing.
37
- * Each statement goes through `unsafe` without parameters (simple protocol), so scripts with
38
- * `$$`-quoted function bodies work.
39
- */
40
25
  export async function migrate(sql, m) {
41
26
  await sql.begin(async (tx) => {
42
27
  for (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IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QACrE,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,WAAW,CACzB,GAAwB,EACxB,MAAc,EACd,EAA2C;IAE3C,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,GAE5B,CAAC;IACF,IAAI,SAAS;QAAE,OAAO,CAAC,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAM,CAAC;IAC3D,IAAI,KAAK;QAAE,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAM,CAAC;IACnD,MAAM,IAAI,KAAK,CACd,6GAA6G,CAC7G,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAmC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AAMhF,MAAM,CAAC,KAAK,UAAU,OAAO,CAC5B,GAA+B,EAC/B,CAAkB;IAElB,MAAM,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QAC5B,KAAK,MAAM,SAAS,IAAI,CAAC,CAAC,UAAU;YAAE,MAAM,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,18 +1,10 @@
1
- import type { RowKeys, TransactionalSql } from "@typesql/core";
1
+ import type { RowKeys } from "@typesql/core";
2
+ import { type TransactionalSql } from "@typesql/core/postgres";
2
3
  import { type PostgresJsQueryable } from "./client.js";
3
4
  import type { PostgresJsBigIntTypeMap, PostgresJsTypeMap } from "./type-map.js";
4
5
  export { executor, type MigrationSource, migrate, type PostgresJsQueryable, type PostgresJsRows, type PostgresJsTransactable, } from "./client.js";
5
6
  export type { PostgresJsBigIntTypeMap, PostgresJsParamTypeMap, PostgresJsTypeMap, } from "./type-map.js";
6
- /** What `createSql<DB>(sql)` returns: core's `Sql` under `PostgresJsTypeMap` (or `TM`), with `transaction(fn)`. */
7
7
  export type PostgresJsSql<DB, Keys extends RowKeys = "preserve", TM = PostgresJsTypeMap> = TransactionalSql<DB, TM, Keys>;
8
- /**
9
- * `createSql<DB>()` from core, pre-bound to `PostgresJsTypeMap` (default parsers: `int8` and `count(*)` are `string`).
10
- * The queries' `execute*` methods run on the postgres.js `sql` instance (or a `TransactionSql`,
11
- * `ReservedSql`), and `sql.transaction(fn)` runs `fn` with a `sql` bound to one transaction.
12
- * `{ rowKeys: "camelCase" }` camelCases the rows' keys, in the types and at runtime.
13
- * `{ bigint: true }` is for `postgres({ types: { bigint: postgres.BigInt } })` connections:
14
- * `int8` and `count(*)` are `bigint` (`PostgresJsBigIntTypeMap`).
15
- */
16
8
  export declare function createSql<DB>(sql: PostgresJsQueryable | undefined, options: {
17
9
  readonly rowKeys: "camelCase";
18
10
  readonly bigint: true;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAc,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAU,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEhF,OAAO,EACN,QAAQ,EACR,KAAK,eAAe,EACpB,OAAO,EACP,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,sBAAsB,GAC3B,MAAM,aAAa,CAAC;AACrB,YAAY,EACX,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,GACjB,MAAM,eAAe,CAAC;AAEvB,mHAAmH;AACnH,MAAM,MAAM,aAAa,CACxB,EAAE,EACF,IAAI,SAAS,OAAO,GAAG,UAAU,EACjC,EAAE,GAAG,iBAAiB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AW,CAAC,CAAC;AAClC,wBAAgB,SAAS,CAAC,EAAE,EAC3B,GAAG,CAAC,EAAE,mBAAmB,EACzB,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,GAClE,aAAa,CAAC,EAAE,CAAC,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { createTransactionalSql } from "@typesql/core/adapter";
2
+ import { postgres, } from "@typesql/core/postgres";
2
3
  import { driver } from "./client.js";
3
4
  export { executor, migrate, } from "./client.js";
4
5
  export function createSql(sql, options) {
5
- return createTransactionalSql(sql, driver, options);
6
+ return createTransactionalSql(postgres, sql, driver, options);
6
7
  }
7
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAA4B,MAAM,aAAa,CAAC;AAG/D,OAAO,EACN,QAAQ,EAER,OAAO,GAIP,MAAM,aAAa,CAAC;AA2CrB,MAAM,UAAU,SAAS,CACxB,GAAyB,EACzB,OAA8B;IAE9B,OAAO,sBAAsB,CAC5B,GAAG,EACH,MAAM,EACN,OAAO,CACP,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAEN,QAAQ,GAER,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAA4B,MAAM,aAAa,CAAC;AAG/D,OAAO,EACN,QAAQ,EAER,OAAO,GAIP,MAAM,aAAa,CAAC;AAiCrB,MAAM,UAAU,SAAS,CACxB,GAAyB,EACzB,OAA8B;IAE9B,OAAO,sBAAsB,CAK3B,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC"}
@@ -1,66 +1,18 @@
1
- import type { DefaultParamTypeMap, DefaultTypeMap } from "@typesql/core";
2
- /**
3
- * Canonical Postgres type name → TS type as postgres.js 3.x returns it with its default
4
- * parsers. Verified against `postgres/src/types.js` (3.4.9), which parses only:
5
- *
6
- * number int2 (21), int4 (23), oid (26), float4 (700), float8 (701)
7
- * boolean bool (16)
8
- * Date date (1082), timestamp (1114), timestamptz (1184) — all three via `new Date(x)`
9
- * unknown json (114), jsonb (3802): `JSON.parse`d
10
- * Buffer bytea (17)
11
- *
12
- * Everything else — including int8 (20) and numeric (1700) — is left as the text Postgres
13
- * sent, so it is `string`. Unlike `pg`, postgres.js has no parsers for interval, point and
14
- * circle, so those are strings here.
15
- *
16
- * This settles PLAN.md open question 3: postgres.js does return `Date` for `date` (and for
17
- * `timestamp`), the same as `pg`. Note that `date` has no time zone, and `new Date("2024-01-02")`
18
- * is parsed as UTC midnight (pg's `postgres-date` yields local midnight instead).
19
- *
20
- * Arrays: postgres.js fetches `pg_type` on connect (`fetch_types: true`, the default) and
21
- * registers an element-wise array parser for every array type, so core's `T[]` →
22
- * element-type[] mapping is exact (int8[] → string[], timestamptz[] → Date[], ...).
23
- */
1
+ import type { DefaultParamTypeMap, DefaultTypeMap } from "@typesql/core/postgres";
24
2
  export interface PostgresJsTypeMap extends Omit<DefaultTypeMap, "bytea" | "interval" | "point" | "circle" | "record" | "void"> {
25
- /** What parameters accept on top of the row types. */
26
3
  $params: PostgresJsParamTypeMap;
27
4
  bytea: Buffer;
28
- /** No default parser: the Postgres text form, e.g. `"1 day 02:00:00"`. */
29
5
  interval: string;
30
- /** No default parser: `"(1,2)"`. */
31
6
  point: string;
32
- /** No default parser: `"<(1,2),3>"`. */
33
7
  circle: string;
34
- /** Anonymous `ROW(...)` results: raw text such as `"(1,foo)"`. */
35
8
  record: string;
36
- /** `void`-returning functions (`pg_sleep`) yield an empty string. */
37
9
  void: string;
38
10
  }
39
- /**
40
- * TS types postgres.js parameters accept on top of the row type
41
- * (`PostgresJsTypeMap["$params"]`). Verified against `postgres/src/types.js` and `Bind` in
42
- * `connection.js` (3.4.9): a value is serialized by the serializer of the parameter type the
43
- * server reports, and types without one (int8, numeric, money, interval, …) with `'' + x`.
44
- *
45
- * int8, numeric, money number | bigint | string
46
- * date, timestamp, timestamptz Date | string | number: serialized as `new Date(x).toISOString()`,
47
- * so a string must be one JS `Date` parses, a number is epoch ms
48
- * interval string
49
- * bytea Uint8Array, besides `Buffer`
50
- *
51
- * `bool` takes only booleans: its serializer sends `'f'` for anything but `true`.
52
- */
53
11
  export interface PostgresJsParamTypeMap extends Omit<DefaultParamTypeMap, "date" | "timestamp" | "timestamptz"> {
54
12
  date: Date | string | number;
55
13
  timestamp: Date | string | number;
56
14
  timestamptz: Date | string | number;
57
15
  }
58
- /**
59
- * Type map for connections created with `postgres({ types: { bigint: postgres.BigInt } })`,
60
- * which registers a parser for int8 (20) that returns JS `bigint`. `count(*)`, `sum(int4)`
61
- * and `int8` columns become `bigint`; `int8[]` becomes `bigint[]`. Everything else is as in
62
- * `PostgresJsTypeMap`.
63
- */
64
16
  export interface PostgresJsBigIntTypeMap extends Omit<PostgresJsTypeMap, "int8"> {
65
17
  int8: bigint;
66
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"type-map.d.ts","sourceRoot":"","sources":["../src/type-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,iBAChB,SAAQ,IAAI,CACX,cAAc,EACd,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAC7D;IACD,sDAAsD;IACtD,OAAO,EAAE,sBAAsB,CAAC;IAChC,KAAK,E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vE,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;IAC7B,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,WAAW,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,uBAChB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC;CACb"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typesql/postgres",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "postgres.js adapter for TypeSQL.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@typesql/core": "0.7.5"
31
+ "@typesql/core": "0.8.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "postgres": ">=3"
@@ -36,8 +36,7 @@
36
36
  "devDependencies": {
37
37
  "postgres": "^3.4.9",
38
38
  "tsrs": "0.18.0-ts7.1.0-dev.20260929",
39
- "typescript": "7.1.0-beta",
40
- "vitest": "^5.0.4"
39
+ "typescript": "7.1.0-beta"
41
40
  },
42
41
  "homepage": "https://typesql.karsli.net/adapters/postgres",
43
42
  "bugs": {
@@ -58,7 +57,6 @@
58
57
  ],
59
58
  "scripts": {
60
59
  "build": "tsrs -p tsconfig.build.json",
61
- "typecheck": "tsrs -p tsconfig.json --noEmit",
62
- "test": "vitest run"
60
+ "typecheck": "tsrs -p tsconfig.json --noEmit"
63
61
  }
64
62
  }
package/src/client.ts CHANGED
@@ -1,18 +1,10 @@
1
1
  import type { Executor } from "@typesql/core";
2
2
  import type { SqlDriver } from "@typesql/core/adapter";
3
3
 
4
- /**
5
- * The shape of a resolved `sql.unsafe()` result the adapter relies on: an array with `count`
6
- * (`null` for statements without a count, such as DDL).
7
- */
8
4
  export type PostgresJsRows = readonly unknown[] & {
9
5
  readonly count: number | null;
10
6
  };
11
7
 
12
- /**
13
- * Anything with postgres.js' `unsafe(query, parameters)` method: the `Sql` instance,
14
- * a `TransactionSql` inside `begin`, a `ReservedSql`, or a fake in tests.
15
- */
16
8
  export interface PostgresJsQueryable {
17
9
  unsafe(
18
10
  query: string,
@@ -21,24 +13,18 @@ export interface PostgresJsQueryable {
21
13
  ): PromiseLike<PostgresJsRows>;
22
14
  }
23
15
 
24
- /** Anything with postgres.js' `begin(fn)`: the `Sql` instance or a `ReservedSql`. */
25
16
  export interface PostgresJsTransactable<
26
17
  Tx extends PostgresJsQueryable = PostgresJsQueryable,
27
18
  > {
28
19
  begin(fn: (tx: Tx) => Promise<unknown>): Promise<unknown>;
29
20
  }
30
21
 
31
- /** A `TransactionSql`'s `savepoint(fn)`. */
32
22
  interface PostgresJsSavepointable {
33
23
  savepoint(
34
24
  fn: (tx: PostgresJsQueryable) => Promise<unknown>,
35
25
  ): Promise<unknown>;
36
26
  }
37
27
 
38
- /**
39
- * An `Executor` for core's `q.execute()`: runs queries through `sql.unsafe` and resolves to
40
- * `{ rows, rowCount }` (postgres.js' `.count`, so `q.executeCount()` works).
41
- */
42
28
  export function executor(sql: PostgresJsQueryable): Executor {
43
29
  const run: Executor = async (text, values) => {
44
30
  const result = await sql.unsafe(text, Array.from(values));
@@ -55,11 +41,6 @@ export function executor(sql: PostgresJsQueryable): Executor {
55
41
  });
56
42
  }
57
43
 
58
- /**
59
- * Run `fn` inside a transaction: `tx.savepoint(fn)` on a `TransactionSql` (only those have it),
60
- * otherwise `sql.begin(fn)`. postgres.js issues BEGIN (or SAVEPOINT), runs the callback with a
61
- * transaction-bound `sql`, then COMMIT, or ROLLBACK and rethrow when the callback throws.
62
- */
63
44
  async function transaction<T>(
64
45
  sql: PostgresJsQueryable,
65
46
  _depth: number,
@@ -75,19 +56,12 @@ async function transaction<T>(
75
56
  );
76
57
  }
77
58
 
78
- /** How `createSql(sql)` runs queries and transactions. */
79
59
  export const driver: SqlDriver<PostgresJsQueryable> = { executor, transaction };
80
60
 
81
- /** Anything carrying an ordered list of DDL statements, e.g. a `migrations()` builder from core. */
82
61
  export interface MigrationSource {
83
62
  readonly statements: readonly string[];
84
63
  }
85
64
 
86
- /**
87
- * Run a migration's statements in order inside one transaction (`sql.begin`), all or nothing.
88
- * Each statement goes through `unsafe` without parameters (simple protocol), so scripts with
89
- * `$$`-quoted function bodies work.
90
- */
91
65
  export async function migrate<Tx extends PostgresJsQueryable>(
92
66
  sql: PostgresJsTransactable<Tx>,
93
67
  m: MigrationSource,
package/src/index.ts CHANGED
@@ -1,5 +1,10 @@
1
- import type { RowKeys, SqlOptions, TransactionalSql } from "@typesql/core";
1
+ import type { RowKeys, SqlOptions } from "@typesql/core";
2
2
  import { createTransactionalSql } from "@typesql/core/adapter";
3
+ import {
4
+ type Postgres,
5
+ postgres,
6
+ type TransactionalSql,
7
+ } from "@typesql/core/postgres";
3
8
  import { driver, type PostgresJsQueryable } from "./client.js";
4
9
  import type { PostgresJsBigIntTypeMap, PostgresJsTypeMap } from "./type-map.js";
5
10
 
@@ -17,26 +22,16 @@ export type {
17
22
  PostgresJsTypeMap,
18
23
  } from "./type-map.js";
19
24
 
20
- /** What `createSql<DB>(sql)` returns: core's `Sql` under `PostgresJsTypeMap` (or `TM`), with `transaction(fn)`. */
21
25
  export type PostgresJsSql<
22
26
  DB,
23
27
  Keys extends RowKeys = "preserve",
24
28
  TM = PostgresJsTypeMap,
25
29
  > = TransactionalSql<DB, TM, Keys>;
26
30
 
27
- /** `createSql`'s options: core's `rowKeys`, and `bigint: true` for a connection that parses `int8` as `bigint`. */
28
31
  interface PostgresJsSqlOptions extends SqlOptions {
29
32
  readonly bigint?: boolean;
30
33
  }
31
34
 
32
- /**
33
- * `createSql<DB>()` from core, pre-bound to `PostgresJsTypeMap` (default parsers: `int8` and `count(*)` are `string`).
34
- * The queries' `execute*` methods run on the postgres.js `sql` instance (or a `TransactionSql`,
35
- * `ReservedSql`), and `sql.transaction(fn)` runs `fn` with a `sql` bound to one transaction.
36
- * `{ rowKeys: "camelCase" }` camelCases the rows' keys, in the types and at runtime.
37
- * `{ bigint: true }` is for `postgres({ types: { bigint: postgres.BigInt } })` connections:
38
- * `int8` and `count(*)` are `bigint` (`PostgresJsBigIntTypeMap`).
39
- */
40
35
  export function createSql<DB>(
41
36
  sql: PostgresJsQueryable | undefined,
42
37
  options: { readonly rowKeys: "camelCase"; readonly bigint: true },
@@ -57,9 +52,10 @@ export function createSql<DB>(
57
52
  sql?: PostgresJsQueryable,
58
53
  options?: PostgresJsSqlOptions,
59
54
  ): PostgresJsSql<DB, RowKeys, PostgresJsTypeMap | PostgresJsBigIntTypeMap> {
60
- return createTransactionalSql<DB, PostgresJsTypeMap, PostgresJsQueryable>(
61
- sql,
62
- driver,
63
- options,
64
- );
55
+ return createTransactionalSql<
56
+ Postgres,
57
+ DB,
58
+ PostgresJsTypeMap,
59
+ PostgresJsQueryable
60
+ >(postgres, sql, driver, options);
65
61
  }
package/src/type-map.ts CHANGED
@@ -1,61 +1,22 @@
1
- import type { DefaultParamTypeMap, DefaultTypeMap } from "@typesql/core";
1
+ import type {
2
+ DefaultParamTypeMap,
3
+ DefaultTypeMap,
4
+ } from "@typesql/core/postgres";
2
5
 
3
- /**
4
- * Canonical Postgres type name → TS type as postgres.js 3.x returns it with its default
5
- * parsers. Verified against `postgres/src/types.js` (3.4.9), which parses only:
6
- *
7
- * number int2 (21), int4 (23), oid (26), float4 (700), float8 (701)
8
- * boolean bool (16)
9
- * Date date (1082), timestamp (1114), timestamptz (1184) — all three via `new Date(x)`
10
- * unknown json (114), jsonb (3802): `JSON.parse`d
11
- * Buffer bytea (17)
12
- *
13
- * Everything else — including int8 (20) and numeric (1700) — is left as the text Postgres
14
- * sent, so it is `string`. Unlike `pg`, postgres.js has no parsers for interval, point and
15
- * circle, so those are strings here.
16
- *
17
- * This settles PLAN.md open question 3: postgres.js does return `Date` for `date` (and for
18
- * `timestamp`), the same as `pg`. Note that `date` has no time zone, and `new Date("2024-01-02")`
19
- * is parsed as UTC midnight (pg's `postgres-date` yields local midnight instead).
20
- *
21
- * Arrays: postgres.js fetches `pg_type` on connect (`fetch_types: true`, the default) and
22
- * registers an element-wise array parser for every array type, so core's `T[]` →
23
- * element-type[] mapping is exact (int8[] → string[], timestamptz[] → Date[], ...).
24
- */
25
6
  export interface PostgresJsTypeMap
26
7
  extends Omit<
27
8
  DefaultTypeMap,
28
9
  "bytea" | "interval" | "point" | "circle" | "record" | "void"
29
10
  > {
30
- /** What parameters accept on top of the row types. */
31
11
  $params: PostgresJsParamTypeMap;
32
12
  bytea: Buffer;
33
- /** No default parser: the Postgres text form, e.g. `"1 day 02:00:00"`. */
34
13
  interval: string;
35
- /** No default parser: `"(1,2)"`. */
36
14
  point: string;
37
- /** No default parser: `"<(1,2),3>"`. */
38
15
  circle: string;
39
- /** Anonymous `ROW(...)` results: raw text such as `"(1,foo)"`. */
40
16
  record: string;
41
- /** `void`-returning functions (`pg_sleep`) yield an empty string. */
42
17
  void: string;
43
18
  }
44
19
 
45
- /**
46
- * TS types postgres.js parameters accept on top of the row type
47
- * (`PostgresJsTypeMap["$params"]`). Verified against `postgres/src/types.js` and `Bind` in
48
- * `connection.js` (3.4.9): a value is serialized by the serializer of the parameter type the
49
- * server reports, and types without one (int8, numeric, money, interval, …) with `'' + x`.
50
- *
51
- * int8, numeric, money number | bigint | string
52
- * date, timestamp, timestamptz Date | string | number: serialized as `new Date(x).toISOString()`,
53
- * so a string must be one JS `Date` parses, a number is epoch ms
54
- * interval string
55
- * bytea Uint8Array, besides `Buffer`
56
- *
57
- * `bool` takes only booleans: its serializer sends `'f'` for anything but `true`.
58
- */
59
20
  export interface PostgresJsParamTypeMap
60
21
  extends Omit<DefaultParamTypeMap, "date" | "timestamp" | "timestamptz"> {
61
22
  date: Date | string | number;
@@ -63,12 +24,6 @@ export interface PostgresJsParamTypeMap
63
24
  timestamptz: Date | string | number;
64
25
  }
65
26
 
66
- /**
67
- * Type map for connections created with `postgres({ types: { bigint: postgres.BigInt } })`,
68
- * which registers a parser for int8 (20) that returns JS `bigint`. `count(*)`, `sum(int4)`
69
- * and `int8` columns become `bigint`; `int8[]` becomes `bigint[]`. Everything else is as in
70
- * `PostgresJsTypeMap`.
71
- */
72
27
  export interface PostgresJsBigIntTypeMap
73
28
  extends Omit<PostgresJsTypeMap, "int8"> {
74
29
  int8: bigint;