drizzle-orm 0.27.3-e080bed → 0.28.0-5dd9190
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/{alias-5aeeb2f5.cjs → alias-3f5ac719.cjs} +267 -142
- package/alias-3f5ac719.cjs.map +1 -0
- package/{alias-6eaa2e87.mjs → alias-7164ff43.mjs} +223 -126
- package/alias-7164ff43.mjs.map +1 -0
- package/aws-data-api/pg/index.cjs +1 -1
- package/aws-data-api/pg/index.d.ts +4 -4
- package/aws-data-api/pg/index.mjs +2 -2
- package/aws-data-api/pg/migrator.d.ts +4 -4
- package/better-sqlite3/index.cjs +2 -2
- package/better-sqlite3/index.d.ts +5 -5
- package/better-sqlite3/index.mjs +2 -2
- package/better-sqlite3/migrator.d.ts +5 -5
- package/bun-sqlite/index.cjs +2 -2
- package/bun-sqlite/index.d.ts +5 -5
- package/bun-sqlite/index.mjs +2 -2
- package/bun-sqlite/migrator.d.ts +5 -5
- package/column.d-9d2f4045.d.ts +1151 -0
- package/d1/index.cjs +2 -2
- package/d1/index.d.ts +5 -5
- package/d1/index.mjs +2 -2
- package/d1/migrator.d.ts +5 -5
- package/{driver.d-58d095ec.d.ts → driver.d-055d4782.d.ts} +2 -2
- package/{driver.d-d2f034d7.d.ts → driver.d-20707624.d.ts} +2 -2
- package/{driver.d-7f308b1e.d.ts → driver.d-ab0f126f.d.ts} +2 -2
- package/{driver.d-f55c470d.d.ts → driver.d-b8dd753f.d.ts} +2 -2
- package/{driver.d-28b0b849.d.ts → driver.d-c4dd56f7.d.ts} +2 -2
- package/{driver.d-53ed595e.d.ts → driver.d-eb654ed5.d.ts} +2 -2
- package/index.cjs +3 -3
- package/index.d.ts +4 -4
- package/index.mjs +2 -2
- package/knex/index.d.ts +1 -1
- package/kysely/index.d.ts +1 -1
- package/libsql/index.cjs +2 -2
- package/libsql/index.d.ts +5 -5
- package/libsql/index.mjs +2 -2
- package/libsql/migrator.d.ts +5 -5
- package/mysql-core/index.cjs +57 -21
- package/mysql-core/index.cjs.map +1 -1
- package/mysql-core/index.d.ts +184 -344
- package/mysql-core/index.mjs +58 -22
- package/mysql-core/index.mjs.map +1 -1
- package/mysql2/index.cjs +14 -10
- package/mysql2/index.cjs.map +1 -1
- package/mysql2/index.d.ts +16 -12
- package/mysql2/index.mjs +15 -11
- package/mysql2/index.mjs.map +1 -1
- package/mysql2/migrator.d.ts +4 -4
- package/neon-http/index.cjs +1 -1
- package/neon-http/index.d.ts +4 -4
- package/neon-http/index.mjs +2 -2
- package/neon-http/migrator.cjs +1 -1
- package/neon-http/migrator.d.ts +4 -4
- package/neon-http/migrator.mjs +1 -1
- package/neon-serverless/index.cjs +1 -1
- package/neon-serverless/index.d.ts +4 -4
- package/neon-serverless/index.mjs +2 -2
- package/neon-serverless/migrator.d.ts +4 -4
- package/node-postgres/index.cjs +1 -1
- package/node-postgres/index.d.ts +4 -4
- package/node-postgres/index.mjs +2 -2
- package/node-postgres/migrator.d.ts +4 -4
- package/package.json +3 -3
- package/pg-core/index.cjs +1 -1
- package/pg-core/index.cjs.map +1 -1
- package/pg-core/index.d.ts +207 -373
- package/pg-core/index.mjs +48 -18
- package/pg-core/index.mjs.map +1 -1
- package/planetscale-serverless/index.cjs +5 -5
- package/planetscale-serverless/index.cjs.map +1 -1
- package/planetscale-serverless/index.d.ts +5 -5
- package/planetscale-serverless/index.mjs +5 -5
- package/planetscale-serverless/index.mjs.map +1 -1
- package/planetscale-serverless/migrator.d.ts +4 -4
- package/postgres-js/index.cjs +1 -1
- package/postgres-js/index.d.ts +4 -4
- package/postgres-js/index.mjs +2 -2
- package/postgres-js/migrator.d.ts +4 -4
- package/{query-promise.d-fd15f63a.d.ts → query-promise.d-bc96befc.d.ts} +48 -45
- package/{db.d-2e828d8c.d.ts → select.types.d-570dd25a.d.ts} +281 -465
- package/{select.types.d-35b6e089.d.ts → select.types.d-73209a67.d.ts} +47 -258
- package/{select.types.d-1ea8ee3b.d.ts → select.types.d-a3c4c974.d.ts} +20 -19
- package/{db.d-9d586c00.d.ts → select.types.d-d0a10728.d.ts} +471 -731
- package/{session-c47f12d9.mjs → session-0c131cde.mjs} +2 -2
- package/{session-c47f12d9.mjs.map → session-0c131cde.mjs.map} +1 -1
- package/{session-2431f9e1.mjs → session-16f863cd.mjs} +36 -64
- package/session-16f863cd.mjs.map +1 -0
- package/{session-6bfef963.cjs → session-805d2876.cjs} +64 -131
- package/session-805d2876.cjs.map +1 -0
- package/{session-fa99bfce.mjs → session-ac71392b.mjs} +67 -134
- package/session-ac71392b.mjs.map +1 -0
- package/{session-fa9720a5.cjs → session-e9306785.cjs} +61 -71
- package/session-e9306785.cjs.map +1 -0
- package/sql-js/index.cjs +2 -2
- package/sql-js/index.d.ts +5 -5
- package/sql-js/index.mjs +2 -2
- package/sql-js/migrator.d.ts +5 -5
- package/sqlite-core/index.cjs +2 -2
- package/sqlite-core/index.d.ts +83 -137
- package/sqlite-core/index.mjs +28 -10
- package/sqlite-core/index.mjs.map +1 -1
- package/sqlite-proxy/index.cjs +2 -2
- package/sqlite-proxy/index.d.ts +6 -6
- package/sqlite-proxy/index.mjs +2 -2
- package/sqlite-proxy/migrator.cjs +1 -1
- package/sqlite-proxy/migrator.d.ts +5 -5
- package/sqlite-proxy/migrator.mjs +1 -1
- package/vercel-postgres/index.cjs +1 -1
- package/vercel-postgres/index.d.ts +4 -4
- package/vercel-postgres/index.mjs +2 -2
- package/vercel-postgres/migrator.d.ts +4 -4
- package/version.cjs +1 -1
- package/version.d.ts +1 -1
- package/version.mjs +1 -1
- package/alias-5aeeb2f5.cjs.map +0 -1
- package/alias-6eaa2e87.mjs.map +0 -1
- package/column.d-9d74a4f3.d.ts +0 -558
- package/session-2431f9e1.mjs.map +0 -1
- package/session-6bfef963.cjs.map +0 -1
- package/session-fa9720a5.cjs.map +0 -1
- package/session-fa99bfce.mjs.map +0 -1
|
@@ -1,417 +1,315 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { e as entityKind, bm as AnyPgTable, aF as KnownKeysOnly, Q as Query, aJ as ColumnsSelection, ah as Subquery, ai as WithSubquery, ax as DrizzleTypeError, bn as AnyPgColumn, X as SQLWrapper, a as SQL, aq as UpdateSet, a3 as DriverValueEncoder, W as QueryTypingsValue, bo as PgColumn, I as InferModel, G as GetColumnData, a9 as Param, ad as Placeholder, bp as IndexColumn, ay as ValueOrArray, bq as PgColumnBuilder, o as BuildColumns, br as AnyPgColumnBuilder, V as View, bs as PgTable, T as Table, bt as PgTableWithColumns, al as UpdateTableConfig, av as Assume, y as SelectedFieldsFlat$1, E as SelectedFields$1, F as SelectedFieldsOrdered$1 } from './column.d-9d2f4045.js';
|
|
2
|
+
import { A as AddAliasToSelection, T as TypedQueryBuilder, f as SelectResultFields, G as GetSelectTableName, a as GetSelectTableSelection, S as SelectMode, J as JoinNullability, B as BuildSubquerySelection, b as SelectResult, c as JoinType, M as MapColumnsToTableAlias, d as AppendToResult, e as AppendToNullabilityMap } from './select.types.d-a3c4c974.js';
|
|
3
|
+
import { T as TablesRelationalConfig, L as TableRelationalConfig, K as DBQueryConfig, V as BuildQueryResult, Q as QueryPromise, N as ExtractTablesWithRelations, R as RelationalSchemaConfig, a as Relation, a3 as BuildRelationalQueryResult } from './query-promise.d-bc96befc.js';
|
|
2
4
|
import { MigrationMeta } from './migrator.js';
|
|
3
|
-
import { Q as QueryPromise, T as TablesRelationalConfig, K as TableRelationalConfig, J as DBQueryConfig, a as Relation, a2 as BuildRelationalQueryResult, U as BuildQueryResult, L as ExtractTablesWithRelations, R as RelationalSchemaConfig } from './query-promise.d-fd15f63a.js';
|
|
4
|
-
import { T as TypedQueryBuilder, A as AddAliasToSelection, G as GetSelectTableName, a as GetSelectTableSelection, S as SelectMode, J as JoinNullability, B as BuildSubquerySelection, b as SelectResult, c as JoinType, M as MapColumnsToTableAlias, d as AppendToResult, e as AppendToNullabilityMap, f as SelectResultFields } from './select.types.d-1ea8ee3b.js';
|
|
5
5
|
|
|
6
|
-
declare class
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
table: AnyPgTable;
|
|
6
|
+
declare class RelationalQueryBuilder<TSchema extends TablesRelationalConfig, TFields extends TableRelationalConfig> {
|
|
7
|
+
private fullSchema;
|
|
8
|
+
private schema;
|
|
9
|
+
private tableNamesMap;
|
|
10
|
+
private table;
|
|
11
|
+
private tableConfig;
|
|
12
|
+
private dialect;
|
|
13
|
+
private session;
|
|
15
14
|
static readonly [entityKind]: string;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
constructor(fullSchema: Record<string, unknown>, schema: TSchema, tableNamesMap: Record<string, string>, table: AnyPgTable, tableConfig: TableRelationalConfig, dialect: PgDialect, session: PgSession);
|
|
16
|
+
findMany<TConfig extends DBQueryConfig<'many', true, TSchema, TFields>>(config?: KnownKeysOnly<TConfig, DBQueryConfig<'many', true, TSchema, TFields>>): PgRelationalQuery<BuildQueryResult<TSchema, TFields, TConfig>[]>;
|
|
17
|
+
findFirst<TSelection extends Omit<DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>(config?: KnownKeysOnly<TSelection, Omit<DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>): PgRelationalQuery<BuildQueryResult<TSchema, TFields, TSelection> | undefined>;
|
|
19
18
|
}
|
|
20
|
-
declare
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
constructor(config: () => {
|
|
31
|
-
columns: AnyPgColumn[];
|
|
32
|
-
foreignColumns: AnyPgColumn[];
|
|
33
|
-
}, actions?: {
|
|
34
|
-
onUpdate?: UpdateDeleteAction;
|
|
35
|
-
onDelete?: UpdateDeleteAction;
|
|
36
|
-
} | undefined);
|
|
37
|
-
onUpdate(action: UpdateDeleteAction): this;
|
|
38
|
-
onDelete(action: UpdateDeleteAction): this;
|
|
39
|
-
}
|
|
40
|
-
type AnyForeignKeyBuilder = ForeignKeyBuilder;
|
|
41
|
-
declare class ForeignKey {
|
|
42
|
-
readonly table: AnyPgTable;
|
|
19
|
+
declare class PgRelationalQuery<TResult> extends QueryPromise<TResult> {
|
|
20
|
+
private fullSchema;
|
|
21
|
+
private schema;
|
|
22
|
+
private tableNamesMap;
|
|
23
|
+
private table;
|
|
24
|
+
private tableConfig;
|
|
25
|
+
private dialect;
|
|
26
|
+
private session;
|
|
27
|
+
private config;
|
|
28
|
+
private mode;
|
|
43
29
|
static readonly [entityKind]: string;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
type ColumnsWithTable<TTableName extends string, TColumns extends AnyPgColumn[]> = {
|
|
51
|
-
[Key in keyof TColumns]: AnyPgColumn<{
|
|
52
|
-
tableName: TTableName;
|
|
30
|
+
protected $brand: 'PgRelationalQuery';
|
|
31
|
+
constructor(fullSchema: Record<string, unknown>, schema: TablesRelationalConfig, tableNamesMap: Record<string, string>, table: AnyPgTable, tableConfig: TableRelationalConfig, dialect: PgDialect, session: PgSession, config: DBQueryConfig<'many', true> | true, mode: 'many' | 'first');
|
|
32
|
+
private _prepare;
|
|
33
|
+
prepare(name: string): PreparedQuery<PreparedQueryConfig & {
|
|
34
|
+
execute: TResult;
|
|
53
35
|
}>;
|
|
54
|
-
|
|
55
|
-
declare function foreignKey<TTableName extends string, TForeignTableName extends string, TColumns extends [AnyPgColumn<{
|
|
56
|
-
tableName: TTableName;
|
|
57
|
-
}>, ...AnyPgColumn<{
|
|
58
|
-
tableName: TTableName;
|
|
59
|
-
}>[]]>(config: {
|
|
60
|
-
columns: TColumns;
|
|
61
|
-
foreignColumns: ColumnsWithTable<TForeignTableName, TColumns>;
|
|
62
|
-
}): ForeignKeyBuilder;
|
|
63
|
-
|
|
64
|
-
interface ReferenceConfig {
|
|
65
|
-
ref: () => AnyPgColumn;
|
|
66
|
-
actions: {
|
|
67
|
-
onUpdate?: UpdateDeleteAction;
|
|
68
|
-
onDelete?: UpdateDeleteAction;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
interface PgColumnBuilderHKT extends ColumnBuilderHKTBase {
|
|
72
|
-
_type: PgColumnBuilder<PgColumnBuilderHKT, Assume<this['config'], ColumnBuilderBaseConfig>>;
|
|
73
|
-
_columnHKT: PgColumnHKT;
|
|
36
|
+
execute(): Promise<TResult>;
|
|
74
37
|
}
|
|
75
|
-
|
|
76
|
-
|
|
38
|
+
|
|
39
|
+
interface PgRefreshMaterializedView<TQueryResult extends QueryResultHKT> extends QueryPromise<QueryResultKind<TQueryResult, never>> {
|
|
77
40
|
}
|
|
78
|
-
declare
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
private foreignKeyConfigs;
|
|
41
|
+
declare class PgRefreshMaterializedView<TQueryResult extends QueryResultHKT> extends QueryPromise<QueryResultKind<TQueryResult, never>> {
|
|
42
|
+
private session;
|
|
43
|
+
private dialect;
|
|
82
44
|
static readonly [entityKind]: string;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
45
|
+
private config;
|
|
46
|
+
constructor(view: PgMaterializedView, session: PgSession, dialect: PgDialect);
|
|
47
|
+
concurrently(): this;
|
|
48
|
+
withNoData(): this;
|
|
49
|
+
toSQL(): {
|
|
50
|
+
sql: Query['sql'];
|
|
51
|
+
params: Query['params'];
|
|
52
|
+
};
|
|
53
|
+
private _prepare;
|
|
54
|
+
prepare(name: string): PreparedQuery<PreparedQueryConfig & {
|
|
55
|
+
execute: QueryResultKind<TQueryResult, never>;
|
|
89
56
|
}>;
|
|
90
|
-
|
|
91
|
-
unique(name?: string, config?: {
|
|
92
|
-
nulls: 'distinct' | 'not distinct';
|
|
93
|
-
}): this;
|
|
94
|
-
}
|
|
95
|
-
type AnyPgColumnBuilder<TPartial extends Partial<ColumnBuilderBaseConfig> = {}> = PgColumnBuilder<PgColumnBuilderHKT, Required<Update<ColumnBuilderBaseConfig, TPartial>>>;
|
|
96
|
-
declare abstract class PgColumn<THKT extends ColumnHKT, T extends ColumnBaseConfig, TRuntimeConfig extends object = {}, TTypeConfig extends object = {}> extends Column<THKT, T, TRuntimeConfig, TTypeConfig & {
|
|
97
|
-
pgBrand: 'PgColumn';
|
|
98
|
-
}> {
|
|
99
|
-
readonly table: AnyPgTable;
|
|
100
|
-
static readonly [entityKind]: string;
|
|
101
|
-
constructor(table: AnyPgTable, config: ColumnBuilderRuntimeConfig<T['data']> & TRuntimeConfig);
|
|
102
|
-
}
|
|
103
|
-
type AnyPgColumn<TPartial extends Partial<ColumnBaseConfig> = {}> = PgColumn<PgColumnHKT, Required<Update<ColumnBaseConfig, TPartial>>>;
|
|
104
|
-
interface AnyPgColumnHKT extends AnyColumnHKT {
|
|
105
|
-
type: AnyPgColumn<Assume<this['config'], Partial<ColumnBaseConfig>>>;
|
|
57
|
+
execute: ReturnType<this['prepare']>['execute'];
|
|
106
58
|
}
|
|
107
59
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
* If true, the index will be created as `create unique index` instead of `create index`.
|
|
113
|
-
*/
|
|
114
|
-
unique: boolean;
|
|
115
|
-
/**
|
|
116
|
-
* If true, the index will be created as `create index concurrently` instead of `create index`.
|
|
117
|
-
*/
|
|
118
|
-
concurrently?: boolean;
|
|
119
|
-
/**
|
|
120
|
-
* If true, the index will be created as `create index ... on only <table>` instead of `create index ... on <table>`.
|
|
121
|
-
*/
|
|
122
|
-
only: boolean;
|
|
123
|
-
/**
|
|
124
|
-
* If set, the index will be created as `create index ... using <method>`.
|
|
125
|
-
*/
|
|
126
|
-
using?: SQL;
|
|
127
|
-
/**
|
|
128
|
-
* If set, the index will be created as `create index ... asc | desc`.
|
|
129
|
-
*/
|
|
130
|
-
order?: 'asc' | 'desc';
|
|
131
|
-
/**
|
|
132
|
-
* If set, adds `nulls first` or `nulls last` to the index.
|
|
133
|
-
*/
|
|
134
|
-
nulls?: 'first' | 'last';
|
|
135
|
-
/**
|
|
136
|
-
* Condition for partial index.
|
|
137
|
-
*/
|
|
138
|
-
where?: SQL;
|
|
139
|
-
}
|
|
140
|
-
type IndexColumn = AnyPgColumn;
|
|
141
|
-
declare class IndexBuilderOn {
|
|
142
|
-
private unique;
|
|
143
|
-
private name?;
|
|
144
|
-
static readonly [entityKind]: string;
|
|
145
|
-
constructor(unique: boolean, name?: string | undefined);
|
|
146
|
-
on(...columns: [IndexColumn, ...IndexColumn[]]): IndexBuilder;
|
|
147
|
-
onOnly(...columns: [IndexColumn, ...IndexColumn[]]): IndexBuilder;
|
|
148
|
-
}
|
|
149
|
-
interface AnyIndexBuilder {
|
|
150
|
-
build(table: AnyPgTable): Index;
|
|
151
|
-
}
|
|
152
|
-
interface IndexBuilder extends AnyIndexBuilder {
|
|
153
|
-
}
|
|
154
|
-
declare class IndexBuilder implements AnyIndexBuilder {
|
|
155
|
-
static readonly [entityKind]: string;
|
|
156
|
-
constructor(columns: IndexColumn[], unique: boolean, only: boolean, name?: string);
|
|
157
|
-
concurrently(): this;
|
|
158
|
-
using(method: SQL): this;
|
|
159
|
-
asc(): Omit<this, 'asc' | 'desc'>;
|
|
160
|
-
desc(): Omit<this, 'asc' | 'desc'>;
|
|
161
|
-
nullsFirst(): Omit<this, 'nullsFirst' | 'nullsLast'>;
|
|
162
|
-
nullsLast(): Omit<this, 'nullsFirst' | 'nullsLast'>;
|
|
163
|
-
where(condition: SQL): Omit<this, 'where'>;
|
|
164
|
-
}
|
|
165
|
-
declare class Index {
|
|
60
|
+
type SubqueryWithSelection<TSelection extends ColumnsSelection, TAlias extends string> = Subquery<TAlias, AddAliasToSelection<TSelection, TAlias, 'pg'>> & AddAliasToSelection<TSelection, TAlias, 'pg'>;
|
|
61
|
+
type WithSubqueryWithSelection<TSelection extends ColumnsSelection, TAlias extends string> = WithSubquery<TAlias, AddAliasToSelection<TSelection, TAlias, 'pg'>> & AddAliasToSelection<TSelection, TAlias, 'pg'>;
|
|
62
|
+
|
|
63
|
+
declare class PgDatabase<TQueryResult extends QueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
166
64
|
static readonly [entityKind]: string;
|
|
167
|
-
readonly
|
|
168
|
-
|
|
65
|
+
readonly _: {
|
|
66
|
+
readonly schema: TSchema | undefined;
|
|
67
|
+
readonly tableNamesMap: Record<string, string>;
|
|
68
|
+
};
|
|
69
|
+
query: TFullSchema extends Record<string, never> ? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'> : {
|
|
70
|
+
[K in keyof TSchema]: RelationalQueryBuilder<TSchema, TSchema[K]>;
|
|
71
|
+
};
|
|
72
|
+
constructor(
|
|
73
|
+
/** @internal */
|
|
74
|
+
dialect: PgDialect,
|
|
75
|
+
/** @internal */
|
|
76
|
+
session: PgSession<any, any, any>, schema: RelationalSchemaConfig<TSchema> | undefined);
|
|
77
|
+
$with<TAlias extends string>(alias: TAlias): {
|
|
78
|
+
as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection, unknown> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection, unknown>)): WithSubqueryWithSelection<TSelection, TAlias>;
|
|
79
|
+
};
|
|
80
|
+
with(...queries: WithSubquery[]): {
|
|
81
|
+
select: {
|
|
82
|
+
(): PgSelectBuilder<undefined>;
|
|
83
|
+
<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection, "db">;
|
|
84
|
+
};
|
|
169
85
|
};
|
|
170
|
-
|
|
86
|
+
select(): PgSelectBuilder<undefined>;
|
|
87
|
+
select<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection>;
|
|
88
|
+
selectDistinct(): PgSelectBuilder<undefined>;
|
|
89
|
+
selectDistinct<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection>;
|
|
90
|
+
selectDistinctOn(on: (AnyPgColumn | SQLWrapper)[]): PgSelectBuilder<undefined>;
|
|
91
|
+
selectDistinctOn<TSelection extends SelectedFields>(on: (AnyPgColumn | SQLWrapper)[], fields: TSelection): PgSelectBuilder<TSelection>;
|
|
92
|
+
update<TTable extends AnyPgTable>(table: TTable): PgUpdateBuilder<TTable, TQueryResult>;
|
|
93
|
+
insert<TTable extends AnyPgTable>(table: TTable): PgInsertBuilder<TTable, TQueryResult>;
|
|
94
|
+
delete<TTable extends AnyPgTable>(table: TTable): PgDelete<TTable, TQueryResult>;
|
|
95
|
+
refreshMaterializedView<TView extends PgMaterializedView>(view: TView): PgRefreshMaterializedView<TQueryResult>;
|
|
96
|
+
execute<TRow extends Record<string, unknown> = Record<string, unknown>>(query: SQLWrapper): Promise<QueryResultKind<TQueryResult, TRow>>;
|
|
97
|
+
transaction<T>(transaction: (tx: PgTransaction<TQueryResult, TFullSchema, TSchema>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
171
98
|
}
|
|
172
|
-
type GetColumnsTableName<TColumns> = TColumns extends AnyPgColumn ? TColumns['_']['name'] : TColumns extends AnyPgColumn[] ? TColumns[number]['_']['name'] : never;
|
|
173
|
-
declare function index(name?: string): IndexBuilderOn;
|
|
174
|
-
declare function uniqueIndex(name?: string): IndexBuilderOn;
|
|
175
99
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
static readonly [entityKind]: string;
|
|
181
|
-
constructor(columns: AnyPgColumn[]);
|
|
100
|
+
interface PreparedQueryConfig {
|
|
101
|
+
execute: unknown;
|
|
102
|
+
all: unknown;
|
|
103
|
+
values: unknown;
|
|
182
104
|
}
|
|
183
|
-
declare class
|
|
184
|
-
readonly table: AnyPgTable;
|
|
105
|
+
declare abstract class PreparedQuery<T extends PreparedQueryConfig> {
|
|
185
106
|
static readonly [entityKind]: string;
|
|
186
|
-
|
|
187
|
-
constructor(table: AnyPgTable, columns: AnyPgColumn<{}>[]);
|
|
188
|
-
getName(): string;
|
|
107
|
+
abstract execute(placeholderValues?: Record<string, unknown>): Promise<T['execute']>;
|
|
189
108
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
private name?;
|
|
195
|
-
static readonly [entityKind]: string;
|
|
196
|
-
constructor(columns: AnyPgColumn[], name?: string | undefined);
|
|
197
|
-
nullsNotDistinct(): this;
|
|
109
|
+
interface PgTransactionConfig {
|
|
110
|
+
isolationLevel?: 'read uncommitted' | 'read committed' | 'repeatable read' | 'serializable';
|
|
111
|
+
accessMode?: 'read only' | 'read write';
|
|
112
|
+
deferrable?: boolean;
|
|
198
113
|
}
|
|
199
|
-
declare class
|
|
114
|
+
declare abstract class PgSession<TQueryResult extends QueryResultHKT = QueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = Record<string, never>> {
|
|
115
|
+
protected dialect: PgDialect;
|
|
200
116
|
static readonly [entityKind]: string;
|
|
201
|
-
constructor(
|
|
202
|
-
|
|
117
|
+
constructor(dialect: PgDialect);
|
|
118
|
+
abstract prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, customResultMapper?: (rows: unknown[][], mapColumnValue?: (value: unknown) => unknown) => T['execute']): PreparedQuery<T>;
|
|
119
|
+
execute<T>(query: SQL): Promise<T>;
|
|
120
|
+
all<T = unknown>(query: SQL): Promise<T[]>;
|
|
121
|
+
abstract transaction<T>(transaction: (tx: PgTransaction<TQueryResult, TFullSchema, TSchema>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
203
122
|
}
|
|
204
|
-
declare class
|
|
205
|
-
|
|
123
|
+
declare abstract class PgTransaction<TQueryResult extends QueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = Record<string, never>> extends PgDatabase<TQueryResult, TFullSchema, TSchema> {
|
|
124
|
+
protected schema: {
|
|
125
|
+
fullSchema: Record<string, unknown>;
|
|
126
|
+
schema: TSchema;
|
|
127
|
+
tableNamesMap: Record<string, string>;
|
|
128
|
+
} | undefined;
|
|
129
|
+
protected readonly nestedIndex: number;
|
|
206
130
|
static readonly [entityKind]: string;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
131
|
+
constructor(dialect: PgDialect, session: PgSession<any, any, any>, schema: {
|
|
132
|
+
fullSchema: Record<string, unknown>;
|
|
133
|
+
schema: TSchema;
|
|
134
|
+
tableNamesMap: Record<string, string>;
|
|
135
|
+
} | undefined, nestedIndex?: number);
|
|
136
|
+
rollback(): never;
|
|
137
|
+
setTransaction(config: PgTransactionConfig): Promise<void>;
|
|
138
|
+
abstract transaction<T>(transaction: (tx: PgTransaction<TQueryResult, TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
|
212
139
|
}
|
|
140
|
+
interface QueryResultHKT {
|
|
141
|
+
readonly $brand: 'QueryRowHKT';
|
|
142
|
+
readonly row: unknown;
|
|
143
|
+
readonly type: unknown;
|
|
144
|
+
}
|
|
145
|
+
type QueryResultKind<TKind extends QueryResultHKT, TRow> = (TKind & {
|
|
146
|
+
readonly row: TRow;
|
|
147
|
+
})['type'];
|
|
213
148
|
|
|
214
|
-
|
|
215
|
-
type TableConfig = TableConfig$1<AnyPgColumn>;
|
|
216
|
-
declare class PgTable<T extends TableConfig> extends Table<T> {
|
|
149
|
+
declare class PgDialect {
|
|
217
150
|
static readonly [entityKind]: string;
|
|
151
|
+
migrate(migrations: MigrationMeta[], session: PgSession): Promise<void>;
|
|
152
|
+
escapeName(name: string): string;
|
|
153
|
+
escapeParam(num: number): string;
|
|
154
|
+
escapeString(str: string): string;
|
|
155
|
+
buildDeleteQuery({ table, where, returning }: PgDeleteConfig): SQL;
|
|
156
|
+
buildUpdateSet(table: AnyPgTable, set: UpdateSet): SQL;
|
|
157
|
+
buildUpdateQuery({ table, set, where, returning }: PgUpdateConfig): SQL;
|
|
158
|
+
/**
|
|
159
|
+
* Builds selection SQL with provided fields/expressions
|
|
160
|
+
*
|
|
161
|
+
* Examples:
|
|
162
|
+
*
|
|
163
|
+
* `select <selection> from`
|
|
164
|
+
*
|
|
165
|
+
* `insert ... returning <selection>`
|
|
166
|
+
*
|
|
167
|
+
* If `isSingleTable` is true, then columns won't be prefixed with table name
|
|
168
|
+
*/
|
|
169
|
+
private buildSelection;
|
|
170
|
+
buildSelectQuery({ withList, fields, fieldsFlat, where, having, table, joins, orderBy, groupBy, limit, offset, lockingClauses, distinct, }: PgSelectConfig): SQL;
|
|
171
|
+
buildInsertQuery({ table, values, onConflict, returning }: PgInsertConfig): SQL;
|
|
172
|
+
buildRefreshMaterializedViewQuery({ view, concurrently, withNoData }: {
|
|
173
|
+
view: PgMaterializedView;
|
|
174
|
+
concurrently?: boolean;
|
|
175
|
+
withNoData?: boolean;
|
|
176
|
+
}): SQL;
|
|
177
|
+
prepareTyping(encoder: DriverValueEncoder<unknown, unknown>): QueryTypingsValue;
|
|
178
|
+
sqlToQuery(sql: SQL): Query;
|
|
179
|
+
buildRelationalQueryWithoutPK({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
|
|
180
|
+
fullSchema: Record<string, unknown>;
|
|
181
|
+
schema: TablesRelationalConfig;
|
|
182
|
+
tableNamesMap: Record<string, string>;
|
|
183
|
+
table: AnyPgTable;
|
|
184
|
+
tableConfig: TableRelationalConfig;
|
|
185
|
+
queryConfig: true | DBQueryConfig<'many', true>;
|
|
186
|
+
tableAlias: string;
|
|
187
|
+
nestedQueryRelation?: Relation;
|
|
188
|
+
joinOn?: SQL;
|
|
189
|
+
}): BuildRelationalQueryResult<AnyPgTable, PgColumn>;
|
|
218
190
|
}
|
|
219
|
-
|
|
220
|
-
interface
|
|
221
|
-
|
|
191
|
+
|
|
192
|
+
interface PgDeleteConfig {
|
|
193
|
+
where?: SQL | undefined;
|
|
194
|
+
table: AnyPgTable;
|
|
195
|
+
returning?: SelectedFieldsOrdered;
|
|
222
196
|
}
|
|
223
|
-
|
|
224
|
-
[Key in keyof T['columns']]: T['columns'][Key];
|
|
225
|
-
};
|
|
226
|
-
interface PgTableFn<TSchema extends string | undefined = undefined> {
|
|
227
|
-
<TTableName extends string, TColumnsMap extends Record<string, AnyPgColumnBuilder>>(name: TTableName, columns: TColumnsMap, extraConfig?: (self: BuildColumns<TTableName, TColumnsMap>) => PgTableExtraConfig): PgTableWithColumns<{
|
|
228
|
-
name: TTableName;
|
|
229
|
-
schema: TSchema;
|
|
230
|
-
columns: BuildColumns<TTableName, TColumnsMap>;
|
|
231
|
-
}>;
|
|
197
|
+
interface PgDelete<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> {
|
|
232
198
|
}
|
|
233
|
-
declare
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
interface PgArrayBuilderHKT extends ColumnBuilderHKTBase {
|
|
237
|
-
_type: PgArrayBuilder<Assume<this['config'], ColumnBuilderBaseConfig>>;
|
|
238
|
-
_columnHKT: PgArrayHKT;
|
|
239
|
-
}
|
|
240
|
-
interface PgArrayHKT extends ColumnHKTBase {
|
|
241
|
-
_type: PgArray<Assume<this['config'], ColumnBaseConfig>>;
|
|
242
|
-
}
|
|
243
|
-
declare class PgArrayBuilder<T extends ColumnBuilderBaseConfig> extends PgColumnBuilder<PgArrayBuilderHKT, T, {
|
|
244
|
-
baseBuilder: PgColumnBuilder<PgColumnBuilderHKT, {
|
|
245
|
-
name: T['name'];
|
|
246
|
-
notNull: T['notNull'];
|
|
247
|
-
hasDefault: T['hasDefault'];
|
|
248
|
-
data: Assume<T['data'], unknown[]>[number];
|
|
249
|
-
driverParam: string | Assume<T['driverParam'], unknown[]>[number];
|
|
250
|
-
}>;
|
|
251
|
-
size: number | undefined;
|
|
252
|
-
}> {
|
|
253
|
-
static readonly [entityKind] = "PgArrayBuilder";
|
|
254
|
-
constructor(name: string, baseBuilder: PgArrayBuilder<T>['config']['baseBuilder'], size: number | undefined);
|
|
255
|
-
}
|
|
256
|
-
declare class PgArray<T extends ColumnBaseConfig> extends PgColumn<PgArrayHKT, T, {}, {
|
|
257
|
-
baseColumn: BuildColumn<string, Assume<PgColumnBuilder<PgColumnBuilderHKT, {
|
|
258
|
-
name: T['name'];
|
|
259
|
-
notNull: T['notNull'];
|
|
260
|
-
hasDefault: T['hasDefault'];
|
|
261
|
-
data: Assume<T['data'], unknown[]>[number];
|
|
262
|
-
driverParam: string | Assume<T['driverParam'], unknown[]>[number];
|
|
263
|
-
}>, AnyColumnBuilder>>;
|
|
264
|
-
}> {
|
|
265
|
-
readonly baseColumn: AnyPgColumn;
|
|
266
|
-
readonly range?: [number | undefined, number | undefined] | undefined;
|
|
267
|
-
protected $pgColumnBrand: 'PgArray';
|
|
268
|
-
readonly size: number | undefined;
|
|
199
|
+
declare class PgDelete<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> implements SQLWrapper {
|
|
200
|
+
private session;
|
|
201
|
+
private dialect;
|
|
269
202
|
static readonly [entityKind]: string;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
203
|
+
private config;
|
|
204
|
+
constructor(table: TTable, session: PgSession, dialect: PgDialect);
|
|
205
|
+
where(where: SQL | undefined): Omit<this, 'where'>;
|
|
206
|
+
returning(): PgDelete<TTable, TQueryResult, InferModel<TTable>>;
|
|
207
|
+
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): PgDelete<TTable, TQueryResult, SelectResultFields<TSelectedFields>>;
|
|
208
|
+
toSQL(): {
|
|
209
|
+
sql: Query['sql'];
|
|
210
|
+
params: Query['params'];
|
|
211
|
+
};
|
|
212
|
+
private _prepare;
|
|
213
|
+
prepare(name: string): PreparedQuery<PreparedQueryConfig & {
|
|
214
|
+
execute: TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[];
|
|
215
|
+
}>;
|
|
216
|
+
execute: ReturnType<this['prepare']>['execute'];
|
|
276
217
|
}
|
|
277
218
|
|
|
278
|
-
interface
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
219
|
+
interface PgUpdateConfig {
|
|
220
|
+
where?: SQL | undefined;
|
|
221
|
+
set: UpdateSet;
|
|
222
|
+
table: AnyPgTable;
|
|
223
|
+
returning?: SelectedFieldsOrdered;
|
|
282
224
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
225
|
+
type PgUpdateSetSource<TTable extends AnyPgTable> = {
|
|
226
|
+
[Key in keyof TTable['_']['columns']]?: GetColumnData<TTable['_']['columns'][Key]> | SQL;
|
|
227
|
+
} & {};
|
|
228
|
+
declare class PgUpdateBuilder<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT> {
|
|
229
|
+
private table;
|
|
230
|
+
private session;
|
|
231
|
+
private dialect;
|
|
289
232
|
static readonly [entityKind]: string;
|
|
290
233
|
readonly _: {
|
|
291
|
-
readonly
|
|
292
|
-
readonly columns: TConfig['columns'];
|
|
293
|
-
};
|
|
294
|
-
constructor(name: TConfig['name'], schema: string | undefined);
|
|
295
|
-
protected config: {
|
|
296
|
-
with?: ViewWithConfig;
|
|
234
|
+
readonly table: TTable;
|
|
297
235
|
};
|
|
298
|
-
|
|
236
|
+
constructor(table: TTable, session: PgSession, dialect: PgDialect);
|
|
237
|
+
set(values: PgUpdateSetSource<TTable>): PgUpdate<TTable, TQueryResult>;
|
|
299
238
|
}
|
|
300
|
-
|
|
301
|
-
name: TName;
|
|
302
|
-
}> {
|
|
303
|
-
static readonly [entityKind]: string;
|
|
304
|
-
as<TSelectedFields extends SelectedFields>(qb: TypedQueryBuilder<TSelectedFields> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelectedFields>)): PgViewWithSelection<TName, false, AddAliasToSelection<TSelectedFields, TName>>;
|
|
305
|
-
}
|
|
306
|
-
declare class ManualViewBuilder<TName extends string = string, TColumns extends Record<string, AnyPgColumnBuilder> = Record<string, AnyPgColumnBuilder>> extends DefaultViewBuilderCore<{
|
|
307
|
-
name: TName;
|
|
308
|
-
columns: TColumns;
|
|
309
|
-
}> {
|
|
310
|
-
static readonly [entityKind]: string;
|
|
311
|
-
private columns;
|
|
312
|
-
constructor(name: TName, columns: TColumns, schema: string | undefined);
|
|
313
|
-
existing(): PgViewWithSelection<TName, true, BuildColumns<TName, TColumns>>;
|
|
314
|
-
as(query: SQL): PgViewWithSelection<TName, false, BuildColumns<TName, TColumns>>;
|
|
315
|
-
}
|
|
316
|
-
interface PgMaterializedViewWithConfig {
|
|
317
|
-
[Key: string]: string | number | boolean | SQL;
|
|
239
|
+
interface PgUpdate<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]>, SQLWrapper {
|
|
318
240
|
}
|
|
319
|
-
declare class
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}> {
|
|
323
|
-
protected name: TConfig['name'];
|
|
324
|
-
protected schema: string | undefined;
|
|
241
|
+
declare class PgUpdate<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> implements SQLWrapper {
|
|
242
|
+
private session;
|
|
243
|
+
private dialect;
|
|
325
244
|
static readonly [entityKind]: string;
|
|
326
|
-
_: {
|
|
327
|
-
readonly
|
|
328
|
-
readonly
|
|
329
|
-
};
|
|
330
|
-
constructor(name: TConfig['name'], schema: string | undefined);
|
|
331
|
-
protected config: {
|
|
332
|
-
with?: PgMaterializedViewWithConfig;
|
|
333
|
-
using?: string;
|
|
334
|
-
tablespace?: string;
|
|
335
|
-
withNoData?: boolean;
|
|
245
|
+
readonly _: {
|
|
246
|
+
readonly table: TTable;
|
|
247
|
+
readonly return: TReturning;
|
|
336
248
|
};
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
249
|
+
private config;
|
|
250
|
+
constructor(table: TTable, set: UpdateSet, session: PgSession, dialect: PgDialect);
|
|
251
|
+
where(where: SQL | undefined): this;
|
|
252
|
+
returning(): PgUpdate<TTable, TQueryResult, InferModel<TTable>>;
|
|
253
|
+
returning<TSelectedFields extends SelectedFields>(fields: TSelectedFields): PgUpdate<TTable, TQueryResult, SelectResultFields<TSelectedFields>>;
|
|
254
|
+
toSQL(): Omit<Query, 'typings'>;
|
|
255
|
+
private _prepare;
|
|
256
|
+
prepare(name: string): PreparedQuery<PreparedQueryConfig & {
|
|
257
|
+
execute: TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[];
|
|
258
|
+
}>;
|
|
259
|
+
execute: ReturnType<this['prepare']>['execute'];
|
|
347
260
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
constructor(name: TName, columns: TColumns, schema: string | undefined);
|
|
355
|
-
existing(): PgMaterializedViewWithSelection<TName, true, BuildColumns<TName, TColumns>>;
|
|
356
|
-
as(query: SQL): PgMaterializedViewWithSelection<TName, false, BuildColumns<TName, TColumns>>;
|
|
261
|
+
|
|
262
|
+
interface PgInsertConfig<TTable extends AnyPgTable = AnyPgTable> {
|
|
263
|
+
table: TTable;
|
|
264
|
+
values: Record<string, Param | SQL>[];
|
|
265
|
+
onConflict?: SQL;
|
|
266
|
+
returning?: SelectedFieldsOrdered;
|
|
357
267
|
}
|
|
358
|
-
|
|
268
|
+
type PgInsertValue<TTable extends AnyPgTable> = {
|
|
269
|
+
[Key in keyof InferModel<TTable, 'insert'>]: InferModel<TTable, 'insert'>[Key] | SQL | Placeholder;
|
|
270
|
+
} & {};
|
|
271
|
+
declare class PgInsertBuilder<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT> {
|
|
272
|
+
private table;
|
|
273
|
+
private session;
|
|
274
|
+
private dialect;
|
|
359
275
|
static readonly [entityKind]: string;
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
276
|
+
constructor(table: TTable, session: PgSession, dialect: PgDialect);
|
|
277
|
+
values(value: PgInsertValue<TTable>): PgInsert<TTable, TQueryResult>;
|
|
278
|
+
values(values: PgInsertValue<TTable>[]): PgInsert<TTable, TQueryResult>;
|
|
363
279
|
}
|
|
364
|
-
|
|
365
|
-
declare class PgView<TName extends string = string, TExisting extends boolean = boolean, TSelectedFields extends ColumnsSelection = ColumnsSelection> extends PgViewBase<TName, TExisting, TSelectedFields> {
|
|
366
|
-
static readonly [entityKind]: string;
|
|
367
|
-
[PgViewConfig]: {
|
|
368
|
-
with?: ViewWithConfig;
|
|
369
|
-
} | undefined;
|
|
370
|
-
constructor({ pgConfig, config }: {
|
|
371
|
-
pgConfig: {
|
|
372
|
-
with?: ViewWithConfig;
|
|
373
|
-
} | undefined;
|
|
374
|
-
config: {
|
|
375
|
-
name: TName;
|
|
376
|
-
schema: string | undefined;
|
|
377
|
-
selectedFields: SelectedFields;
|
|
378
|
-
query: SQL | undefined;
|
|
379
|
-
};
|
|
380
|
-
});
|
|
280
|
+
interface PgInsert<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]>, SQLWrapper {
|
|
381
281
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
282
|
+
declare class PgInsert<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> implements SQLWrapper {
|
|
283
|
+
private session;
|
|
284
|
+
private dialect;
|
|
385
285
|
static readonly [entityKind]: string;
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
286
|
+
_: {
|
|
287
|
+
table: TTable;
|
|
288
|
+
return: TReturning;
|
|
289
|
+
};
|
|
290
|
+
private config;
|
|
291
|
+
constructor(table: TTable, values: PgInsertConfig['values'], session: PgSession, dialect: PgDialect);
|
|
292
|
+
returning(): PgInsert<TTable, TQueryResult, InferModel<TTable>>;
|
|
293
|
+
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): PgInsert<TTable, TQueryResult, SelectResultFields<TSelectedFields>>;
|
|
294
|
+
onConflictDoNothing(config?: {
|
|
295
|
+
target?: IndexColumn | IndexColumn[];
|
|
296
|
+
where?: SQL;
|
|
297
|
+
}): this;
|
|
298
|
+
onConflictDoUpdate(config: {
|
|
299
|
+
target: IndexColumn | IndexColumn[];
|
|
300
|
+
where?: SQL;
|
|
301
|
+
set: PgUpdateSetSource<TTable>;
|
|
302
|
+
}): this;
|
|
303
|
+
toSQL(): {
|
|
304
|
+
sql: Query['sql'];
|
|
305
|
+
params: Query['params'];
|
|
306
|
+
};
|
|
307
|
+
private _prepare;
|
|
308
|
+
prepare(name: string): PreparedQuery<PreparedQueryConfig & {
|
|
309
|
+
execute: TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[];
|
|
310
|
+
}>;
|
|
311
|
+
execute: ReturnType<this['prepare']>['execute'];
|
|
406
312
|
}
|
|
407
|
-
type PgMaterializedViewWithSelection<TName extends string = string, TExisting extends boolean = boolean, TSelectedFields extends ColumnsSelection = ColumnsSelection> = PgMaterializedView<TName, TExisting, TSelectedFields> & TSelectedFields;
|
|
408
|
-
declare function pgView<TName extends string>(name: TName): ViewBuilder<TName>;
|
|
409
|
-
declare function pgView<TName extends string, TColumns extends Record<string, AnyPgColumnBuilder>>(name: TName, columns: TColumns): ManualViewBuilder<TName, TColumns>;
|
|
410
|
-
declare function pgMaterializedView<TName extends string>(name: TName): MaterializedViewBuilder<TName>;
|
|
411
|
-
declare function pgMaterializedView<TName extends string, TColumns extends Record<string, AnyPgColumnBuilder>>(name: TName, columns: TColumns): ManualMaterializedViewBuilder<TName, TColumns>;
|
|
412
|
-
|
|
413
|
-
type SubqueryWithSelection<TSelection extends ColumnsSelection, TAlias extends string> = Subquery<TAlias, AddAliasToSelection<TSelection, TAlias>> & AddAliasToSelection<TSelection, TAlias>;
|
|
414
|
-
type WithSubqueryWithSelection<TSelection extends ColumnsSelection, TAlias extends string> = WithSubquery<TAlias, AddAliasToSelection<TSelection, TAlias>> & AddAliasToSelection<TSelection, TAlias>;
|
|
415
313
|
|
|
416
314
|
type CreatePgSelectFromBuilderMode<TBuilderMode extends 'db' | 'qb', TTableName extends string | undefined, TSelection extends ColumnsSelection, TSelectMode extends SelectMode> = TBuilderMode extends 'db' ? PgSelect<TTableName, TSelection, TSelectMode> : PgSelectQueryBuilder<PgSelectQueryBuilderHKT, TTableName, TSelection, TSelectMode>;
|
|
417
315
|
declare class PgSelectBuilder<TSelection extends SelectedFields | undefined, TBuilderMode extends 'db' | 'qb' = 'db'> {
|
|
@@ -585,7 +483,10 @@ declare abstract class PgSelectQueryBuilder<THKT extends PgSelectHKTBase, TTable
|
|
|
585
483
|
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE|Postgres locking clause documentation}
|
|
586
484
|
*/
|
|
587
485
|
for(strength: LockStrength, config?: LockConfig): this;
|
|
588
|
-
toSQL():
|
|
486
|
+
toSQL(): {
|
|
487
|
+
sql: Query['sql'];
|
|
488
|
+
params: Query['params'];
|
|
489
|
+
};
|
|
589
490
|
as<TAlias extends string>(alias: TAlias): SubqueryWithSelection<BuildSubquerySelection<TSelection, TNullabilityMap>, TAlias>;
|
|
590
491
|
}
|
|
591
492
|
interface PgSelect<TTableName extends string | undefined, TSelection extends ColumnsSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}> extends PgSelectQueryBuilder<PgSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>, QueryPromise<SelectResult<TSelection, TSelectMode, TNullabilityMap>[]> {
|
|
@@ -606,398 +507,237 @@ declare class PgSelect<TTableName extends string | undefined, TSelection, TSelec
|
|
|
606
507
|
execute: ReturnType<this['prepare']>['execute'];
|
|
607
508
|
}
|
|
608
509
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
alias:
|
|
613
|
-
|
|
614
|
-
lateral?: boolean;
|
|
615
|
-
}
|
|
616
|
-
type AnyPgSelect = PgSelect<any, any, any, any>;
|
|
617
|
-
type BuildAliasTable<TTable extends AnyTable, TAlias extends string> = PgTableWithColumns<Assume<UpdateTableConfig<TTable['_']['config'], {
|
|
618
|
-
name: TAlias;
|
|
619
|
-
columns: MapColumnsToTableAlias<TTable['_']['columns'], TAlias>;
|
|
620
|
-
}>, TableConfig>>;
|
|
621
|
-
interface PgSelectConfig {
|
|
622
|
-
withList?: Subquery[];
|
|
623
|
-
fields: Record<string, unknown>;
|
|
624
|
-
fieldsFlat?: SelectedFieldsOrdered;
|
|
625
|
-
where?: SQL;
|
|
626
|
-
having?: SQL;
|
|
627
|
-
table: AnyPgTable | Subquery | PgViewBase | SQL;
|
|
628
|
-
limit?: number | Placeholder;
|
|
629
|
-
offset?: number | Placeholder;
|
|
630
|
-
joins?: Join[];
|
|
631
|
-
orderBy?: (AnyPgColumn | SQL | SQL.Aliased)[];
|
|
632
|
-
groupBy?: (AnyPgColumn | SQL | SQL.Aliased)[];
|
|
633
|
-
lockingClauses?: {
|
|
634
|
-
strength: LockStrength;
|
|
635
|
-
config: LockConfig;
|
|
636
|
-
}[];
|
|
637
|
-
distinct?: boolean | {
|
|
638
|
-
on: (AnyPgColumn | SQLWrapper)[];
|
|
510
|
+
declare class QueryBuilder {
|
|
511
|
+
static readonly [entityKind]: string;
|
|
512
|
+
private dialect;
|
|
513
|
+
$with<TAlias extends string>(alias: TAlias): {
|
|
514
|
+
as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection, unknown> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection, unknown>)): WithSubqueryWithSelection<TSelection, TAlias>;
|
|
639
515
|
};
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
selectMode: SelectMode;
|
|
662
|
-
nullabilityMap: unknown;
|
|
663
|
-
_type: unknown;
|
|
664
|
-
}
|
|
665
|
-
type PgSelectKind<T extends PgSelectHKTBase, TTableName extends string | undefined, TSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability>> = (T & {
|
|
666
|
-
tableName: TTableName;
|
|
667
|
-
selection: TSelection;
|
|
668
|
-
selectMode: TSelectMode;
|
|
669
|
-
nullabilityMap: TNullabilityMap;
|
|
670
|
-
})['_type'];
|
|
671
|
-
interface PgSelectQueryBuilderHKT extends PgSelectHKTBase {
|
|
672
|
-
_type: PgSelectQueryBuilder<this, this['tableName'], Assume<this['selection'], ColumnsSelection>, this['selectMode'], Assume<this['nullabilityMap'], Record<string, JoinNullability>>>;
|
|
673
|
-
}
|
|
674
|
-
interface PgSelectHKT extends PgSelectHKTBase {
|
|
675
|
-
_type: PgSelect<this['tableName'], Assume<this['selection'], ColumnsSelection>, this['selectMode'], Assume<this['nullabilityMap'], Record<string, JoinNullability>>>;
|
|
516
|
+
with(...queries: WithSubquery[]): {
|
|
517
|
+
select: {
|
|
518
|
+
(): PgSelectBuilder<undefined, 'qb'>;
|
|
519
|
+
<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection, "qb">;
|
|
520
|
+
};
|
|
521
|
+
selectDistinct: {
|
|
522
|
+
(): PgSelectBuilder<undefined, 'qb'>;
|
|
523
|
+
<TSelection_1 extends SelectedFields>(fields: TSelection_1): PgSelectBuilder<TSelection_1, "qb">;
|
|
524
|
+
};
|
|
525
|
+
selectDistinctOn: {
|
|
526
|
+
(on: (AnyPgColumn | SQLWrapper)[]): PgSelectBuilder<undefined, 'qb'>;
|
|
527
|
+
<TSelection_2 extends SelectedFields>(on: (AnyPgColumn | SQLWrapper)[], fields: TSelection_2): PgSelectBuilder<TSelection_2, "qb">;
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
select(): PgSelectBuilder<undefined, 'qb'>;
|
|
531
|
+
select<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection, 'qb'>;
|
|
532
|
+
selectDistinct(): PgSelectBuilder<undefined>;
|
|
533
|
+
selectDistinct<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection>;
|
|
534
|
+
selectDistinctOn(on: (AnyPgColumn | SQLWrapper)[]): PgSelectBuilder<undefined>;
|
|
535
|
+
selectDistinctOn<TSelection extends SelectedFields>(on: (AnyPgColumn | SQLWrapper)[], fields: TSelection): PgSelectBuilder<TSelection>;
|
|
536
|
+
private getDialect;
|
|
676
537
|
}
|
|
677
538
|
|
|
678
|
-
interface
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
539
|
+
interface ViewWithConfig {
|
|
540
|
+
checkOption: 'local' | 'cascaded';
|
|
541
|
+
securityBarrier: boolean;
|
|
542
|
+
securityInvoker: boolean;
|
|
682
543
|
}
|
|
683
|
-
declare
|
|
544
|
+
declare class DefaultViewBuilderCore<TConfig extends {
|
|
545
|
+
name: string;
|
|
546
|
+
columns?: unknown;
|
|
547
|
+
}> {
|
|
548
|
+
protected name: TConfig['name'];
|
|
549
|
+
protected schema: string | undefined;
|
|
684
550
|
static readonly [entityKind]: string;
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
static readonly [entityKind]: string;
|
|
695
|
-
constructor(dialect: PgDialect);
|
|
696
|
-
abstract prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, customResultMapper?: (rows: unknown[][], mapColumnValue?: (value: unknown) => unknown) => T['execute']): PreparedQuery<T>;
|
|
697
|
-
execute<T>(query: SQL): Promise<T>;
|
|
698
|
-
all<T = unknown>(query: SQL): Promise<T[]>;
|
|
699
|
-
abstract transaction<T>(transaction: (tx: PgTransaction<TQueryResult, TFullSchema, TSchema>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
551
|
+
readonly _: {
|
|
552
|
+
readonly name: TConfig['name'];
|
|
553
|
+
readonly columns: TConfig['columns'];
|
|
554
|
+
};
|
|
555
|
+
constructor(name: TConfig['name'], schema: string | undefined);
|
|
556
|
+
protected config: {
|
|
557
|
+
with?: ViewWithConfig;
|
|
558
|
+
};
|
|
559
|
+
with(config: ViewWithConfig): this;
|
|
700
560
|
}
|
|
701
|
-
declare
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
schema: TSchema;
|
|
705
|
-
tableNamesMap: Record<string, string>;
|
|
706
|
-
} | undefined;
|
|
707
|
-
protected readonly nestedIndex: number;
|
|
561
|
+
declare class ViewBuilder<TName extends string = string> extends DefaultViewBuilderCore<{
|
|
562
|
+
name: TName;
|
|
563
|
+
}> {
|
|
708
564
|
static readonly [entityKind]: string;
|
|
709
|
-
|
|
710
|
-
fullSchema: Record<string, unknown>;
|
|
711
|
-
schema: TSchema;
|
|
712
|
-
tableNamesMap: Record<string, string>;
|
|
713
|
-
} | undefined, nestedIndex?: number);
|
|
714
|
-
rollback(): never;
|
|
715
|
-
setTransaction(config: PgTransactionConfig): Promise<void>;
|
|
716
|
-
abstract transaction<T>(transaction: (tx: PgTransaction<TQueryResult, TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
|
717
|
-
}
|
|
718
|
-
interface QueryResultHKT {
|
|
719
|
-
readonly $brand: 'QueryRowHKT';
|
|
720
|
-
readonly row: unknown;
|
|
721
|
-
readonly type: unknown;
|
|
565
|
+
as<TSelectedFields extends SelectedFields>(qb: TypedQueryBuilder<TSelectedFields> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelectedFields>)): PgViewWithSelection<TName, false, AddAliasToSelection<TSelectedFields, TName, 'pg'>>;
|
|
722
566
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
interface PgDeleteConfig {
|
|
728
|
-
where?: SQL | undefined;
|
|
729
|
-
table: AnyPgTable;
|
|
730
|
-
returning?: SelectedFieldsOrdered;
|
|
731
|
-
}
|
|
732
|
-
interface PgDelete<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> {
|
|
733
|
-
}
|
|
734
|
-
declare class PgDelete<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> implements SQLWrapper {
|
|
735
|
-
private session;
|
|
736
|
-
private dialect;
|
|
567
|
+
declare class ManualViewBuilder<TName extends string = string, TColumns extends Record<string, PgColumnBuilder> = Record<string, PgColumnBuilder>> extends DefaultViewBuilderCore<{
|
|
568
|
+
name: TName;
|
|
569
|
+
columns: TColumns;
|
|
570
|
+
}> {
|
|
737
571
|
static readonly [entityKind]: string;
|
|
738
|
-
private
|
|
739
|
-
constructor(
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): PgDelete<TTable, TQueryResult, SelectResultFields<TSelectedFields>>;
|
|
743
|
-
toSQL(): Simplify<Omit<Query, 'typings'>>;
|
|
744
|
-
private _prepare;
|
|
745
|
-
prepare(name: string): PreparedQuery<PreparedQueryConfig & {
|
|
746
|
-
execute: TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[];
|
|
747
|
-
}>;
|
|
748
|
-
execute: ReturnType<this['prepare']>['execute'];
|
|
572
|
+
private columns;
|
|
573
|
+
constructor(name: TName, columns: TColumns, schema: string | undefined);
|
|
574
|
+
existing(): PgViewWithSelection<TName, true, BuildColumns<TName, TColumns, 'pg'>>;
|
|
575
|
+
as(query: SQL): PgViewWithSelection<TName, false, BuildColumns<TName, TColumns, 'pg'>>;
|
|
749
576
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
where?: SQL | undefined;
|
|
753
|
-
set: UpdateSet;
|
|
754
|
-
table: AnyPgTable;
|
|
755
|
-
returning?: SelectedFieldsOrdered;
|
|
577
|
+
interface PgMaterializedViewWithConfig {
|
|
578
|
+
[Key: string]: string | number | boolean | SQL;
|
|
756
579
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
private dialect;
|
|
580
|
+
declare class MaterializedViewBuilderCore<TConfig extends {
|
|
581
|
+
name: string;
|
|
582
|
+
columns?: unknown;
|
|
583
|
+
}> {
|
|
584
|
+
protected name: TConfig['name'];
|
|
585
|
+
protected schema: string | undefined;
|
|
764
586
|
static readonly [entityKind]: string;
|
|
765
|
-
|
|
766
|
-
readonly
|
|
587
|
+
_: {
|
|
588
|
+
readonly name: TConfig['name'];
|
|
589
|
+
readonly columns: TConfig['columns'];
|
|
767
590
|
};
|
|
768
|
-
constructor(
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
private session;
|
|
775
|
-
private dialect;
|
|
776
|
-
static readonly [entityKind]: string;
|
|
777
|
-
readonly _: {
|
|
778
|
-
readonly table: TTable;
|
|
779
|
-
readonly return: TReturning;
|
|
591
|
+
constructor(name: TConfig['name'], schema: string | undefined);
|
|
592
|
+
protected config: {
|
|
593
|
+
with?: PgMaterializedViewWithConfig;
|
|
594
|
+
using?: string;
|
|
595
|
+
tablespace?: string;
|
|
596
|
+
withNoData?: boolean;
|
|
780
597
|
};
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
returning<TSelectedFields extends SelectedFields>(fields: TSelectedFields): PgUpdate<TTable, TQueryResult, SelectResultFields<TSelectedFields>>;
|
|
786
|
-
toSQL(): Omit<Query, 'typings'>;
|
|
787
|
-
private _prepare;
|
|
788
|
-
prepare(name: string): PreparedQuery<PreparedQueryConfig & {
|
|
789
|
-
execute: TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[];
|
|
790
|
-
}>;
|
|
791
|
-
execute: ReturnType<this['prepare']>['execute'];
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
interface PgInsertConfig<TTable extends AnyPgTable = AnyPgTable> {
|
|
795
|
-
table: TTable;
|
|
796
|
-
values: Record<string, Param | SQL>[];
|
|
797
|
-
onConflict?: SQL;
|
|
798
|
-
returning?: SelectedFieldsOrdered;
|
|
598
|
+
using(using: string): this;
|
|
599
|
+
with(config: PgMaterializedViewWithConfig): this;
|
|
600
|
+
tablespace(tablespace: string): this;
|
|
601
|
+
withNoData(): this;
|
|
799
602
|
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
}
|
|
803
|
-
declare class PgInsertBuilder<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT> {
|
|
804
|
-
private table;
|
|
805
|
-
private session;
|
|
806
|
-
private dialect;
|
|
603
|
+
declare class MaterializedViewBuilder<TName extends string = string> extends MaterializedViewBuilderCore<{
|
|
604
|
+
name: TName;
|
|
605
|
+
}> {
|
|
807
606
|
static readonly [entityKind]: string;
|
|
808
|
-
|
|
809
|
-
values(value: PgInsertValue<TTable>): PgInsert<TTable, TQueryResult>;
|
|
810
|
-
values(values: PgInsertValue<TTable>[]): PgInsert<TTable, TQueryResult>;
|
|
607
|
+
as<TSelectedFields extends SelectedFields>(qb: TypedQueryBuilder<TSelectedFields> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelectedFields>)): PgMaterializedViewWithSelection<TName, false, AddAliasToSelection<TSelectedFields, TName, 'pg'>>;
|
|
811
608
|
}
|
|
812
|
-
|
|
609
|
+
declare class ManualMaterializedViewBuilder<TName extends string = string, TColumns extends Record<string, AnyPgColumnBuilder> = Record<string, AnyPgColumnBuilder>> extends MaterializedViewBuilderCore<{
|
|
610
|
+
name: TName;
|
|
611
|
+
columns: TColumns;
|
|
612
|
+
}> {
|
|
613
|
+
static readonly [entityKind]: string;
|
|
614
|
+
private columns;
|
|
615
|
+
constructor(name: TName, columns: TColumns, schema: string | undefined);
|
|
616
|
+
existing(): PgMaterializedViewWithSelection<TName, true, BuildColumns<TName, TColumns, 'pg'>>;
|
|
617
|
+
as(query: SQL): PgMaterializedViewWithSelection<TName, false, BuildColumns<TName, TColumns, 'pg'>>;
|
|
813
618
|
}
|
|
814
|
-
declare class
|
|
815
|
-
private session;
|
|
816
|
-
private dialect;
|
|
619
|
+
declare abstract class PgViewBase<TName extends string = string, TExisting extends boolean = boolean, TSelectedFields extends ColumnsSelection = ColumnsSelection> extends View<TName, TExisting, TSelectedFields> {
|
|
817
620
|
static readonly [entityKind]: string;
|
|
818
|
-
_: {
|
|
819
|
-
|
|
820
|
-
return: TReturning;
|
|
621
|
+
readonly _: View<TName, TExisting, TSelectedFields>['_'] & {
|
|
622
|
+
readonly viewBrand: 'PgViewBase';
|
|
821
623
|
};
|
|
822
|
-
private config;
|
|
823
|
-
constructor(table: TTable, values: PgInsertConfig['values'], session: PgSession, dialect: PgDialect);
|
|
824
|
-
returning(): PgInsert<TTable, TQueryResult, InferModel<TTable>>;
|
|
825
|
-
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): PgInsert<TTable, TQueryResult, SelectResultFields<TSelectedFields>>;
|
|
826
|
-
onConflictDoNothing(config?: {
|
|
827
|
-
target?: IndexColumn | IndexColumn[];
|
|
828
|
-
where?: SQL;
|
|
829
|
-
}): this;
|
|
830
|
-
onConflictDoUpdate(config: {
|
|
831
|
-
target: IndexColumn | IndexColumn[];
|
|
832
|
-
where?: SQL;
|
|
833
|
-
set: PgUpdateSetSource<TTable>;
|
|
834
|
-
}): this;
|
|
835
|
-
toSQL(): Simplify<Omit<Query, 'typings'>>;
|
|
836
|
-
private _prepare;
|
|
837
|
-
prepare(name: string): PreparedQuery<PreparedQueryConfig & {
|
|
838
|
-
execute: TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[];
|
|
839
|
-
}>;
|
|
840
|
-
execute: ReturnType<this['prepare']>['execute'];
|
|
841
624
|
}
|
|
842
|
-
|
|
843
|
-
declare class
|
|
625
|
+
declare const PgViewConfig: unique symbol;
|
|
626
|
+
declare class PgView<TName extends string = string, TExisting extends boolean = boolean, TSelectedFields extends ColumnsSelection = ColumnsSelection> extends PgViewBase<TName, TExisting, TSelectedFields> {
|
|
844
627
|
static readonly [entityKind]: string;
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
};
|
|
858
|
-
selectDistinctOn: {
|
|
859
|
-
(on: (AnyPgColumn | SQLWrapper)[]): PgSelectBuilder<undefined, 'qb'>;
|
|
860
|
-
<TSelection_2 extends SelectedFields>(on: (AnyPgColumn | SQLWrapper)[], fields: TSelection_2): PgSelectBuilder<TSelection_2, "qb">;
|
|
628
|
+
[PgViewConfig]: {
|
|
629
|
+
with?: ViewWithConfig;
|
|
630
|
+
} | undefined;
|
|
631
|
+
constructor({ pgConfig, config }: {
|
|
632
|
+
pgConfig: {
|
|
633
|
+
with?: ViewWithConfig;
|
|
634
|
+
} | undefined;
|
|
635
|
+
config: {
|
|
636
|
+
name: TName;
|
|
637
|
+
schema: string | undefined;
|
|
638
|
+
selectedFields: SelectedFields;
|
|
639
|
+
query: SQL | undefined;
|
|
861
640
|
};
|
|
862
|
-
};
|
|
863
|
-
select(): PgSelectBuilder<undefined, 'qb'>;
|
|
864
|
-
select<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection, 'qb'>;
|
|
865
|
-
selectDistinct(): PgSelectBuilder<undefined>;
|
|
866
|
-
selectDistinct<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection>;
|
|
867
|
-
selectDistinctOn(on: (AnyPgColumn | SQLWrapper)[]): PgSelectBuilder<undefined>;
|
|
868
|
-
selectDistinctOn<TSelection extends SelectedFields>(on: (AnyPgColumn | SQLWrapper)[], fields: TSelection): PgSelectBuilder<TSelection>;
|
|
869
|
-
private getDialect;
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
interface PgRefreshMaterializedView<TQueryResult extends QueryResultHKT> extends QueryPromise<QueryResultKind<TQueryResult, never>> {
|
|
641
|
+
});
|
|
873
642
|
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
643
|
+
type PgViewWithSelection<TName extends string = string, TExisting extends boolean = boolean, TSelectedFields extends ColumnsSelection = ColumnsSelection> = PgView<TName, TExisting, TSelectedFields> & TSelectedFields;
|
|
644
|
+
declare const PgMaterializedViewConfig: unique symbol;
|
|
645
|
+
declare class PgMaterializedView<TName extends string = string, TExisting extends boolean = boolean, TSelectedFields extends ColumnsSelection = ColumnsSelection> extends PgViewBase<TName, TExisting, TSelectedFields> {
|
|
877
646
|
static readonly [entityKind]: string;
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
647
|
+
readonly [PgMaterializedViewConfig]: {
|
|
648
|
+
readonly with?: PgMaterializedViewWithConfig;
|
|
649
|
+
readonly using?: string;
|
|
650
|
+
readonly tablespace?: string;
|
|
651
|
+
readonly withNoData?: boolean;
|
|
652
|
+
} | undefined;
|
|
653
|
+
constructor({ pgConfig, config }: {
|
|
654
|
+
pgConfig: {
|
|
655
|
+
with: PgMaterializedViewWithConfig | undefined;
|
|
656
|
+
using: string | undefined;
|
|
657
|
+
tablespace: string | undefined;
|
|
658
|
+
withNoData: boolean | undefined;
|
|
659
|
+
} | undefined;
|
|
660
|
+
config: {
|
|
661
|
+
name: TName;
|
|
662
|
+
schema: string | undefined;
|
|
663
|
+
selectedFields: SelectedFields;
|
|
664
|
+
query: SQL | undefined;
|
|
665
|
+
};
|
|
666
|
+
});
|
|
888
667
|
}
|
|
668
|
+
type PgMaterializedViewWithSelection<TName extends string = string, TExisting extends boolean = boolean, TSelectedFields extends ColumnsSelection = ColumnsSelection> = PgMaterializedView<TName, TExisting, TSelectedFields> & TSelectedFields;
|
|
669
|
+
declare function pgView<TName extends string>(name: TName): ViewBuilder<TName>;
|
|
670
|
+
declare function pgView<TName extends string, TColumns extends Record<string, AnyPgColumnBuilder>>(name: TName, columns: TColumns): ManualViewBuilder<TName, TColumns>;
|
|
671
|
+
declare function pgMaterializedView<TName extends string>(name: TName): MaterializedViewBuilder<TName>;
|
|
672
|
+
declare function pgMaterializedView<TName extends string, TColumns extends Record<string, AnyPgColumnBuilder>>(name: TName, columns: TColumns): ManualMaterializedViewBuilder<TName, TColumns>;
|
|
889
673
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
buildDeleteQuery({ table, where, returning }: PgDeleteConfig): SQL;
|
|
897
|
-
buildUpdateSet(table: AnyPgTable, set: UpdateSet): SQL;
|
|
898
|
-
buildUpdateQuery({ table, set, where, returning }: PgUpdateConfig): SQL;
|
|
899
|
-
/**
|
|
900
|
-
* Builds selection SQL with provided fields/expressions
|
|
901
|
-
*
|
|
902
|
-
* Examples:
|
|
903
|
-
*
|
|
904
|
-
* `select <selection> from`
|
|
905
|
-
*
|
|
906
|
-
* `insert ... returning <selection>`
|
|
907
|
-
*
|
|
908
|
-
* If `isSingleTable` is true, then columns won't be prefixed with table name
|
|
909
|
-
*/
|
|
910
|
-
private buildSelection;
|
|
911
|
-
buildSelectQuery({ withList, fields, fieldsFlat, where, having, table, joins, orderBy, groupBy, limit, offset, lockingClauses, distinct, }: PgSelectConfig): SQL;
|
|
912
|
-
buildInsertQuery({ table, values, onConflict, returning }: PgInsertConfig): SQL;
|
|
913
|
-
buildRefreshMaterializedViewQuery({ view, concurrently, withNoData }: {
|
|
914
|
-
view: PgMaterializedView;
|
|
915
|
-
concurrently?: boolean;
|
|
916
|
-
withNoData?: boolean;
|
|
917
|
-
}): SQL;
|
|
918
|
-
prepareTyping(encoder: DriverValueEncoder<unknown, unknown>): QueryTypingsValue;
|
|
919
|
-
sqlToQuery(sql: SQL): Query;
|
|
920
|
-
buildRelationalQueryWithoutPK({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
|
|
921
|
-
fullSchema: Record<string, unknown>;
|
|
922
|
-
schema: TablesRelationalConfig;
|
|
923
|
-
tableNamesMap: Record<string, string>;
|
|
924
|
-
table: AnyPgTable;
|
|
925
|
-
tableConfig: TableRelationalConfig;
|
|
926
|
-
queryConfig: true | DBQueryConfig<'many', true>;
|
|
927
|
-
tableAlias: string;
|
|
928
|
-
nestedQueryRelation?: Relation;
|
|
929
|
-
joinOn?: SQL;
|
|
930
|
-
}): BuildRelationalQueryResult<AnyPgTable, AnyPgColumn>;
|
|
674
|
+
interface Join {
|
|
675
|
+
on: SQL | undefined;
|
|
676
|
+
table: PgTable | Subquery | PgViewBase | SQL;
|
|
677
|
+
alias: string | undefined;
|
|
678
|
+
joinType: JoinType;
|
|
679
|
+
lateral?: boolean;
|
|
931
680
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
681
|
+
type AnyPgSelect = PgSelect<any, any, any, any>;
|
|
682
|
+
type BuildAliasTable<TTable extends PgTable | View, TAlias extends string> = TTable extends Table ? PgTableWithColumns<UpdateTableConfig<TTable['_']['config'], {
|
|
683
|
+
name: TAlias;
|
|
684
|
+
columns: MapColumnsToTableAlias<TTable['_']['columns'], TAlias, 'pg'>;
|
|
685
|
+
}>> : TTable extends View ? PgViewWithSelection<TAlias, TTable['_']['existing'], MapColumnsToTableAlias<TTable['_']['selectedFields'], TAlias, 'pg'>> : never;
|
|
686
|
+
interface PgSelectConfig {
|
|
687
|
+
withList?: Subquery[];
|
|
688
|
+
fields: Record<string, unknown>;
|
|
689
|
+
fieldsFlat?: SelectedFieldsOrdered;
|
|
690
|
+
where?: SQL;
|
|
691
|
+
having?: SQL;
|
|
692
|
+
table: PgTable | Subquery | PgViewBase | SQL;
|
|
693
|
+
limit?: number | Placeholder;
|
|
694
|
+
offset?: number | Placeholder;
|
|
695
|
+
joins?: Join[];
|
|
696
|
+
orderBy?: (PgColumn | SQL | SQL.Aliased)[];
|
|
697
|
+
groupBy?: (PgColumn | SQL | SQL.Aliased)[];
|
|
698
|
+
lockingClauses?: {
|
|
699
|
+
strength: LockStrength;
|
|
700
|
+
config: LockConfig;
|
|
701
|
+
}[];
|
|
702
|
+
distinct?: boolean | {
|
|
703
|
+
on: (PgColumn | SQLWrapper)[];
|
|
704
|
+
};
|
|
945
705
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
706
|
+
type JoinFn<THKT extends PgSelectHKTBase, TTableName extends string | undefined, TSelectMode extends SelectMode, TJoinType extends JoinType, TSelection, TNullabilityMap extends Record<string, JoinNullability>> = <TJoinedTable extends PgTable | Subquery | PgViewBase | SQL, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: ((aliases: TSelection) => SQL | undefined) | SQL | undefined) => PgSelectKind<THKT, TTableName, AppendToResult<TTableName, TSelection, TJoinedName, TJoinedTable extends Table ? TJoinedTable['_']['columns'] : TJoinedTable extends Subquery ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields> : never, TSelectMode>, TSelectMode extends 'partial' ? TSelectMode : 'multiple', AppendToNullabilityMap<TNullabilityMap, TJoinedName, TJoinType>>;
|
|
707
|
+
type SelectedFieldsFlat = SelectedFieldsFlat$1<PgColumn>;
|
|
708
|
+
type SelectedFields = SelectedFields$1<PgColumn, PgTable>;
|
|
709
|
+
type SelectedFieldsOrdered = SelectedFieldsOrdered$1<PgColumn>;
|
|
710
|
+
type LockStrength = 'update' | 'no key update' | 'share' | 'key share';
|
|
711
|
+
type LockConfig = {
|
|
712
|
+
of?: PgTable;
|
|
713
|
+
} & ({
|
|
714
|
+
noWait: true;
|
|
715
|
+
skipLocked?: undefined;
|
|
716
|
+
} | {
|
|
717
|
+
noWait?: undefined;
|
|
718
|
+
skipLocked: true;
|
|
719
|
+
} | {
|
|
720
|
+
noWait?: undefined;
|
|
721
|
+
skipLocked?: undefined;
|
|
722
|
+
});
|
|
723
|
+
interface PgSelectHKTBase {
|
|
724
|
+
tableName: string | undefined;
|
|
725
|
+
selection: unknown;
|
|
726
|
+
selectMode: SelectMode;
|
|
727
|
+
nullabilityMap: unknown;
|
|
728
|
+
_type: unknown;
|
|
964
729
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
/** @internal */
|
|
977
|
-
dialect: PgDialect,
|
|
978
|
-
/** @internal */
|
|
979
|
-
session: PgSession<any, any, any>, schema: RelationalSchemaConfig<TSchema> | undefined);
|
|
980
|
-
$with<TAlias extends string>(alias: TAlias): {
|
|
981
|
-
as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection, unknown> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection, unknown>)): WithSubqueryWithSelection<TSelection, TAlias>;
|
|
982
|
-
};
|
|
983
|
-
with(...queries: WithSubquery[]): {
|
|
984
|
-
select: {
|
|
985
|
-
(): PgSelectBuilder<undefined>;
|
|
986
|
-
<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection, "db">;
|
|
987
|
-
};
|
|
988
|
-
};
|
|
989
|
-
select(): PgSelectBuilder<undefined>;
|
|
990
|
-
select<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection>;
|
|
991
|
-
selectDistinct(): PgSelectBuilder<undefined>;
|
|
992
|
-
selectDistinct<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection>;
|
|
993
|
-
selectDistinctOn(on: (AnyPgColumn | SQLWrapper)[]): PgSelectBuilder<undefined>;
|
|
994
|
-
selectDistinctOn<TSelection extends SelectedFields>(on: (AnyPgColumn | SQLWrapper)[], fields: TSelection): PgSelectBuilder<TSelection>;
|
|
995
|
-
update<TTable extends AnyPgTable>(table: TTable): PgUpdateBuilder<TTable, TQueryResult>;
|
|
996
|
-
insert<TTable extends AnyPgTable>(table: TTable): PgInsertBuilder<TTable, TQueryResult>;
|
|
997
|
-
delete<TTable extends AnyPgTable>(table: TTable): PgDelete<TTable, TQueryResult>;
|
|
998
|
-
refreshMaterializedView<TView extends PgMaterializedView>(view: TView): PgRefreshMaterializedView<TQueryResult>;
|
|
999
|
-
execute<TRow extends Record<string, unknown> = Record<string, unknown>>(query: SQLWrapper): Promise<QueryResultKind<TQueryResult, TRow>>;
|
|
1000
|
-
transaction<T>(transaction: (tx: PgTransaction<TQueryResult, TFullSchema, TSchema>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
730
|
+
type PgSelectKind<T extends PgSelectHKTBase, TTableName extends string | undefined, TSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability>> = (T & {
|
|
731
|
+
tableName: TTableName;
|
|
732
|
+
selection: TSelection;
|
|
733
|
+
selectMode: TSelectMode;
|
|
734
|
+
nullabilityMap: TNullabilityMap;
|
|
735
|
+
})['_type'];
|
|
736
|
+
interface PgSelectQueryBuilderHKT extends PgSelectHKTBase {
|
|
737
|
+
_type: PgSelectQueryBuilder<this, this['tableName'], Assume<this['selection'], ColumnsSelection>, this['selectMode'], Assume<this['nullabilityMap'], Record<string, JoinNullability>>>;
|
|
738
|
+
}
|
|
739
|
+
interface PgSelectHKT extends PgSelectHKTBase {
|
|
740
|
+
_type: PgSelect<this['tableName'], Assume<this['selection'], ColumnsSelection>, this['selectMode'], Assume<this['nullabilityMap'], Record<string, JoinNullability>>>;
|
|
1001
741
|
}
|
|
1002
742
|
|
|
1003
|
-
export {
|
|
743
|
+
export { PgViewConfig as $, AnyPgSelect as A, BuildAliasTable as B, PgUpdateConfig as C, PgUpdateSetSource as D, PgUpdateBuilder as E, PgUpdate as F, PreparedQueryConfig as G, PreparedQuery as H, PgTransactionConfig as I, Join as J, PgSession as K, LockStrength as L, PgTransaction as M, QueryResultHKT as N, QueryResultKind as O, PgViewBase as P, QueryBuilder as Q, SubqueryWithSelection as R, SelectedFieldsFlat as S, DefaultViewBuilderCore as T, ViewBuilder as U, ViewWithConfig as V, WithSubqueryWithSelection as W, ManualViewBuilder as X, MaterializedViewBuilderCore as Y, MaterializedViewBuilder as Z, ManualMaterializedViewBuilder as _, pgMaterializedView as a, PgViewWithSelection as a0, PgMaterializedViewConfig as a1, PgMaterializedViewWithSelection as a2, PgView as b, PgMaterializedView as c, PgMaterializedViewWithConfig as d, PgDatabase as e, PgDialect as f, PgDeleteConfig as g, PgDelete as h, PgInsertConfig as i, PgInsertValue as j, PgInsertBuilder as k, PgInsert as l, PgRefreshMaterializedView as m, PgSelectBuilder as n, PgSelectQueryBuilder as o, pgView as p, PgSelect as q, PgSelectConfig as r, JoinFn as s, SelectedFields as t, SelectedFieldsOrdered as u, LockConfig as v, PgSelectHKTBase as w, PgSelectKind as x, PgSelectQueryBuilderHKT as y, PgSelectHKT as z };
|