durcno 1.0.0-alpha.0
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/LICENSE +201 -0
- package/README.md +56 -0
- package/dist/bin.cjs +13522 -0
- package/dist/src/_virtual/_rolldown/runtime.mjs +28 -0
- package/dist/src/cli/helpers.mjs +16 -0
- package/dist/src/columns/bigint.d.mts +19 -0
- package/dist/src/columns/bigint.mjs +32 -0
- package/dist/src/columns/bigserial.d.mts +24 -0
- package/dist/src/columns/bigserial.mjs +35 -0
- package/dist/src/columns/boolean.d.mts +19 -0
- package/dist/src/columns/boolean.mjs +31 -0
- package/dist/src/columns/bytea.d.mts +19 -0
- package/dist/src/columns/bytea.mjs +33 -0
- package/dist/src/columns/char.d.mts +32 -0
- package/dist/src/columns/char.mjs +44 -0
- package/dist/src/columns/cidr.d.mts +19 -0
- package/dist/src/columns/cidr.mjs +31 -0
- package/dist/src/columns/common.d.mts +233 -0
- package/dist/src/columns/common.mjs +276 -0
- package/dist/src/columns/date.d.mts +19 -0
- package/dist/src/columns/date.mjs +32 -0
- package/dist/src/columns/enum.d.mts +21 -0
- package/dist/src/columns/enum.mjs +35 -0
- package/dist/src/columns/inet.d.mts +19 -0
- package/dist/src/columns/inet.mjs +36 -0
- package/dist/src/columns/integer.d.mts +19 -0
- package/dist/src/columns/integer.mjs +32 -0
- package/dist/src/columns/json.d.mts +52 -0
- package/dist/src/columns/json.mjs +67 -0
- package/dist/src/columns/jsonb.d.mts +53 -0
- package/dist/src/columns/jsonb.mjs +68 -0
- package/dist/src/columns/macaddr.d.mts +19 -0
- package/dist/src/columns/macaddr.mjs +31 -0
- package/dist/src/columns/numeric.d.mts +42 -0
- package/dist/src/columns/numeric.mjs +57 -0
- package/dist/src/columns/postgis/geography/index.d.mts +18 -0
- package/dist/src/columns/postgis/geography/index.mjs +17 -0
- package/dist/src/columns/postgis/geography/linestring.d.mts +38 -0
- package/dist/src/columns/postgis/geography/linestring.mjs +70 -0
- package/dist/src/columns/postgis/geography/multilinestring.d.mts +39 -0
- package/dist/src/columns/postgis/geography/multilinestring.mjs +70 -0
- package/dist/src/columns/postgis/geography/multipoint.d.mts +38 -0
- package/dist/src/columns/postgis/geography/multipoint.mjs +70 -0
- package/dist/src/columns/postgis/geography/multipolygon.d.mts +40 -0
- package/dist/src/columns/postgis/geography/multipolygon.mjs +70 -0
- package/dist/src/columns/postgis/geography/point.d.mts +36 -0
- package/dist/src/columns/postgis/geography/point.mjs +69 -0
- package/dist/src/columns/postgis/geography/polygon.d.mts +39 -0
- package/dist/src/columns/postgis/geography/polygon.mjs +70 -0
- package/dist/src/columns/serial.d.mts +24 -0
- package/dist/src/columns/serial.mjs +35 -0
- package/dist/src/columns/smallint.d.mts +19 -0
- package/dist/src/columns/smallint.mjs +32 -0
- package/dist/src/columns/smallserial.d.mts +24 -0
- package/dist/src/columns/smallserial.mjs +35 -0
- package/dist/src/columns/text.d.mts +19 -0
- package/dist/src/columns/text.mjs +30 -0
- package/dist/src/columns/time.d.mts +44 -0
- package/dist/src/columns/time.mjs +47 -0
- package/dist/src/columns/timestamp.d.mts +44 -0
- package/dist/src/columns/timestamp.mjs +47 -0
- package/dist/src/columns/uuid.d.mts +33 -0
- package/dist/src/columns/uuid.mjs +44 -0
- package/dist/src/columns/varchar.d.mts +32 -0
- package/dist/src/columns/varchar.mjs +44 -0
- package/dist/src/connectors/bun.d.mts +18 -0
- package/dist/src/connectors/bun.mjs +97 -0
- package/dist/src/connectors/common.d.mts +148 -0
- package/dist/src/connectors/common.mjs +65 -0
- package/dist/src/connectors/pg.d.mts +18 -0
- package/dist/src/connectors/pg.mjs +103 -0
- package/dist/src/connectors/pglite.d.mts +19 -0
- package/dist/src/connectors/pglite.mjs +94 -0
- package/dist/src/connectors/postgres.d.mts +18 -0
- package/dist/src/connectors/postgres.mjs +93 -0
- package/dist/src/constraints/check.d.mts +88 -0
- package/dist/src/constraints/check.mjs +307 -0
- package/dist/src/constraints/primary-key.d.mts +28 -0
- package/dist/src/constraints/primary-key.mjs +36 -0
- package/dist/src/constraints/unique.d.mts +28 -0
- package/dist/src/constraints/unique.mjs +36 -0
- package/dist/src/db.d.mts +180 -0
- package/dist/src/db.mjs +191 -0
- package/dist/src/entity.mjs +23 -0
- package/dist/src/enumtype.d.mts +27 -0
- package/dist/src/enumtype.mjs +42 -0
- package/dist/src/filters/array.d.mts +97 -0
- package/dist/src/filters/array.mjs +150 -0
- package/dist/src/filters/custom.d.mts +12 -0
- package/dist/src/filters/custom.mjs +7 -0
- package/dist/src/filters/index.d.mts +155 -0
- package/dist/src/filters/index.mjs +318 -0
- package/dist/src/functions/index.d.mts +24 -0
- package/dist/src/functions/index.mjs +29 -0
- package/dist/src/index.d.mts +129 -0
- package/dist/src/index.mjs +78 -0
- package/dist/src/indexes.d.mts +31 -0
- package/dist/src/indexes.mjs +43 -0
- package/dist/src/migration/consts.d.mts +8 -0
- package/dist/src/migration/consts.mjs +8 -0
- package/dist/src/migration/ddl.d.mts +747 -0
- package/dist/src/migration/ddl.mjs +1084 -0
- package/dist/src/migration/index.d.mts +15 -0
- package/dist/src/migration/index.mjs +5 -0
- package/dist/src/migration/snapshot.d.mts +169 -0
- package/dist/src/migration/snapshot.mjs +123 -0
- package/dist/src/migration/statement.d.mts +89 -0
- package/dist/src/migration/statement.mjs +61 -0
- package/dist/src/models.d.mts +34 -0
- package/dist/src/models.mjs +27 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.mjs +126 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.mjs +29 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.mjs +165 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.mjs +92 -0
- package/dist/src/query-builders/aggregates.d.mts +20 -0
- package/dist/src/query-builders/aggregates.mjs +43 -0
- package/dist/src/query-builders/count.d.mts +19 -0
- package/dist/src/query-builders/count.mjs +36 -0
- package/dist/src/query-builders/delete.d.mts +19 -0
- package/dist/src/query-builders/delete.mjs +57 -0
- package/dist/src/query-builders/distinct.d.mts +19 -0
- package/dist/src/query-builders/distinct.mjs +42 -0
- package/dist/src/query-builders/exists.d.mts +19 -0
- package/dist/src/query-builders/exists.mjs +37 -0
- package/dist/src/query-builders/first.d.mts +17 -0
- package/dist/src/query-builders/first.mjs +46 -0
- package/dist/src/query-builders/insert-returning.d.mts +16 -0
- package/dist/src/query-builders/insert-returning.mjs +63 -0
- package/dist/src/query-builders/insert.d.mts +22 -0
- package/dist/src/query-builders/insert.mjs +93 -0
- package/dist/src/query-builders/orderby-clause.d.mts +14 -0
- package/dist/src/query-builders/orderby-clause.mjs +20 -0
- package/dist/src/query-builders/pre.d.mts +36 -0
- package/dist/src/query-builders/pre.mjs +60 -0
- package/dist/src/query-builders/query-promise.d.mts +14 -0
- package/dist/src/query-builders/query-promise.mjs +21 -0
- package/dist/src/query-builders/query.d.mts +14 -0
- package/dist/src/query-builders/query.mjs +17 -0
- package/dist/src/query-builders/raw.d.mts +14 -0
- package/dist/src/query-builders/raw.mjs +26 -0
- package/dist/src/query-builders/rq.d.mts +36 -0
- package/dist/src/query-builders/rq.mjs +231 -0
- package/dist/src/query-builders/select.d.mts +48 -0
- package/dist/src/query-builders/select.mjs +118 -0
- package/dist/src/query-builders/update.d.mts +24 -0
- package/dist/src/query-builders/update.mjs +99 -0
- package/dist/src/sequence.d.mts +48 -0
- package/dist/src/sequence.mjs +53 -0
- package/dist/src/sql.d.mts +15 -0
- package/dist/src/sql.mjs +36 -0
- package/dist/src/symbols.d.mts +4 -0
- package/dist/src/symbols.mjs +4 -0
- package/dist/src/table.d.mts +144 -0
- package/dist/src/table.mjs +134 -0
- package/dist/src/types.d.mts +4 -0
- package/dist/src/utils.mjs +10 -0
- package/dist/src/validators/zod.d.mts +23 -0
- package/dist/src/validators/zod.mjs +27 -0
- package/dist/src/wkx/binaryreader.mjs +56 -0
- package/dist/src/wkx/binarywriter.mjs +110 -0
- package/dist/src/wkx/geometry.mjs +101 -0
- package/dist/src/wkx/geometrycollection.mjs +113 -0
- package/dist/src/wkx/index.mjs +18 -0
- package/dist/src/wkx/linestring.mjs +124 -0
- package/dist/src/wkx/multilinestring.mjs +133 -0
- package/dist/src/wkx/multipoint.mjs +120 -0
- package/dist/src/wkx/multipolygon.mjs +155 -0
- package/dist/src/wkx/parser.mjs +183 -0
- package/dist/src/wkx/point.mjs +159 -0
- package/dist/src/wkx/polygon.mjs +189 -0
- package/dist/src/wkx/types.mjs +37 -0
- package/dist/src/wkx/wktparser.mjs +109 -0
- package/dist/src/wkx/zigzag.mjs +18 -0
- package/package.json +100 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sql } from "../sql.mjs";
|
|
2
|
+
//#region src/functions/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns a Sql object that represents the SQL function `now()`.
|
|
5
|
+
* @returns Sql
|
|
6
|
+
*/
|
|
7
|
+
function now() {
|
|
8
|
+
return sql`now()`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns a Sql object that represents the SQL function `gen_random_uuid()` (UUID v4).
|
|
12
|
+
*
|
|
13
|
+
* Note: Requires the pgcrypto extension in PostgreSQL.
|
|
14
|
+
* @returns Sql
|
|
15
|
+
*/
|
|
16
|
+
function uuidv4() {
|
|
17
|
+
return sql`gen_random_uuid()`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns a Sql object that represents the SQL function `uuid_generate_v7()` (UUID v7).
|
|
21
|
+
*
|
|
22
|
+
* Note: Requires the uuid-ossp extension in PostgreSQL.
|
|
23
|
+
* @returns Sql
|
|
24
|
+
*/
|
|
25
|
+
function uuidv7() {
|
|
26
|
+
return sql`uuid_generate_v7()`;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { now, uuidv4, uuidv7 };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Query } from "./query-builders/query.mjs";
|
|
2
|
+
import { asc, desc } from "./query-builders/orderby-clause.mjs";
|
|
3
|
+
import { Sql, sql } from "./sql.mjs";
|
|
4
|
+
import { Filter } from "./filters/custom.mjs";
|
|
5
|
+
import { and, eq, gt, gte, isIn, isNotNull, isNull, lt, lte, ne, or } from "./filters/index.mjs";
|
|
6
|
+
import { database } from "./db.mjs";
|
|
7
|
+
import { Arg, prequery } from "./query-builders/pre.mjs";
|
|
8
|
+
import { Column, ColumnConfig, notNull, primaryKey, unique } from "./columns/common.mjs";
|
|
9
|
+
import { PrimaryKeyConstraint, primaryKeyConstraint } from "./constraints/primary-key.mjs";
|
|
10
|
+
import { UniqueConstraint, uniqueConstraint } from "./constraints/unique.mjs";
|
|
11
|
+
import { index, uniqueIndex } from "./indexes.mjs";
|
|
12
|
+
import { AnyColumn, AnyTableColumn, Table, TableColumn, fk, many, one, relations, table } from "./table.mjs";
|
|
13
|
+
import { Sequence, SequenceOptions, sequence } from "./sequence.mjs";
|
|
14
|
+
import { bigint } from "./columns/bigint.mjs";
|
|
15
|
+
import { bigserial } from "./columns/bigserial.mjs";
|
|
16
|
+
import { boolean } from "./columns/boolean.mjs";
|
|
17
|
+
import { bytea } from "./columns/bytea.mjs";
|
|
18
|
+
import { char } from "./columns/char.mjs";
|
|
19
|
+
import { cidr } from "./columns/cidr.mjs";
|
|
20
|
+
import { date } from "./columns/date.mjs";
|
|
21
|
+
import { Enum, enumtype } from "./enumtype.mjs";
|
|
22
|
+
import { enumed } from "./columns/enum.mjs";
|
|
23
|
+
import { inet } from "./columns/inet.mjs";
|
|
24
|
+
import { integer } from "./columns/integer.mjs";
|
|
25
|
+
import { json } from "./columns/json.mjs";
|
|
26
|
+
import { jsonb } from "./columns/jsonb.mjs";
|
|
27
|
+
import { macaddr } from "./columns/macaddr.mjs";
|
|
28
|
+
import { numeric } from "./columns/numeric.mjs";
|
|
29
|
+
import { geography } from "./columns/postgis/geography/index.mjs";
|
|
30
|
+
import { serial } from "./columns/serial.mjs";
|
|
31
|
+
import { smallint } from "./columns/smallint.mjs";
|
|
32
|
+
import { smallserial } from "./columns/smallserial.mjs";
|
|
33
|
+
import { text } from "./columns/text.mjs";
|
|
34
|
+
import { time } from "./columns/time.mjs";
|
|
35
|
+
import { timestamp } from "./columns/timestamp.mjs";
|
|
36
|
+
import { UuidVersion, uuid } from "./columns/uuid.mjs";
|
|
37
|
+
import { varchar } from "./columns/varchar.mjs";
|
|
38
|
+
import { arrayAll, arrayContainedBy, arrayContains, arrayHas, arrayOverlaps } from "./filters/array.mjs";
|
|
39
|
+
import { now, uuidv4, uuidv7 } from "./functions/index.mjs";
|
|
40
|
+
import { Migrations, pk } from "./models.mjs";
|
|
41
|
+
import { Connector } from "./connectors/common.mjs";
|
|
42
|
+
import { ConnectionOptions } from "node:tls";
|
|
43
|
+
|
|
44
|
+
//#region src/index.d.ts
|
|
45
|
+
declare const $: {
|
|
46
|
+
isTable: (value: unknown) => value is Table<string, string, Record<string, AnyColumn>>;
|
|
47
|
+
isEnum: (value: unknown) => value is Enum<string, readonly [string, ...string[]]>;
|
|
48
|
+
isSequence: (value: unknown) => value is Sequence<SequenceOptions>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* A Durcno setup object containing the connector instance and configuration.
|
|
52
|
+
*
|
|
53
|
+
* Returned by `defineConfig()` and consumed by the `database()` function
|
|
54
|
+
* and CLI commands.
|
|
55
|
+
*/
|
|
56
|
+
type DurcnoSetup<T extends Connector = Connector> = {
|
|
57
|
+
/** The connector instance for database operations. */connector: T; /** The configuration options passed to `defineConfig`. */
|
|
58
|
+
config: Config;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Define a Durcno configuration.
|
|
62
|
+
*
|
|
63
|
+
* This is the recommended way to create your `durcno.config.ts` file.
|
|
64
|
+
* Pass the connector class for your database driver and the configuration options.
|
|
65
|
+
*
|
|
66
|
+
* @param Connector - The connector class to use (e.g., `PgConnector`, `PostgresConnector`, `BunConnector`, `PgLiteConnector`).
|
|
67
|
+
* @param config - The database configuration including connection credentials and pool settings.
|
|
68
|
+
* @returns A setup object containing the connector instance and the config options.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { defineConfig } from "durcno";
|
|
73
|
+
* import { PgConnector } from "durcno/connectors/pg";
|
|
74
|
+
*
|
|
75
|
+
* export default defineConfig(PgConnector, {
|
|
76
|
+
* schema: "db/schema.ts",
|
|
77
|
+
* out: "migrations",
|
|
78
|
+
* dbCredentials: {
|
|
79
|
+
* url: process.env.DATABASE_URL!,
|
|
80
|
+
* },
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function defineConfig<T extends Connector>(ConnectorClass: new (config: Config) => T, config: Config): DurcnoSetup<T>;
|
|
85
|
+
type Config = {
|
|
86
|
+
/**
|
|
87
|
+
* The relative path to the database schema file.
|
|
88
|
+
*/
|
|
89
|
+
schema: string;
|
|
90
|
+
/**
|
|
91
|
+
* The relative path to the output directory for generated migrations.
|
|
92
|
+
* @default "migrations"
|
|
93
|
+
*/
|
|
94
|
+
out?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Database connection credentials.
|
|
97
|
+
*/
|
|
98
|
+
dbCredentials: ({
|
|
99
|
+
host: string;
|
|
100
|
+
port?: number;
|
|
101
|
+
user: string;
|
|
102
|
+
password?: string;
|
|
103
|
+
database: string;
|
|
104
|
+
ssl?: boolean | "require" | "allow" | "prefer" | "verify-full" | ConnectionOptions;
|
|
105
|
+
} & {}) | {
|
|
106
|
+
url: string;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Connection pool configuration.
|
|
110
|
+
*/
|
|
111
|
+
pool?: {
|
|
112
|
+
/**
|
|
113
|
+
* Maximum number of connections in the `db` pool.
|
|
114
|
+
* @default 10
|
|
115
|
+
*/
|
|
116
|
+
max?: number;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
declare global {
|
|
120
|
+
type Key = string | number | symbol;
|
|
121
|
+
type Valueof<T> = T extends any ? T[keyof T] : never;
|
|
122
|
+
type SelfOrArray<T> = T | T[];
|
|
123
|
+
type SelfOrReadonly<T> = T | Readonly<T>;
|
|
124
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
125
|
+
type Is<T, U> = T extends U ? true : false;
|
|
126
|
+
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
export { $, type AnyColumn, type AnyTableColumn, Arg, Column, type ColumnConfig, Config, DurcnoSetup, Filter, Migrations, PrimaryKeyConstraint, type Query, Sql, type TableColumn, UniqueConstraint, type UuidVersion, and, arrayAll, arrayContainedBy, arrayContains, arrayHas, arrayOverlaps, asc, bigint, bigserial, boolean, bytea, char, cidr, database, date, defineConfig, desc, enumed, enumtype, eq, fk, geography, gt, gte, index, inet, integer, isIn, isNotNull, isNull, json, jsonb, lt, lte, macaddr, many, ne, notNull, now, numeric, one, or, pk, prequery, primaryKey, primaryKeyConstraint, relations, sequence, serial, smallint, smallserial, sql, table, text, time, timestamp, unique, uniqueConstraint, uniqueIndex, uuid, uuidv4, uuidv7, varchar };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Arg, prequery } from "./query-builders/pre.mjs";
|
|
2
|
+
import { Column, notNull, primaryKey, unique } from "./columns/common.mjs";
|
|
3
|
+
import { is } from "./entity.mjs";
|
|
4
|
+
import { Sql, sql } from "./sql.mjs";
|
|
5
|
+
import { bigint } from "./columns/bigint.mjs";
|
|
6
|
+
import { bigserial } from "./columns/bigserial.mjs";
|
|
7
|
+
import { boolean } from "./columns/boolean.mjs";
|
|
8
|
+
import { bytea } from "./columns/bytea.mjs";
|
|
9
|
+
import { char } from "./columns/char.mjs";
|
|
10
|
+
import { cidr } from "./columns/cidr.mjs";
|
|
11
|
+
import { date } from "./columns/date.mjs";
|
|
12
|
+
import { enumed } from "./columns/enum.mjs";
|
|
13
|
+
import { inet } from "./columns/inet.mjs";
|
|
14
|
+
import { integer } from "./columns/integer.mjs";
|
|
15
|
+
import { json } from "./columns/json.mjs";
|
|
16
|
+
import { jsonb } from "./columns/jsonb.mjs";
|
|
17
|
+
import { macaddr } from "./columns/macaddr.mjs";
|
|
18
|
+
import { numeric } from "./columns/numeric.mjs";
|
|
19
|
+
import { geography } from "./columns/postgis/geography/index.mjs";
|
|
20
|
+
import { serial } from "./columns/serial.mjs";
|
|
21
|
+
import { smallint } from "./columns/smallint.mjs";
|
|
22
|
+
import { smallserial } from "./columns/smallserial.mjs";
|
|
23
|
+
import { text } from "./columns/text.mjs";
|
|
24
|
+
import { time } from "./columns/time.mjs";
|
|
25
|
+
import { timestamp } from "./columns/timestamp.mjs";
|
|
26
|
+
import { uuid } from "./columns/uuid.mjs";
|
|
27
|
+
import { varchar } from "./columns/varchar.mjs";
|
|
28
|
+
import { PrimaryKeyConstraint, primaryKeyConstraint } from "./constraints/primary-key.mjs";
|
|
29
|
+
import { UniqueConstraint, uniqueConstraint } from "./constraints/unique.mjs";
|
|
30
|
+
import { Table, fk, many, one, relations, table } from "./table.mjs";
|
|
31
|
+
import { database } from "./db.mjs";
|
|
32
|
+
import { Enum, enumtype } from "./enumtype.mjs";
|
|
33
|
+
import { Filter } from "./filters/custom.mjs";
|
|
34
|
+
import { arrayAll, arrayContainedBy, arrayContains, arrayHas, arrayOverlaps } from "./filters/array.mjs";
|
|
35
|
+
import { and, eq, gt, gte, isIn, isNotNull, isNull, lt, lte, ne, or } from "./filters/index.mjs";
|
|
36
|
+
import { now, uuidv4, uuidv7 } from "./functions/index.mjs";
|
|
37
|
+
import { index, uniqueIndex } from "./indexes.mjs";
|
|
38
|
+
import { Migrations, pk } from "./models.mjs";
|
|
39
|
+
import { asc, desc } from "./query-builders/orderby-clause.mjs";
|
|
40
|
+
import { Sequence, sequence } from "./sequence.mjs";
|
|
41
|
+
//#region src/index.ts
|
|
42
|
+
const $ = {
|
|
43
|
+
isTable: (value) => is(value, Table),
|
|
44
|
+
isEnum: (value) => is(value, Enum),
|
|
45
|
+
isSequence: (value) => is(value, Sequence)
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Define a Durcno configuration.
|
|
49
|
+
*
|
|
50
|
+
* This is the recommended way to create your `durcno.config.ts` file.
|
|
51
|
+
* Pass the connector class for your database driver and the configuration options.
|
|
52
|
+
*
|
|
53
|
+
* @param Connector - The connector class to use (e.g., `PgConnector`, `PostgresConnector`, `BunConnector`, `PgLiteConnector`).
|
|
54
|
+
* @param config - The database configuration including connection credentials and pool settings.
|
|
55
|
+
* @returns A setup object containing the connector instance and the config options.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { defineConfig } from "durcno";
|
|
60
|
+
* import { PgConnector } from "durcno/connectors/pg";
|
|
61
|
+
*
|
|
62
|
+
* export default defineConfig(PgConnector, {
|
|
63
|
+
* schema: "db/schema.ts",
|
|
64
|
+
* out: "migrations",
|
|
65
|
+
* dbCredentials: {
|
|
66
|
+
* url: process.env.DATABASE_URL!,
|
|
67
|
+
* },
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
function defineConfig(ConnectorClass, config) {
|
|
72
|
+
return {
|
|
73
|
+
connector: new ConnectorClass(config),
|
|
74
|
+
config
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { $, Arg, Column, Filter, Migrations, PrimaryKeyConstraint, Sql, UniqueConstraint, and, arrayAll, arrayContainedBy, arrayContains, arrayHas, arrayOverlaps, asc, bigint, bigserial, boolean, bytea, char, cidr, database, date, defineConfig, desc, enumed, enumtype, eq, fk, geography, gt, gte, index, inet, integer, isIn, isNotNull, isNull, json, jsonb, lt, lte, macaddr, many, ne, notNull, now, numeric, one, or, pk, prequery, primaryKey, primaryKeyConstraint, relations, sequence, serial, smallint, smallserial, sql, table, text, time, timestamp, unique, uniqueConstraint, uniqueIndex, uuid, uuidv4, uuidv7, varchar };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AnyColumn, StdTable, TableColumn } from "./table.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/indexes.d.ts
|
|
4
|
+
type IndexType = "btree" | "hash" | "gist" | "spgist" | "gin" | "brin" | "hnsw" | "ivfflat" | (string & {});
|
|
5
|
+
declare class Index<Col extends AnyColumn> {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(columns: TableColumn<string, string, Key, Col>[], using: IndexType, unique: boolean);
|
|
8
|
+
_: {
|
|
9
|
+
getColumns: () => TableColumn<string, string, Key, Col>[];
|
|
10
|
+
getUsing: () => IndexType;
|
|
11
|
+
getUnique: () => boolean;
|
|
12
|
+
getName: (table: StdTable) => string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Change the index type to use.
|
|
16
|
+
*
|
|
17
|
+
* SQL equivalent: `USING <index_type>`
|
|
18
|
+
* ```sql
|
|
19
|
+
* CREATE INDEX ON table_name (column)
|
|
20
|
+
* USING gist;
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param using - the index method to use (gin, gist, etc.)
|
|
24
|
+
* @returns the current `Index` instance for chaining
|
|
25
|
+
*/
|
|
26
|
+
using(using: IndexType): this;
|
|
27
|
+
}
|
|
28
|
+
declare function index<Col extends AnyColumn>(columns: TableColumn<string, string, Key, Col>[], using?: IndexType): Index<Col>;
|
|
29
|
+
declare function uniqueIndex<Col extends AnyColumn>(columns: TableColumn<string, string, Key, Col>[], using?: IndexType): Index<Col>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { Index, IndexType, index, uniqueIndex };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/indexes.ts
|
|
2
|
+
var Index = class {
|
|
3
|
+
#columns;
|
|
4
|
+
#using;
|
|
5
|
+
#unique;
|
|
6
|
+
constructor(columns, using, unique) {
|
|
7
|
+
this.#columns = columns;
|
|
8
|
+
this.#using = using;
|
|
9
|
+
this.#unique = unique;
|
|
10
|
+
}
|
|
11
|
+
_ = {
|
|
12
|
+
getColumns: () => this.#columns,
|
|
13
|
+
getUsing: () => this.#using,
|
|
14
|
+
getUnique: () => this.#unique,
|
|
15
|
+
getName: (table) => {
|
|
16
|
+
return `${table._.name}_${this.#columns.map((col) => col.nameSnake).join("_")}_index`;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Change the index type to use.
|
|
21
|
+
*
|
|
22
|
+
* SQL equivalent: `USING <index_type>`
|
|
23
|
+
* ```sql
|
|
24
|
+
* CREATE INDEX ON table_name (column)
|
|
25
|
+
* USING gist;
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param using - the index method to use (gin, gist, etc.)
|
|
29
|
+
* @returns the current `Index` instance for chaining
|
|
30
|
+
*/
|
|
31
|
+
using(using) {
|
|
32
|
+
this.#using = using;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
function index(columns, using) {
|
|
37
|
+
return new Index(columns, using ?? "btree", false);
|
|
38
|
+
}
|
|
39
|
+
function uniqueIndex(columns, using) {
|
|
40
|
+
return new Index(columns, using ?? "btree", true);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { index, uniqueIndex };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/migration/consts.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Regex for ISO timestamp like format with Windows-compatible separators
|
|
4
|
+
* (e.g., 2024-01-15T10-30-45.123Z ; uses `-` instead of `:` for time)
|
|
5
|
+
*/
|
|
6
|
+
declare const MIGRATION_NAME_REGEX: RegExp;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { MIGRATION_NAME_REGEX };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/migration/consts.ts
|
|
2
|
+
/**
|
|
3
|
+
* Regex for ISO timestamp like format with Windows-compatible separators
|
|
4
|
+
* (e.g., 2024-01-15T10-30-45.123Z ; uses `-` instead of `:` for time)
|
|
5
|
+
*/
|
|
6
|
+
const MIGRATION_NAME_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}\.\d{3}Z$/;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { MIGRATION_NAME_REGEX };
|