rado 0.4.8 → 1.0.0-preview.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/dist/core/Builder.d.ts +36 -0
- package/dist/core/Builder.js +99 -0
- package/dist/core/Column.d.ts +38 -0
- package/dist/core/Column.js +59 -0
- package/dist/core/Constraint.d.ts +39 -0
- package/dist/core/Constraint.js +87 -0
- package/dist/core/Database.d.ts +43 -0
- package/dist/core/Database.js +58 -0
- package/dist/core/Dialect.d.ts +6 -0
- package/dist/core/Dialect.js +16 -0
- package/dist/core/Driver.d.ts +28 -0
- package/dist/core/Emitter.d.ts +35 -0
- package/dist/core/Emitter.js +153 -0
- package/dist/core/Index.d.ts +28 -0
- package/dist/core/Index.js +50 -0
- package/dist/core/Internal.d.ts +67 -0
- package/dist/core/Internal.js +62 -0
- package/dist/core/MetaData.d.ts +27 -0
- package/dist/core/Param.d.ts +9 -0
- package/dist/core/Param.js +14 -0
- package/dist/core/Query.d.ts +40 -0
- package/dist/core/Query.js +70 -0
- package/dist/core/Resolver.d.ts +23 -0
- package/dist/core/Resolver.js +54 -0
- package/dist/core/Schema.d.ts +4 -0
- package/dist/core/Schema.js +13 -0
- package/dist/core/Selection.d.ts +27 -0
- package/dist/core/Selection.js +88 -0
- package/dist/core/Sql.d.ts +49 -0
- package/dist/core/Sql.js +153 -0
- package/dist/core/Table.d.ts +56 -0
- package/dist/core/Table.js +103 -0
- package/dist/core/Types.d.ts +3 -0
- package/dist/core/Virtual.d.ts +2 -0
- package/dist/core/Virtual.js +28 -0
- package/dist/core/expr/Aggregate.d.ts +10 -0
- package/dist/core/expr/Aggregate.js +38 -0
- package/dist/core/expr/Conditions.d.ts +40 -0
- package/dist/core/expr/Conditions.js +137 -0
- package/dist/core/expr/Field.d.ts +14 -0
- package/dist/core/expr/Field.js +15 -0
- package/dist/core/expr/Functions.d.ts +6 -0
- package/dist/core/expr/Functions.js +11 -0
- package/dist/core/expr/Input.d.ts +3 -0
- package/dist/core/expr/Input.js +14 -0
- package/dist/core/query/CreateTable.d.ts +13 -0
- package/dist/core/query/CreateTable.js +23 -0
- package/dist/core/query/Delete.d.ts +19 -0
- package/dist/core/query/Delete.js +44 -0
- package/dist/core/query/DropTable.d.ts +13 -0
- package/dist/core/query/DropTable.js +23 -0
- package/dist/core/query/Insert.d.ts +43 -0
- package/dist/core/query/Insert.js +111 -0
- package/dist/core/query/Select.d.ts +93 -0
- package/dist/core/query/Select.js +196 -0
- package/dist/core/query/Union.d.ts +27 -0
- package/dist/core/query/Union.js +86 -0
- package/dist/core/query/Update.d.ts +23 -0
- package/dist/core/query/Update.js +55 -0
- package/dist/driver/better-sqlite3.d.ts +3 -16
- package/dist/driver/better-sqlite3.js +27 -33
- package/dist/driver/bun-sqlite.d.ts +3 -18
- package/dist/driver/bun-sqlite.js +26 -42
- package/dist/driver/pg.d.ts +25 -0
- package/dist/driver/pg.js +81 -0
- package/dist/driver/pglite.d.ts +24 -0
- package/dist/driver/pglite.js +59 -0
- package/dist/driver/sql.js.d.ts +3 -16
- package/dist/driver/sql.js.js +41 -47
- package/dist/index.d.ts +16 -21
- package/dist/index.js +16 -14
- package/dist/migrate/Scan.d.ts +1 -0
- package/dist/migrate/Scan.js +0 -0
- package/dist/postgres/PostgresColumns.d.ts +10 -0
- package/dist/postgres/PostgresColumns.js +58 -0
- package/dist/postgres/PostgresDialect.d.ts +2 -0
- package/dist/postgres/PostgresDialect.js +58 -0
- package/dist/postgres/PostgresSchema.d.ts +1 -0
- package/dist/postgres/PostgresSchema.js +4 -0
- package/dist/postgres/PostgresTable.d.ts +1 -0
- package/dist/postgres/PostgresTable.js +4 -0
- package/dist/postgres.d.ts +2 -0
- package/dist/postgres.js +2 -0
- package/dist/sqlite/SqliteColumns.d.ts +9 -0
- package/dist/sqlite/SqliteColumns.js +63 -0
- package/dist/sqlite/SqliteDialect.d.ts +2 -0
- package/dist/sqlite/SqliteDialect.js +51 -0
- package/dist/sqlite/SqliteFunctions.d.ts +8 -167
- package/dist/sqlite/SqliteFunctions.js +6 -3
- package/dist/sqlite/SqliteTable.d.ts +1 -0
- package/dist/sqlite/SqliteTable.js +4 -0
- package/dist/sqlite.d.ts +3 -2
- package/dist/sqlite.js +3 -2
- package/dist/src/core/Builder.d.ts +36 -0
- package/dist/src/core/Column.d.ts +38 -0
- package/dist/src/core/Constraint.d.ts +39 -0
- package/dist/src/core/Database.d.ts +43 -0
- package/dist/src/core/Dialect.d.ts +6 -0
- package/dist/src/core/Driver.d.ts +28 -0
- package/dist/src/core/Emitter.d.ts +35 -0
- package/dist/src/core/Index.d.ts +28 -0
- package/dist/src/core/Internal.d.ts +67 -0
- package/dist/src/core/MetaData.d.ts +27 -0
- package/dist/src/core/Param.d.ts +9 -0
- package/dist/src/core/Query.d.ts +40 -0
- package/dist/src/core/Resolver.d.ts +23 -0
- package/dist/src/core/Schema.d.ts +4 -0
- package/dist/src/core/Selection.d.ts +27 -0
- package/dist/src/core/Sql.d.ts +49 -0
- package/dist/src/core/Table.d.ts +56 -0
- package/dist/src/core/Types.d.ts +3 -0
- package/dist/src/core/Virtual.d.ts +2 -0
- package/dist/src/core/expr/Aggregate.d.ts +10 -0
- package/dist/src/core/expr/Conditions.d.ts +40 -0
- package/dist/src/core/expr/Field.d.ts +14 -0
- package/dist/src/core/expr/Functions.d.ts +6 -0
- package/dist/src/core/expr/Input.d.ts +3 -0
- package/dist/src/core/query/CreateTable.d.ts +13 -0
- package/dist/src/core/query/Delete.d.ts +19 -0
- package/dist/src/core/query/DropTable.d.ts +13 -0
- package/dist/src/core/query/Insert.d.ts +43 -0
- package/dist/src/core/query/Select.d.ts +93 -0
- package/dist/src/core/query/Union.d.ts +27 -0
- package/dist/src/core/query/Update.d.ts +23 -0
- package/dist/src/driver/better-sqlite3.d.ts +3 -0
- package/dist/src/driver/bun-sqlite.d.ts +4 -0
- package/dist/src/driver/pg.d.ts +25 -0
- package/dist/src/driver/pglite.d.ts +24 -0
- package/dist/src/driver/sql.js.d.ts +3 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/migrate/Scan.d.ts +1 -0
- package/dist/src/postgres/PostgresColumns.d.ts +10 -0
- package/dist/src/postgres/PostgresDialect.d.ts +2 -0
- package/dist/src/postgres/PostgresSchema.d.ts +1 -0
- package/dist/src/postgres/PostgresTable.d.ts +1 -0
- package/dist/src/postgres.d.ts +2 -0
- package/dist/src/sqlite/SqliteColumns.d.ts +9 -0
- package/dist/src/sqlite/SqliteDialect.d.ts +2 -0
- package/dist/src/sqlite/SqliteFunctions.d.ts +8 -0
- package/dist/src/sqlite/SqliteTable.d.ts +1 -0
- package/dist/src/sqlite.d.ts +3 -0
- package/dist/src/universal/UniversalColumns.d.ts +6 -0
- package/dist/src/universal/UniversalTransaction.d.ts +3 -0
- package/dist/src/universal.d.ts +2 -0
- package/dist/test/Suite.d.ts +11 -0
- package/dist/test/TestDriver.d.ts +2 -0
- package/dist/test/TestUtils.d.ts +4 -0
- package/dist/test/core/Expr.test.d.ts +1 -0
- package/dist/test/core/Selection.test.d.ts +1 -0
- package/dist/test/core/Sql.test.d.ts +1 -0
- package/dist/test/core/SqliteFunctions.test.d.ts +1 -0
- package/dist/test/core/Table.test.d.ts +1 -0
- package/dist/test/driver/better-sqlite3.test.d.ts +1 -0
- package/dist/test/driver/bun-sqlite.test.d.ts +1 -0
- package/dist/test/driver/pg.test.d.ts +1 -0
- package/dist/test/driver/pglite.test.d.ts +1 -0
- package/dist/test/driver/sql.js.test.d.ts +1 -0
- package/dist/test/query/CreateTable.test.d.ts +1 -0
- package/dist/test/query/Delete.test.d.ts +1 -0
- package/dist/test/query/DropTable.test.d.ts +1 -0
- package/dist/test/query/Insert.test.d.ts +1 -0
- package/dist/test/query/Select.test.d.ts +1 -0
- package/dist/test/query/Union.test.d.ts +1 -0
- package/dist/test/query/Update.test.d.ts +1 -0
- package/dist/universal/UniversalColumns.d.ts +6 -0
- package/dist/universal/UniversalColumns.js +56 -0
- package/dist/universal/UniversalTransaction.d.ts +3 -0
- package/dist/universal/UniversalTransaction.js +14 -0
- package/dist/universal.d.ts +2 -0
- package/dist/universal.js +2 -0
- package/package.json +25 -43
- package/dist/define/Column.d.ts +0 -122
- package/dist/define/Column.js +0 -183
- package/dist/define/Expr.d.ts +0 -183
- package/dist/define/Expr.js +0 -453
- package/dist/define/Fields.d.ts +0 -18
- package/dist/define/Functions.d.ts +0 -5
- package/dist/define/Functions.js +0 -12
- package/dist/define/Id.d.ts +0 -3
- package/dist/define/Index.d.ts +0 -17
- package/dist/define/Index.js +0 -19
- package/dist/define/Ops.d.ts +0 -36
- package/dist/define/Ops.js +0 -114
- package/dist/define/OrderBy.d.ts +0 -9
- package/dist/define/OrderBy.js +0 -8
- package/dist/define/Param.d.ts +0 -18
- package/dist/define/Param.js +0 -27
- package/dist/define/Query.d.ts +0 -268
- package/dist/define/Query.js +0 -596
- package/dist/define/Schema.d.ts +0 -12
- package/dist/define/Schema.js +0 -140
- package/dist/define/Selection.d.ts +0 -21
- package/dist/define/Selection.js +0 -6
- package/dist/define/Sql.d.ts +0 -6
- package/dist/define/Sql.js +0 -21
- package/dist/define/Table.d.ts +0 -75
- package/dist/define/Table.js +0 -138
- package/dist/define/Target.d.ts +0 -47
- package/dist/define/Target.js +0 -68
- package/dist/define/VirtualTable.d.ts +0 -31
- package/dist/define/VirtualTable.js +0 -39
- package/dist/driver/@sqlite.org/sqlite-wasm.d.ts +0 -17
- package/dist/driver/@sqlite.org/sqlite-wasm.js +0 -80
- package/dist/driver/d1.d.ts +0 -22
- package/dist/driver/d1.js +0 -71
- package/dist/driver/sqlite3.d.ts +0 -22
- package/dist/driver/sqlite3.js +0 -132
- package/dist/lib/Driver.d.ts +0 -111
- package/dist/lib/Driver.js +0 -398
- package/dist/lib/Formatter.d.ts +0 -106
- package/dist/lib/Formatter.js +0 -888
- package/dist/lib/Sanitizer.d.ts +0 -5
- package/dist/lib/SqlError.d.ts +0 -3
- package/dist/lib/SqlError.js +0 -10
- package/dist/lib/Statement.d.ts +0 -108
- package/dist/lib/Statement.js +0 -190
- package/dist/sqlite/SqliteFormatter.d.ts +0 -11
- package/dist/sqlite/SqliteFormatter.js +0 -66
- package/dist/sqlite/SqliteSchema.d.ts +0 -25
- package/dist/sqlite/SqliteSchema.js +0 -46
- package/dist/util/Alias.d.ts +0 -1
- package/dist/util/Alias.js +0 -6
- package/dist/util/Callable.d.ts +0 -16
- package/dist/util/Callable.js +0 -9
- /package/dist/{define/Fields.js → core/Driver.js} +0 -0
- /package/dist/{define/Id.js → core/MetaData.js} +0 -0
- /package/dist/{lib/Sanitizer.js → core/Types.js} +0 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { internalData, internalQuery, type HasQuery, type HasResolver, type HasTarget } from './Internal.ts';
|
|
2
|
+
import type { Async, QueryMeta, Sync } from './MetaData.ts';
|
|
3
|
+
import type { PreparedStatement, Resolver } from './Resolver.ts';
|
|
4
|
+
import type { Sql } from './Sql.ts';
|
|
5
|
+
export declare class QueryData<Meta extends QueryMeta> {
|
|
6
|
+
resolver?: Resolver<Meta>;
|
|
7
|
+
cte?: Array<HasQuery & HasTarget>;
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class Query<Result, Meta extends QueryMeta> implements PromiseLike<Array<Result>> {
|
|
10
|
+
#private;
|
|
11
|
+
readonly [internalData]: QueryData<Meta>;
|
|
12
|
+
abstract [internalQuery]: Sql;
|
|
13
|
+
constructor(data: QueryData<Meta>);
|
|
14
|
+
[Symbol.iterator](): Generator<Promise<unknown>, Array<Result>, unknown>;
|
|
15
|
+
prepare<Inputs extends Record<string, unknown>>(name: string): PreparedQuery<Result, Inputs, Meta>;
|
|
16
|
+
all(this: Query<Result, Sync>): Array<Result>;
|
|
17
|
+
all(this: Query<Result, Async>): Promise<Array<Result>>;
|
|
18
|
+
all(db: HasResolver<Sync> | Resolver<Sync>): Array<Result>;
|
|
19
|
+
all(db: HasResolver<Async> | Resolver<Async>): Promise<Array<Result>>;
|
|
20
|
+
get(this: Query<Result, Sync>): Result;
|
|
21
|
+
get(this: Query<Result, Async>): Promise<Result>;
|
|
22
|
+
get(db: HasResolver<Sync> | Resolver<Sync>): Result;
|
|
23
|
+
get(db: HasResolver<Async> | Resolver<Async>): Promise<Result>;
|
|
24
|
+
run(this: Query<Result, Sync>): void;
|
|
25
|
+
run(this: Query<Result, Async>): Promise<void>;
|
|
26
|
+
run(db: HasResolver<Sync> | Resolver<Sync>): void;
|
|
27
|
+
run(db: HasResolver<Async> | Resolver<Async>): Promise<void>;
|
|
28
|
+
then<TResult1 = Array<Result>, TResult2 = never>(this: Query<Result, Sync | Async>, onfulfilled?: ((value: Array<Result>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
29
|
+
catch<TResult = never>(this: Query<Result, Async>, onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<Array<Result> | TResult>;
|
|
30
|
+
finally(this: Query<Result, Async>, onfinally?: (() => void) | undefined | null): Promise<Array<Result>>;
|
|
31
|
+
}
|
|
32
|
+
export interface PreparedQuery<Result, Inputs extends Record<string, unknown>, Meta extends QueryMeta> extends PreparedStatement<Meta> {
|
|
33
|
+
all(this: PreparedQuery<Result, Inputs, Sync>, inputs?: Inputs): Array<Result>;
|
|
34
|
+
all(this: PreparedQuery<Result, Inputs, Async>, inputs?: Inputs): Promise<Array<Result>>;
|
|
35
|
+
get(this: PreparedQuery<Result, Inputs, Sync>, inputs?: Inputs): Result;
|
|
36
|
+
get(this: PreparedQuery<Result, Inputs, Async>, inputs?: Inputs): Promise<Result>;
|
|
37
|
+
run(this: PreparedQuery<Result, Inputs, Sync>, inputs?: Inputs): void;
|
|
38
|
+
run(this: PreparedQuery<Result, Inputs, Async>, inputs?: Inputs): Promise<void>;
|
|
39
|
+
execute(inputs?: Inputs): Promise<Array<Result>>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Dialect } from './Dialect.ts';
|
|
2
|
+
import type { Driver, Statement } from './Driver.ts';
|
|
3
|
+
import type { Emitter } from './Emitter.ts';
|
|
4
|
+
import { type HasQuery } from './Internal.ts';
|
|
5
|
+
import type { QueryMeta } from './MetaData.ts';
|
|
6
|
+
export declare class Resolver<Meta extends QueryMeta = QueryMeta> {
|
|
7
|
+
#private;
|
|
8
|
+
private brand;
|
|
9
|
+
constructor(driver: Driver, dialect: Dialect);
|
|
10
|
+
prepare(query: HasQuery, name: string): PreparedStatement<Meta>;
|
|
11
|
+
}
|
|
12
|
+
type RowMapper = ((values: Array<unknown>) => unknown) | undefined;
|
|
13
|
+
export declare class PreparedStatement<Meta extends QueryMeta> {
|
|
14
|
+
#private;
|
|
15
|
+
private brand;
|
|
16
|
+
constructor(emitter: Emitter, stmt: Statement, mapRow: RowMapper);
|
|
17
|
+
all(inputs?: Record<string, unknown>): Array<unknown> | Promise<Array<unknown>>;
|
|
18
|
+
get(inputs?: Record<string, unknown>): unknown | Promise<unknown>;
|
|
19
|
+
run(inputs?: Record<string, unknown>): unknown;
|
|
20
|
+
execute(inputs?: Record<string, unknown>): Promise<unknown>;
|
|
21
|
+
free(): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Table, type TableConfig, type TableDefinition } from './Table.ts';
|
|
2
|
+
export declare function schema<SchemaName extends string>(schemaName: SchemaName): {
|
|
3
|
+
table<Definition extends TableDefinition, TableName extends string>(tableName: TableName, columns: Definition, config?: ((self: Table<Definition>) => TableConfig<`${SchemaName}.${TableName}`>) | undefined): Table<Definition, `${SchemaName}.${TableName}`>;
|
|
4
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { internalSql, type HasSql, type HasTable } from './Internal.ts';
|
|
2
|
+
import { type Sql } from './Sql.ts';
|
|
3
|
+
import type { Table, TableRow } from './Table.ts';
|
|
4
|
+
import type { Expand } from './Types.ts';
|
|
5
|
+
declare const nullable: unique symbol;
|
|
6
|
+
export interface SelectionRecord extends Record<string, SelectionInput> {
|
|
7
|
+
}
|
|
8
|
+
export type IsNullable = {
|
|
9
|
+
[nullable]: true;
|
|
10
|
+
};
|
|
11
|
+
export type MakeNullable<T> = Expand<{
|
|
12
|
+
[K in keyof T]: T[K] & IsNullable;
|
|
13
|
+
}>;
|
|
14
|
+
export type SelectionInput = HasSql | HasTable | SelectionRecord;
|
|
15
|
+
export type RowOfRecord<Input> = Expand<{
|
|
16
|
+
[Key in keyof Input as Key extends string ? Key : never]: SelectionRow<Input[Key]>;
|
|
17
|
+
}>;
|
|
18
|
+
export type SelectionRow<Input> = Input extends HasSql<infer Value> ? Value : Input extends IsNullable ? RowOfRecord<Input> | null : Input extends SelectionRecord ? RowOfRecord<Input> : Input extends Table<infer Definition> ? TableRow<Definition> : never;
|
|
19
|
+
export declare class Selection implements HasSql {
|
|
20
|
+
#private;
|
|
21
|
+
constructor(input: SelectionInput, nullable: Set<string>);
|
|
22
|
+
makeVirtual(name: string): SelectionRecord | HasSql<unknown> | HasTable<import("./Table.ts").TableDefinition, string>;
|
|
23
|
+
mapRow: (values: Array<unknown>) => unknown;
|
|
24
|
+
get [internalSql](): Sql<unknown>;
|
|
25
|
+
}
|
|
26
|
+
export declare function selection(input: SelectionInput, nullable?: Set<string>): Selection;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Emitter } from './Emitter.ts';
|
|
2
|
+
import { internalSql, type HasSql } from './Internal.ts';
|
|
3
|
+
import type { FieldData } from './expr/Field.ts';
|
|
4
|
+
type EmitMethods = {
|
|
5
|
+
[K in keyof Emitter as K extends `emit${string}` ? K : never]: Emitter[K];
|
|
6
|
+
};
|
|
7
|
+
declare class Chunk<Type = keyof EmitMethods, Inner = unknown> {
|
|
8
|
+
type: Type;
|
|
9
|
+
inner: Inner;
|
|
10
|
+
constructor(type: Type, inner: Inner);
|
|
11
|
+
}
|
|
12
|
+
export type Decoder<T> = ((value: unknown) => T) | {
|
|
13
|
+
mapFromDriverValue?(value: unknown): T;
|
|
14
|
+
};
|
|
15
|
+
export declare class Sql<Value = unknown> implements HasSql<Value> {
|
|
16
|
+
#private;
|
|
17
|
+
private brand;
|
|
18
|
+
alias?: string;
|
|
19
|
+
mapFromDriverValue?: (input: unknown) => Value;
|
|
20
|
+
readonly [internalSql]: this;
|
|
21
|
+
constructor(chunks?: Array<Chunk>);
|
|
22
|
+
as(name: string): Sql<Value>;
|
|
23
|
+
mapWith<T = Value>(decoder: Decoder<T>): Sql<T>;
|
|
24
|
+
chunk<Type extends keyof EmitMethods>(type: Type, inner: Parameters<EmitMethods[Type]>[0]): Sql<Value>;
|
|
25
|
+
unsafe(sql: string): Sql<Value>;
|
|
26
|
+
field(field: FieldData): Sql<Value>;
|
|
27
|
+
add(sql: HasSql): Sql<Value>;
|
|
28
|
+
value(value: unknown): Sql<Value>;
|
|
29
|
+
inline(value: unknown): Sql<Value>;
|
|
30
|
+
jsonPath(path: Array<string | number>): Sql<Value>;
|
|
31
|
+
placeholder(name: string): Sql<Value>;
|
|
32
|
+
identifier(identifier: string): Sql<Value>;
|
|
33
|
+
inlineFields(withTableName: boolean): Sql<Value>;
|
|
34
|
+
emit(emitter: Emitter): void;
|
|
35
|
+
}
|
|
36
|
+
export declare function sql<T>(strings: TemplateStringsArray, ...inner: Array<HasSql>): Sql<T>;
|
|
37
|
+
export declare namespace sql {
|
|
38
|
+
function empty<T>(): Sql<T>;
|
|
39
|
+
function unsafe<T>(directSql: string): Sql<T>;
|
|
40
|
+
function value<T>(value: T): Sql<T>;
|
|
41
|
+
function inline<T>(value: T): Sql<T>;
|
|
42
|
+
function placeholder<T>(name: string): Sql<T>;
|
|
43
|
+
function identifier<T>(identifier: string): Sql<T>;
|
|
44
|
+
function field<T>(field: FieldData): Sql<T>;
|
|
45
|
+
function chunk<Type extends keyof EmitMethods>(type: Type, inner: Parameters<EmitMethods[Type]>[0]): Sql;
|
|
46
|
+
function query(ast: Record<string, HasSql | undefined>): Sql;
|
|
47
|
+
function join<T>(items: Array<Sql | HasSql | undefined | false>, separator?: Sql): Sql<T>;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Column, JsonColumn, RequiredColumn } from './Column.ts';
|
|
2
|
+
import type { ForeignKeyConstraint, PrimaryKeyConstraint, UniqueConstraint } from './Constraint.ts';
|
|
3
|
+
import type { Index } from './Index.ts';
|
|
4
|
+
import { type HasSql, type HasTable, type HasTarget } from './Internal.ts';
|
|
5
|
+
import { type Sql } from './Sql.ts';
|
|
6
|
+
import { type JsonExpr } from './expr/Conditions.ts';
|
|
7
|
+
import { Field } from './expr/Field.ts';
|
|
8
|
+
import type { Input } from './expr/Input.ts';
|
|
9
|
+
export type TableDefinition = {
|
|
10
|
+
[name: string]: Column;
|
|
11
|
+
};
|
|
12
|
+
declare class TableData {
|
|
13
|
+
name: string;
|
|
14
|
+
alias?: string;
|
|
15
|
+
schemaName?: string;
|
|
16
|
+
columns: TableDefinition;
|
|
17
|
+
config?: TableConfig;
|
|
18
|
+
}
|
|
19
|
+
export declare class TableApi<Definition extends TableDefinition = TableDefinition, Name extends string = string> extends TableData {
|
|
20
|
+
private brand;
|
|
21
|
+
get aliased(): string;
|
|
22
|
+
target(): Sql;
|
|
23
|
+
createDefinition(): Sql;
|
|
24
|
+
listColumns(): Sql;
|
|
25
|
+
fields(): Record<string, HasSql>;
|
|
26
|
+
}
|
|
27
|
+
export type Table<Definition extends TableDefinition = TableDefinition, Name extends string = string> = TableFields<Definition, Name> & HasTable<Definition, Name> & HasTarget;
|
|
28
|
+
export type TableFields<Definition extends TableDefinition, TableName extends string = string> = {
|
|
29
|
+
[K in keyof Definition]: Definition[K] extends JsonColumn<infer T> ? JsonExpr<T> : Definition[K] extends Column<infer T> ? Field<T, TableName> : never;
|
|
30
|
+
};
|
|
31
|
+
export type TableRow<Definition extends TableDefinition> = {
|
|
32
|
+
[K in keyof Definition]: Definition[K] extends Column<infer T> ? T : never;
|
|
33
|
+
} & {};
|
|
34
|
+
type IsReq<Col> = Col extends RequiredColumn ? true : false;
|
|
35
|
+
type Required<D> = {
|
|
36
|
+
[K in keyof D as true extends IsReq<D[K]> ? K : never]: D[K];
|
|
37
|
+
};
|
|
38
|
+
type Optional<D> = {
|
|
39
|
+
[K in keyof D as false extends IsReq<D[K]> ? K : never]: D[K];
|
|
40
|
+
};
|
|
41
|
+
type RequiredInput<D> = {
|
|
42
|
+
readonly [K in keyof Required<D>]: D[K] extends Column<infer V> ? Input<V> : never;
|
|
43
|
+
};
|
|
44
|
+
type OptionalInput<D> = {
|
|
45
|
+
readonly [K in keyof Optional<D>]?: D[K] extends Column<infer V> ? Input<V> : never;
|
|
46
|
+
};
|
|
47
|
+
export type TableInsert<Definition extends TableDefinition> = RequiredInput<Definition> & OptionalInput<Definition>;
|
|
48
|
+
export type TableUpdate<Definition extends TableDefinition> = {
|
|
49
|
+
readonly [K in keyof Definition]?: Definition[K] extends Column<infer T> ? Input<T> : never;
|
|
50
|
+
};
|
|
51
|
+
export type TableConfigSetting<Name extends string> = UniqueConstraint<Name> | PrimaryKeyConstraint<Name> | ForeignKeyConstraint<Name> | Index<Name>;
|
|
52
|
+
export interface TableConfig<Name extends string = string> extends Record<string, TableConfigSetting<Name>> {
|
|
53
|
+
}
|
|
54
|
+
export declare function table<Definition extends TableDefinition, Name extends string>(name: Name, columns: Definition, config?: (self: Table<Definition, Name>) => TableConfig<Name>, schemaName?: string): Table<Definition, Name>;
|
|
55
|
+
export declare function alias<Definition extends TableDefinition, Alias extends string>(table: Table<Definition>, alias: Alias): Table<Definition, Alias>;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type HasSql } from '../Internal.ts';
|
|
2
|
+
import { type Sql } from '../Sql.ts';
|
|
3
|
+
export declare function count(input?: HasSql): Sql<number>;
|
|
4
|
+
export declare function countDistinct(input: HasSql): Sql<number>;
|
|
5
|
+
export declare function avg(input: HasSql): Sql<string | null>;
|
|
6
|
+
export declare function avgDistinct(input: HasSql): Sql<string | null>;
|
|
7
|
+
export declare function sum(input: HasSql): HasSql<string | null>;
|
|
8
|
+
export declare function sumDistinct(input: HasSql): HasSql<string | null>;
|
|
9
|
+
export declare function max<T>(input: HasSql<T>): Sql<T>;
|
|
10
|
+
export declare function min<T>(input: HasSql<T>): Sql<T>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { HasSql } from '../Internal.ts';
|
|
2
|
+
import { type Sql } from '../Sql.ts';
|
|
3
|
+
import { type Input } from './Input.ts';
|
|
4
|
+
export declare function eq<T>(left: Input<T>, right: Input<T>): HasSql<boolean>;
|
|
5
|
+
export declare function ne<T>(left: Input<T>, right: Input<T>): HasSql<boolean>;
|
|
6
|
+
export declare function and(...conditions: Array<Input<boolean>>): HasSql<boolean>;
|
|
7
|
+
export declare function or(...conditions: Array<Input<boolean>>): HasSql<boolean>;
|
|
8
|
+
export declare function not(condition: Input): HasSql<boolean>;
|
|
9
|
+
export declare function gt<T>(left: Input<T>, right: Input<T>): HasSql<boolean>;
|
|
10
|
+
export declare function gte<T>(left: Input<T>, right: Input<T>): HasSql<boolean>;
|
|
11
|
+
export declare function lt<T>(left: Input<T>, right: Input<T>): HasSql<boolean>;
|
|
12
|
+
export declare function lte<T>(left: Input<T>, right: Input<T>): HasSql<boolean>;
|
|
13
|
+
export declare function inArray<T>(left: Input<T>, right: Input<Array<T>>): HasSql<boolean>;
|
|
14
|
+
export declare function notInArray<T>(left: Input<T>, right: Input<Array<T>>): HasSql<boolean>;
|
|
15
|
+
export declare function isNull(value: Input): HasSql<boolean>;
|
|
16
|
+
export declare function isNotNull(value: Input): HasSql<boolean>;
|
|
17
|
+
export declare function between<T>(value: Input<T>, left: Input<T>, right: Input<T>): HasSql<boolean>;
|
|
18
|
+
export declare function notBetween<T>(value: Input<T>, left: Input<T>, right: Input<T>): HasSql<boolean>;
|
|
19
|
+
export declare function like(left: Input<string>, pattern: Input<string>): HasSql<boolean>;
|
|
20
|
+
export declare function notLike(value: Input<string>, pattern: Input<string>): HasSql<boolean>;
|
|
21
|
+
export declare function ilike(value: Input<string>, pattern: Input<string>): HasSql<boolean>;
|
|
22
|
+
export declare function notILike(value: Input<string>, pattern: Input<string>): HasSql<boolean>;
|
|
23
|
+
export declare function arrayContains<T>(left: Input<Array<T>>, right: Input<T>): HasSql<boolean>;
|
|
24
|
+
export declare function arrayContained<T>(left: Input<T>, right: Input<Array<T>>): HasSql<boolean>;
|
|
25
|
+
export declare function arrayOverlaps<T>(left: Input<Array<T>>, right: Input<Array<T>>): HasSql<boolean>;
|
|
26
|
+
export declare function asc<T>(input: HasSql<T>): Sql;
|
|
27
|
+
export declare function desc<T>(input: HasSql<T>): Sql;
|
|
28
|
+
export declare function distinct<T>(input: HasSql<T>): Sql;
|
|
29
|
+
export interface JsonArrayHasSql<Value> extends HasSql<Value> {
|
|
30
|
+
[index: number]: JsonExpr<Value>;
|
|
31
|
+
}
|
|
32
|
+
export type JsonRecordHasSql<Row> = HasSql<Row> & {
|
|
33
|
+
[K in keyof Row]: JsonExpr<Row[K]>;
|
|
34
|
+
};
|
|
35
|
+
type Nullable<T> = {
|
|
36
|
+
[P in keyof T]: T[P] | null;
|
|
37
|
+
};
|
|
38
|
+
export type JsonExpr<Value> = [NonNullable<Value>] extends [Array<infer V>] ? JsonArrayHasSql<null extends Value ? V | null : V> : [NonNullable<Value>] extends [object] ? JsonRecordHasSql<null extends Value ? Nullable<Value> : Value> : HasSql<Value>;
|
|
39
|
+
export declare function jsonExpr<Value>(e: HasSql<Value>): JsonExpr<Value>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { internalField, internalSql, type HasSql } from '../Internal.ts';
|
|
2
|
+
import { type Sql } from '../Sql.ts';
|
|
3
|
+
export interface FieldData {
|
|
4
|
+
targetName: string;
|
|
5
|
+
fieldName: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class Field<Value = unknown, Table extends string = string> implements HasSql<Value> {
|
|
8
|
+
private brand;
|
|
9
|
+
readonly [internalField]: FieldData;
|
|
10
|
+
readonly [internalSql]: Sql<Value>;
|
|
11
|
+
constructor(targetName: string, fieldName: string, options?: {
|
|
12
|
+
mapFromDriverValue?(value: unknown): Value;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { internalData, internalQuery, type HasTable } from '../Internal.ts';
|
|
2
|
+
import type { QueryMeta } from '../MetaData.ts';
|
|
3
|
+
import { Query, type QueryData } from '../Query.ts';
|
|
4
|
+
export interface CreateData<Meta extends QueryMeta> extends QueryData<Meta> {
|
|
5
|
+
table: HasTable;
|
|
6
|
+
ifNotExists?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class Create<Meta extends QueryMeta = QueryMeta> extends Query<void, Meta> {
|
|
9
|
+
readonly [internalData]: CreateData<Meta>;
|
|
10
|
+
constructor(data: CreateData<Meta>);
|
|
11
|
+
ifNotExists(): Create<Meta>;
|
|
12
|
+
get [internalQuery](): import("../Sql.ts").Sql<unknown>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { internalData, internalQuery, internalSelection, type HasSql, type HasTable } from '../Internal.ts';
|
|
2
|
+
import type { QueryMeta } from '../MetaData.ts';
|
|
3
|
+
import { Query, QueryData } from '../Query.ts';
|
|
4
|
+
import { type Selection, type SelectionInput, type SelectionRow } from '../Selection.ts';
|
|
5
|
+
export declare class DeleteData<Meta extends QueryMeta = QueryMeta> extends QueryData<Meta> {
|
|
6
|
+
from: HasTable;
|
|
7
|
+
where?: HasSql;
|
|
8
|
+
returning?: Selection;
|
|
9
|
+
}
|
|
10
|
+
export declare class Delete<Result, Meta extends QueryMeta = QueryMeta> extends Query<Result, Meta> {
|
|
11
|
+
readonly [internalData]: DeleteData<Meta>;
|
|
12
|
+
readonly [internalSelection]?: Selection;
|
|
13
|
+
constructor(data: DeleteData<Meta>);
|
|
14
|
+
get [internalQuery](): import("../Sql.ts").Sql<unknown>;
|
|
15
|
+
}
|
|
16
|
+
export declare class DeleteFrom<Meta extends QueryMeta> extends Delete<void, Meta> {
|
|
17
|
+
where(condition: HasSql<boolean>): DeleteFrom<Meta>;
|
|
18
|
+
returning<Input extends SelectionInput>(returning: Input): Delete<SelectionRow<Input>, Meta>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { internalData, internalQuery, type HasTable } from '../Internal.ts';
|
|
2
|
+
import type { QueryMeta } from '../MetaData.ts';
|
|
3
|
+
import { Query, type QueryData } from '../Query.ts';
|
|
4
|
+
export interface DropData<Meta extends QueryMeta> extends QueryData<Meta> {
|
|
5
|
+
table: HasTable;
|
|
6
|
+
ifExists?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class Drop<Meta extends QueryMeta = QueryMeta> extends Query<void, Meta> {
|
|
9
|
+
readonly [internalData]: DropData<Meta>;
|
|
10
|
+
constructor(data: DropData<Meta>);
|
|
11
|
+
ifExists(): Drop<Meta>;
|
|
12
|
+
get [internalQuery](): import("../Sql.ts").Sql<unknown>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { internalData, internalQuery, internalSelection, type HasSql, type HasTable } from '../Internal.ts';
|
|
2
|
+
import type { IsPostgres, QueryMeta } from '../MetaData.ts';
|
|
3
|
+
import { Query, QueryData } from '../Query.ts';
|
|
4
|
+
import { type Selection, type SelectionInput, type SelectionRow } from '../Selection.ts';
|
|
5
|
+
import type { TableDefinition, TableInsert, TableRow, TableUpdate } from '../Table.ts';
|
|
6
|
+
declare class InsertIntoData<Meta extends QueryMeta> extends QueryData<Meta> {
|
|
7
|
+
into: HasTable;
|
|
8
|
+
values?: HasSql;
|
|
9
|
+
}
|
|
10
|
+
export declare class InsertData<Meta extends QueryMeta> extends InsertIntoData<Meta> {
|
|
11
|
+
returning?: Selection;
|
|
12
|
+
onConflict?: HasSql;
|
|
13
|
+
}
|
|
14
|
+
export declare class Insert<Result, Meta extends QueryMeta = QueryMeta> extends Query<Result, Meta> {
|
|
15
|
+
readonly [internalData]: InsertData<Meta>;
|
|
16
|
+
readonly [internalSelection]?: Selection;
|
|
17
|
+
constructor(data: InsertData<Meta>);
|
|
18
|
+
get [internalQuery](): import("../Sql.ts").Sql<unknown>;
|
|
19
|
+
}
|
|
20
|
+
declare class InsertCanReturn<Definition extends TableDefinition, Meta extends QueryMeta> extends Insert<void, Meta> {
|
|
21
|
+
returning(): Insert<TableRow<Definition>, Meta>;
|
|
22
|
+
returning<Input extends SelectionInput>(returning: Input): Insert<SelectionRow<Input>, Meta>;
|
|
23
|
+
}
|
|
24
|
+
export interface OnConflict {
|
|
25
|
+
target: HasSql | Array<HasSql>;
|
|
26
|
+
targetWhere?: HasSql<boolean>;
|
|
27
|
+
}
|
|
28
|
+
export interface OnConflictUpdate<Definition extends TableDefinition> extends OnConflict {
|
|
29
|
+
set: TableUpdate<Definition>;
|
|
30
|
+
setWhere?: HasSql<boolean>;
|
|
31
|
+
}
|
|
32
|
+
declare class InsertCanConflict<Definition extends TableDefinition, Meta extends QueryMeta> extends InsertCanReturn<Definition, Meta> {
|
|
33
|
+
#private;
|
|
34
|
+
onConflictDoNothing(this: InsertCanConflict<Definition, IsPostgres>, onConflict?: OnConflict): InsertCanReturn<Definition, Meta>;
|
|
35
|
+
onConflictDoUpdate(this: InsertCanConflict<Definition, IsPostgres>, onConflict: OnConflictUpdate<Definition>): InsertCanReturn<Definition, Meta>;
|
|
36
|
+
}
|
|
37
|
+
export declare class InsertInto<Definition extends TableDefinition, Meta extends QueryMeta> {
|
|
38
|
+
[internalData]: InsertData<Meta>;
|
|
39
|
+
constructor(data: InsertData<Meta>);
|
|
40
|
+
values(value: TableInsert<Definition>): InsertCanConflict<Definition, Meta>;
|
|
41
|
+
values(values: Array<TableInsert<Definition>>): InsertCanConflict<Definition, Meta>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { internalData, internalQuery, internalSelection, type HasSelection, type HasSql, type HasTable, type HasTarget } from '../Internal.ts';
|
|
2
|
+
import type { IsMysql, IsPostgres, QueryMeta } from '../MetaData.ts';
|
|
3
|
+
import { Query, QueryData } from '../Query.ts';
|
|
4
|
+
import { type IsNullable, type MakeNullable, type SelectionInput, type SelectionRecord, type SelectionRow } from '../Selection.ts';
|
|
5
|
+
import type { Table, TableDefinition, TableFields } from '../Table.ts';
|
|
6
|
+
import type { Expand } from '../Types.ts';
|
|
7
|
+
import type { Field } from '../expr/Field.ts';
|
|
8
|
+
import { type Input as UserInput } from '../expr/Input.ts';
|
|
9
|
+
import { Union } from './Union.ts';
|
|
10
|
+
export type SelectionType = 'selection' | 'allFrom' | 'joinTables';
|
|
11
|
+
export declare class SelectData<Meta extends QueryMeta> extends QueryData<Meta> {
|
|
12
|
+
select: {
|
|
13
|
+
type: SelectionType;
|
|
14
|
+
tables: Array<string>;
|
|
15
|
+
nullable: Array<string>;
|
|
16
|
+
input?: SelectionInput;
|
|
17
|
+
};
|
|
18
|
+
distinct?: boolean;
|
|
19
|
+
distinctOn?: Array<HasSql>;
|
|
20
|
+
from?: HasSql;
|
|
21
|
+
subject?: HasSql;
|
|
22
|
+
where?: HasSql;
|
|
23
|
+
groupBy?: HasSql;
|
|
24
|
+
having?: HasSql;
|
|
25
|
+
orderBy?: HasSql;
|
|
26
|
+
limit?: HasSql;
|
|
27
|
+
offset?: HasSql;
|
|
28
|
+
}
|
|
29
|
+
export declare class Select<Input, Meta extends QueryMeta = QueryMeta> extends Query<SelectionRow<Input>, Meta> implements HasSelection, SelectBase<Input, Meta> {
|
|
30
|
+
#private;
|
|
31
|
+
readonly [internalData]: SelectData<Meta>;
|
|
32
|
+
constructor(data: SelectData<Meta>);
|
|
33
|
+
as(alias: string): SubQuery<Input>;
|
|
34
|
+
from(target: HasTarget): Select<Input, Meta>;
|
|
35
|
+
leftJoin(right: HasTable, on: HasSql<boolean>): Select<Input, Meta>;
|
|
36
|
+
rightJoin(right: HasTable, on: HasSql<boolean>): Select<Input, Meta>;
|
|
37
|
+
innerJoin(right: HasTable, on: HasSql<boolean>): Select<Input, Meta>;
|
|
38
|
+
fullJoin(right: HasTable, on: HasSql<boolean>): Select<Input, Meta>;
|
|
39
|
+
where(where: HasSql<boolean>): Select<Input, Meta>;
|
|
40
|
+
groupBy(...exprs: Array<HasSql>): Select<Input, Meta>;
|
|
41
|
+
having(having: HasSql<boolean>): Select<Input, Meta>;
|
|
42
|
+
orderBy(...exprs: Array<HasSql>): Select<Input, Meta>;
|
|
43
|
+
limit(limit: UserInput<number>): Select<Input, Meta>;
|
|
44
|
+
offset(offset: UserInput<number>): Select<Input, Meta>;
|
|
45
|
+
union(right: SelectBase<Input, Meta>): Union<Input, Meta>;
|
|
46
|
+
unionAll(right: SelectBase<Input, Meta>): Union<Input, Meta>;
|
|
47
|
+
intersect(right: SelectBase<Input, Meta>): Union<Input, Meta>;
|
|
48
|
+
intersectAll(this: SelectBase<Input, IsPostgres | IsMysql>, right: SelectBase<Input, Meta>): Union<Input, Meta>;
|
|
49
|
+
except(right: SelectBase<Input, Meta>): Union<Input, Meta>;
|
|
50
|
+
exceptAll(right: SelectBase<Input, IsPostgres | IsMysql>): Union<Input, Meta>;
|
|
51
|
+
get [internalSelection](): import("../Selection.ts").Selection;
|
|
52
|
+
get [internalQuery](): import("../Sql.ts").Sql<unknown>;
|
|
53
|
+
}
|
|
54
|
+
export type SubQuery<Input> = Input & HasTarget;
|
|
55
|
+
export interface SelectBase<Input, Meta extends QueryMeta = QueryMeta> extends Query<SelectionRow<Input>, Meta>, HasSelection {
|
|
56
|
+
where(where: HasSql<boolean>): Select<Input, Meta>;
|
|
57
|
+
groupBy(...exprs: Array<HasSql>): Select<Input, Meta>;
|
|
58
|
+
having(having: HasSql<boolean>): Select<Input, Meta>;
|
|
59
|
+
orderBy(...exprs: Array<HasSql>): Select<Input, Meta>;
|
|
60
|
+
limit(limit: UserInput<number>): Select<Input, Meta>;
|
|
61
|
+
offset(offset: UserInput<number>): Select<Input, Meta>;
|
|
62
|
+
union(right: SelectBase<Input, Meta>): Union<Input, Meta>;
|
|
63
|
+
unionAll(right: SelectBase<Input, Meta>): Union<Input, Meta>;
|
|
64
|
+
intersect(right: SelectBase<Input, Meta>): Union<Input, Meta>;
|
|
65
|
+
intersectAll(this: SelectBase<Input, IsPostgres | IsMysql>, right: SelectBase<Input, Meta>): Union<Input, Meta>;
|
|
66
|
+
except(right: SelectBase<Input, Meta>): Union<Input, Meta>;
|
|
67
|
+
exceptAll(right: SelectBase<Input, IsPostgres | IsMysql>): Union<Input, Meta>;
|
|
68
|
+
as(name: string): SubQuery<Input>;
|
|
69
|
+
}
|
|
70
|
+
export interface WithoutSelection<Meta extends QueryMeta> {
|
|
71
|
+
from<Definition extends TableDefinition, Name extends string>(from: Table<Definition, Name>): AllFrom<TableFields<Definition>, Meta, Record<Name, TableFields<Definition>>>;
|
|
72
|
+
from<Input>(from: SubQuery<Input>): SelectionFrom<Input, Meta>;
|
|
73
|
+
}
|
|
74
|
+
export interface WithSelection<Input, Meta extends QueryMeta> {
|
|
75
|
+
from<Definition extends TableDefinition, Name extends string>(from: Table<Definition, Name>): SelectionFrom<Input, Meta>;
|
|
76
|
+
from(from: SubQuery<unknown>): SelectionFrom<Input, Meta>;
|
|
77
|
+
}
|
|
78
|
+
export interface AllFrom<Input, Meta extends QueryMeta, Tables = Input> extends SelectBase<Input, Meta> {
|
|
79
|
+
leftJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): AllFrom<Expand<Tables & MakeNullable<Record<Name, TableFields<Definition>>>>, Meta>;
|
|
80
|
+
rightJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): AllFrom<Expand<MakeNullable<Tables> & Record<Name, TableFields<Definition>>>, Meta>;
|
|
81
|
+
innerJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): AllFrom<Expand<Tables & Record<Name, TableFields<Definition>>>, Meta>;
|
|
82
|
+
fullJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): AllFrom<Expand<MakeNullable<Tables> & MakeNullable<Record<Name, TableFields<Definition>>>>, Meta>;
|
|
83
|
+
}
|
|
84
|
+
type MarkFieldsAsNullable<Input, TableName extends string> = Expand<{
|
|
85
|
+
[K in keyof Input]: Input[K] extends Field<infer T, TableName> ? HasSql<T | null> : Input[K] extends Table<infer Definition, TableName> ? TableFields<Definition> & IsNullable : Input[K] extends Record<string, Field<unknown, TableName> | HasSql<unknown>> ? Input[K] & IsNullable : Input[K] extends SelectionRecord ? MarkFieldsAsNullable<Input[K], TableName> : Input[K];
|
|
86
|
+
}>;
|
|
87
|
+
export interface SelectionFrom<Input, Meta extends QueryMeta> extends SelectBase<Input, Meta> {
|
|
88
|
+
leftJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): SelectionFrom<MarkFieldsAsNullable<Input, Name>, Meta>;
|
|
89
|
+
rightJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): SelectionFrom<Input, Meta>;
|
|
90
|
+
innerJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): SelectionFrom<Input, Meta>;
|
|
91
|
+
fullJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): SelectionFrom<Input, Meta>;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { internalData, internalQuery, internalSelection, type HasQuery, type HasSelection, type HasSql } from '../Internal.ts';
|
|
2
|
+
import type { IsMysql, IsPostgres, QueryMeta } from '../MetaData.ts';
|
|
3
|
+
import { Query, QueryData } from '../Query.ts';
|
|
4
|
+
import type { Selection } from '../Selection.ts';
|
|
5
|
+
import type { SelectBase } from './Select.ts';
|
|
6
|
+
export declare class UnionData<Meta extends QueryMeta> extends QueryData<Meta> {
|
|
7
|
+
selection: Selection;
|
|
8
|
+
left: HasQuery;
|
|
9
|
+
operator: HasSql;
|
|
10
|
+
right: HasQuery;
|
|
11
|
+
}
|
|
12
|
+
export declare class Union<Result, Meta extends QueryMeta = QueryMeta> extends Query<Result, Meta> implements HasSelection {
|
|
13
|
+
readonly [internalData]: UnionData<Meta>;
|
|
14
|
+
readonly [internalSelection]: Selection;
|
|
15
|
+
constructor(data: UnionData<Meta>);
|
|
16
|
+
union(right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
17
|
+
unionAll(right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
18
|
+
intersect(right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
19
|
+
except(right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
20
|
+
get [internalQuery](): import("../Sql.ts").Sql<unknown>;
|
|
21
|
+
}
|
|
22
|
+
export declare function union<Result, Meta extends QueryMeta>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
23
|
+
export declare function unionAll<Result, Meta extends QueryMeta>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
24
|
+
export declare function intersect<Result, Meta extends QueryMeta>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
25
|
+
export declare function intersectAll<Result, Meta extends IsPostgres | IsMysql>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
26
|
+
export declare function except<Result, Meta extends QueryMeta>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
27
|
+
export declare function exceptAll<Result, Meta extends IsPostgres | IsMysql>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { internalData, internalQuery, internalSelection, type HasSql, type HasTable } from '../Internal.ts';
|
|
2
|
+
import type { QueryMeta } from '../MetaData.ts';
|
|
3
|
+
import { Query, QueryData } from '../Query.ts';
|
|
4
|
+
import { type Selection, type SelectionInput, type SelectionRow } from '../Selection.ts';
|
|
5
|
+
import { type Sql } from '../Sql.ts';
|
|
6
|
+
import type { TableDefinition, TableUpdate } from '../Table.ts';
|
|
7
|
+
export declare class UpdateData<Meta extends QueryMeta = QueryMeta> extends QueryData<Meta> {
|
|
8
|
+
table: HasTable;
|
|
9
|
+
set?: HasSql;
|
|
10
|
+
where?: HasSql;
|
|
11
|
+
returning?: Selection;
|
|
12
|
+
}
|
|
13
|
+
export declare class Update<Result, Meta extends QueryMeta = QueryMeta> extends Query<Result, Meta> {
|
|
14
|
+
readonly [internalData]: UpdateData<Meta>;
|
|
15
|
+
readonly [internalSelection]?: Selection;
|
|
16
|
+
constructor(data: UpdateData<Meta>);
|
|
17
|
+
get [internalQuery](): Sql;
|
|
18
|
+
}
|
|
19
|
+
export declare class UpdateTable<Definition extends TableDefinition, Meta extends QueryMeta> extends Update<void, Meta> {
|
|
20
|
+
set(values: TableUpdate<Definition>): UpdateTable<Definition, Meta>;
|
|
21
|
+
where(where: HasSql<boolean>): UpdateTable<Definition, Meta>;
|
|
22
|
+
returning<Input extends SelectionInput>(returning: Input): Update<SelectionRow<Input>, Meta>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import pg, { type Client, type PoolClient } from 'pg';
|
|
2
|
+
import { AsyncDatabase, type TransactionOptions } from '../core/Database.ts';
|
|
3
|
+
import type { AsyncDriver, AsyncStatement } from '../core/Driver.ts';
|
|
4
|
+
type Queryable = Client | pg.Pool | PoolClient;
|
|
5
|
+
declare class PreparedStatement implements AsyncStatement {
|
|
6
|
+
private client;
|
|
7
|
+
private sql;
|
|
8
|
+
private name?;
|
|
9
|
+
constructor(client: Queryable, sql: string, name?: string | undefined);
|
|
10
|
+
all(params: Array<unknown>): Promise<Array<object>>;
|
|
11
|
+
run(params: Array<unknown>): Promise<void>;
|
|
12
|
+
get(params: Array<unknown>): Promise<object>;
|
|
13
|
+
values(params: Array<unknown>): Promise<any[][]>;
|
|
14
|
+
free(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare class PgDriver implements AsyncDriver {
|
|
17
|
+
private client;
|
|
18
|
+
constructor(client: Queryable);
|
|
19
|
+
exec(query: string): Promise<void>;
|
|
20
|
+
prepare(sql: string, name: string): PreparedStatement;
|
|
21
|
+
close(): Promise<void>;
|
|
22
|
+
transaction<T>(run: (inner: AsyncDriver) => Promise<T>, options: TransactionOptions['postgres'], depth: number): Promise<T>;
|
|
23
|
+
}
|
|
24
|
+
export declare function connect(client: Queryable): AsyncDatabase<"postgres">;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PGlite, Transaction } from '@electric-sql/pglite';
|
|
2
|
+
import type { AsyncDriver, AsyncStatement } from '../core/Driver.ts';
|
|
3
|
+
import { AsyncDatabase, type TransactionOptions } from '../index.ts';
|
|
4
|
+
type Queryable = PGlite | Transaction;
|
|
5
|
+
declare class PreparedStatement implements AsyncStatement {
|
|
6
|
+
private client;
|
|
7
|
+
private sql;
|
|
8
|
+
constructor(client: Queryable, sql: string);
|
|
9
|
+
all(params: Array<unknown>): Promise<Array<object>>;
|
|
10
|
+
run(params: Array<unknown>): Promise<void>;
|
|
11
|
+
get(params: Array<unknown>): Promise<object>;
|
|
12
|
+
values(params: Array<unknown>): Promise<unknown[][]>;
|
|
13
|
+
free(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class PGliteDriver implements AsyncDriver {
|
|
16
|
+
private client;
|
|
17
|
+
constructor(client: Queryable);
|
|
18
|
+
exec(query: string): Promise<void>;
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
prepare(sql: string): PreparedStatement;
|
|
21
|
+
transaction<T>(run: (inner: AsyncDriver) => Promise<T>, options: TransactionOptions['postgres']): Promise<T>;
|
|
22
|
+
}
|
|
23
|
+
export declare function connect(db: PGlite): AsyncDatabase<"postgres">;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './core/Column.ts';
|
|
2
|
+
export * from './core/Constraint.ts';
|
|
3
|
+
export * from './core/Database.ts';
|
|
4
|
+
export * from './core/Driver.ts';
|
|
5
|
+
export * from './core/Index.ts';
|
|
6
|
+
export * from './core/Query.ts';
|
|
7
|
+
export * from './core/Selection.ts';
|
|
8
|
+
export * from './core/Sql.ts';
|
|
9
|
+
export * from './core/Table.ts';
|
|
10
|
+
export * from './core/expr/Conditions.ts';
|
|
11
|
+
export * from './core/query/CreateTable.ts';
|
|
12
|
+
export * from './core/query/Delete.ts';
|
|
13
|
+
export * from './core/query/Insert.ts';
|
|
14
|
+
export * from './core/query/Select.ts';
|
|
15
|
+
export * from './core/query/Union.ts';
|
|
16
|
+
export * from './core/query/Update.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|