@ez4/database 0.18.0 → 0.20.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/library.cjs +106 -102
- package/dist/library.mjs +110 -106
- package/dist/main.cjs +8 -6
- package/dist/main.d.ts +7 -5
- package/dist/main.mjs +4 -3
- package/dist/services/client.d.ts +4 -4
- package/dist/services/database.d.ts +1 -1
- package/dist/services/engine.d.ts +46 -16
- package/dist/services/insensitive.d.ts +19 -0
- package/dist/services/order.d.ts +31 -0
- package/dist/services/pagination.d.ts +45 -0
- package/dist/services/parameters.d.ts +12 -12
- package/dist/services/query.d.ts +121 -122
- package/dist/services/relations.d.ts +10 -10
- package/dist/services/table.d.ts +26 -11
- package/dist/services/transaction.d.ts +26 -21
- package/dist/triggers/service.d.ts +1 -1
- package/dist/types/engine.d.ts +10 -3
- package/dist/types/stream.d.ts +1 -1
- package/package.json +6 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { ParametersUtils } from './parameters.js';
|
|
2
|
+
import type { TransactionUtils } from './transaction.js';
|
|
3
3
|
import type { TableClients } from './table.js';
|
|
4
4
|
import type { Database } from './database.js';
|
|
5
5
|
/**
|
|
@@ -13,12 +13,12 @@ export type Client<T extends Database.Service> = TableClients<T> & {
|
|
|
13
13
|
* @param parameters Parameters in use by the given query.
|
|
14
14
|
* @returns Returns the results for the given query.
|
|
15
15
|
*/
|
|
16
|
-
rawQuery(query: string, parameters?:
|
|
16
|
+
rawQuery(query: string, parameters?: ParametersUtils.Type<T>): Promise<Record<string, unknown>[]>;
|
|
17
17
|
/**
|
|
18
18
|
* Prepare and execute the given transaction.
|
|
19
19
|
*
|
|
20
20
|
* @param operation Transaction operation.
|
|
21
21
|
* @returns Returns the transaction result if the given transaction is interactive.
|
|
22
22
|
*/
|
|
23
|
-
transaction<O extends
|
|
23
|
+
transaction<O extends TransactionUtils.Type<T, R>, R>(operation: O): Promise<TransactionUtils.Result<O>>;
|
|
24
24
|
};
|
|
@@ -1,22 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Parameters type.
|
|
10
|
-
*/
|
|
11
|
-
export declare const enum ParametersType {
|
|
12
|
-
NameAndIndex = "both",
|
|
13
|
-
OnlyIndex = "index"
|
|
14
|
-
}
|
|
1
|
+
import type { ParametersMode } from './parameters.js';
|
|
2
|
+
import type { TransactionMode } from './transaction.js';
|
|
3
|
+
import type { InsensitiveMode } from './insensitive.js';
|
|
4
|
+
import type { PaginationMode } from './pagination.js';
|
|
5
|
+
import type { OrderMode } from './order.js';
|
|
6
|
+
import type { Database } from './database.js';
|
|
15
7
|
/**
|
|
16
8
|
* Database engine.
|
|
17
9
|
*/
|
|
18
10
|
export type DatabaseEngine = {
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
parametersMode: ParametersMode;
|
|
12
|
+
transactionMode: TransactionMode;
|
|
13
|
+
insensitiveMode: InsensitiveMode;
|
|
14
|
+
paginationMode: PaginationMode;
|
|
15
|
+
orderMode: OrderMode;
|
|
21
16
|
name: string;
|
|
22
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Engine utils.
|
|
20
|
+
*/
|
|
21
|
+
export declare namespace EngineUtils {
|
|
22
|
+
/**
|
|
23
|
+
* Get the parameters mode from the given database service.
|
|
24
|
+
*/
|
|
25
|
+
type GetParametersMode<T extends Database.Service> = T['engine'] extends {
|
|
26
|
+
parametersMode: infer M;
|
|
27
|
+
} ? M : never;
|
|
28
|
+
/**
|
|
29
|
+
* Get the transaction mode from the given database service.
|
|
30
|
+
*/
|
|
31
|
+
type GetTransactionMode<T extends Database.Service> = T['engine'] extends {
|
|
32
|
+
transactionMode: infer M;
|
|
33
|
+
} ? M : never;
|
|
34
|
+
/**
|
|
35
|
+
* Get the insensitive mode from the given database engine.
|
|
36
|
+
*/
|
|
37
|
+
type GetInsensitiveMode<E extends DatabaseEngine> = E extends {
|
|
38
|
+
insensitiveMode: infer M;
|
|
39
|
+
} ? M : never;
|
|
40
|
+
/**
|
|
41
|
+
* Get the pagination mode from the given database engine.
|
|
42
|
+
*/
|
|
43
|
+
type GetPaginationMode<E extends DatabaseEngine> = E extends {
|
|
44
|
+
paginationMode: infer M;
|
|
45
|
+
} ? M : never;
|
|
46
|
+
/**
|
|
47
|
+
* Get the order mode from the given database service.
|
|
48
|
+
*/
|
|
49
|
+
type GetOrderMode<T extends Database.Service> = T['engine'] extends {
|
|
50
|
+
orderMode: infer M;
|
|
51
|
+
} ? M : never;
|
|
52
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DatabaseEngine, EngineUtils } from './engine.js';
|
|
2
|
+
/**
|
|
3
|
+
* Insensitive mode.
|
|
4
|
+
*/
|
|
5
|
+
export declare const enum InsensitiveMode {
|
|
6
|
+
Unsupported = "unsupported",
|
|
7
|
+
Enabled = "enabled"
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Insensitive utils.
|
|
11
|
+
*/
|
|
12
|
+
export declare namespace InsensitiveUtils {
|
|
13
|
+
/**
|
|
14
|
+
* Get the insensitive input based on the given database engine.
|
|
15
|
+
*/
|
|
16
|
+
type Input<E extends DatabaseEngine> = EngineUtils.GetInsensitiveMode<E> extends InsensitiveMode.Enabled ? {
|
|
17
|
+
insensitive?: boolean;
|
|
18
|
+
} : {};
|
|
19
|
+
}
|
package/dist/services/order.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { DecomposeIndexName } from './indexes.js';
|
|
2
|
+
import type { TableMetadata } from './table.js';
|
|
3
|
+
import type { Database } from './database.js';
|
|
1
4
|
/**
|
|
2
5
|
* Query order types.
|
|
3
6
|
*/
|
|
@@ -5,3 +8,31 @@ export declare const enum Order {
|
|
|
5
8
|
Asc = "asc",
|
|
6
9
|
Desc = "desc"
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Order mode.
|
|
13
|
+
*/
|
|
14
|
+
export declare const enum OrderMode {
|
|
15
|
+
IndexColumns = "index",
|
|
16
|
+
AnyColumns = "any"
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Order utils.
|
|
20
|
+
*/
|
|
21
|
+
export declare namespace OrderUtils {
|
|
22
|
+
/**
|
|
23
|
+
* Order input for index columns.
|
|
24
|
+
*/
|
|
25
|
+
type IndexInput<I extends Database.Indexes> = {
|
|
26
|
+
[P in DecomposeIndexName<keyof I>]?: Order;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Order input for any columns.
|
|
30
|
+
*/
|
|
31
|
+
type AnyInput<T extends Database.Schema> = {
|
|
32
|
+
[P in keyof T]?: Order;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Order input type based on the table metadata.
|
|
36
|
+
*/
|
|
37
|
+
type Input<T extends TableMetadata> = T['engine']['orderMode'] extends OrderMode.IndexColumns ? IndexInput<T['indexes']> : AnyInput<T['schema']>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { DatabaseEngine, EngineUtils } from './engine.js';
|
|
2
|
+
/**
|
|
3
|
+
* Pagination mode.
|
|
4
|
+
*/
|
|
5
|
+
export declare const enum PaginationMode {
|
|
6
|
+
Cursor = "cursor",
|
|
7
|
+
Offset = "offset"
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Pagination utils.
|
|
11
|
+
*/
|
|
12
|
+
export declare namespace PaginationUtils {
|
|
13
|
+
/**
|
|
14
|
+
* Get the pagination range based on the given database engine.
|
|
15
|
+
*/
|
|
16
|
+
type Range<E extends DatabaseEngine> = EngineUtils.GetPaginationMode<E> extends PaginationMode.Cursor ? {
|
|
17
|
+
cursor?: string;
|
|
18
|
+
limit?: number;
|
|
19
|
+
} : {
|
|
20
|
+
skip?: number;
|
|
21
|
+
take?: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Get the pagination begin based on the given table metadata.
|
|
25
|
+
*/
|
|
26
|
+
type Begin<E extends DatabaseEngine> = EngineUtils.GetPaginationMode<E> extends PaginationMode.Cursor ? {
|
|
27
|
+
cursor?: string;
|
|
28
|
+
} : {
|
|
29
|
+
skip?: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Get the pagination end based on the given table metadata.
|
|
33
|
+
*/
|
|
34
|
+
type End<E extends DatabaseEngine> = EngineUtils.GetPaginationMode<E> extends PaginationMode.Cursor ? {
|
|
35
|
+
limit?: number;
|
|
36
|
+
} : {
|
|
37
|
+
take?: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Get the pagination result based on the given table metadata.
|
|
41
|
+
*/
|
|
42
|
+
type Result<E extends DatabaseEngine> = EngineUtils.GetPaginationMode<E> extends PaginationMode.Cursor ? {
|
|
43
|
+
cursor?: string;
|
|
44
|
+
} : {};
|
|
45
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EngineUtils } from './engine.js';
|
|
2
2
|
import type { Database } from './database.js';
|
|
3
3
|
/**
|
|
4
|
-
* Parameters
|
|
4
|
+
* Parameters mode.
|
|
5
5
|
*/
|
|
6
|
-
export declare
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
export declare const enum ParametersMode {
|
|
7
|
+
NameAndIndex = "both",
|
|
8
|
+
OnlyIndex = "index"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parameters utils.
|
|
12
|
+
*/
|
|
13
|
+
export declare namespace ParametersUtils {
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
15
|
+
* Get the parameters type based on the given database service.
|
|
13
16
|
*/
|
|
14
|
-
type
|
|
15
|
-
parameters: infer R;
|
|
16
|
-
} ? R : never;
|
|
17
|
-
export {};
|
|
17
|
+
type Type<T extends Database.Service> = EngineUtils.GetParametersMode<T> extends ParametersMode.NameAndIndex ? unknown[] | Record<string, unknown> : unknown[];
|
|
18
18
|
}
|
package/dist/services/query.d.ts
CHANGED
|
@@ -1,150 +1,149 @@
|
|
|
1
1
|
import type { DecomposeIndexName, PrimaryIndexes, UniqueIndexes } from './indexes.js';
|
|
2
|
+
import type { DatabaseEngine } from './engine.js';
|
|
2
3
|
import type { RelationMetadata } from './relations.js';
|
|
4
|
+
import type { InsensitiveUtils } from './insensitive.js';
|
|
5
|
+
import type { PaginationUtils } from './pagination.js';
|
|
6
|
+
import type { TableMetadata } from './table.js';
|
|
7
|
+
import type { OrderUtils } from './order.js';
|
|
3
8
|
import type { Database } from './database.js';
|
|
4
|
-
import type { Order } from './order.js';
|
|
5
9
|
import type { AnyObject, PartialProperties, PartialObject, FlatObject, OptionalObject, StrictObject, IsNullable, IsObjectEmpty, IsObject, IsArray } from '@ez4/utils';
|
|
6
10
|
/**
|
|
7
11
|
* Query builder types.
|
|
8
12
|
*/
|
|
9
13
|
export declare namespace Query {
|
|
10
|
-
export type InsertOneInput<
|
|
11
|
-
select?: StrictSelectInput<
|
|
12
|
-
data: InsertDataInput<T
|
|
13
|
-
};
|
|
14
|
-
export type UpdateOneInput<
|
|
15
|
-
select?: StrictSelectInput<
|
|
16
|
-
include?: StrictIncludeInput<S,
|
|
17
|
-
data: OptionalObject<UpdateDataInput<T
|
|
18
|
-
where: WhereInput<T,
|
|
19
|
-
};
|
|
20
|
-
export type FindOneInput<
|
|
21
|
-
select: StrictSelectInput<
|
|
22
|
-
include?: StrictIncludeInput<S,
|
|
23
|
-
where: WhereInput<T,
|
|
24
|
-
};
|
|
25
|
-
export type UpsertOneInput<
|
|
26
|
-
select?: StrictSelectInput<
|
|
27
|
-
include?: StrictIncludeInput<S,
|
|
28
|
-
update: OptionalObject<UpdateDataInput<T
|
|
29
|
-
insert: InsertDataInput<T
|
|
30
|
-
where: WhereInput<T,
|
|
31
|
-
};
|
|
32
|
-
export type DeleteOneInput<
|
|
33
|
-
select?: StrictSelectInput<
|
|
34
|
-
include?: StrictIncludeInput<S,
|
|
35
|
-
where: WhereInput<T,
|
|
36
|
-
};
|
|
37
|
-
export type InsertManyInput<T extends
|
|
38
|
-
data: T[];
|
|
39
|
-
};
|
|
40
|
-
export type UpdateManyInput<
|
|
41
|
-
select?: StrictSelectInput<
|
|
42
|
-
include?: StrictIncludeInput<S,
|
|
43
|
-
data: OptionalObject<UpdateDataInput<T
|
|
44
|
-
where?: WhereInput<T
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export type FindManyInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes, R extends RelationMetadata, C extends boolean> = {
|
|
14
|
+
export type InsertOneInput<S extends AnyObject, T extends TableMetadata> = {
|
|
15
|
+
select?: StrictSelectInput<S, T>;
|
|
16
|
+
data: InsertDataInput<T>;
|
|
17
|
+
};
|
|
18
|
+
export type UpdateOneInput<S extends AnyObject, T extends TableMetadata> = {
|
|
19
|
+
select?: StrictSelectInput<S, T>;
|
|
20
|
+
include?: StrictIncludeInput<S, T>;
|
|
21
|
+
data: OptionalObject<UpdateDataInput<T>>;
|
|
22
|
+
where: WhereInput<T, true>;
|
|
23
|
+
};
|
|
24
|
+
export type FindOneInput<S extends AnyObject, T extends TableMetadata> = {
|
|
25
|
+
select: StrictSelectInput<S, T>;
|
|
26
|
+
include?: StrictIncludeInput<S, T>;
|
|
27
|
+
where: WhereInput<T, true>;
|
|
28
|
+
};
|
|
29
|
+
export type UpsertOneInput<S extends AnyObject, T extends TableMetadata> = {
|
|
30
|
+
select?: StrictSelectInput<S, T>;
|
|
31
|
+
include?: StrictIncludeInput<S, T>;
|
|
32
|
+
update: OptionalObject<UpdateDataInput<T>>;
|
|
33
|
+
insert: InsertDataInput<T>;
|
|
34
|
+
where: WhereInput<T, true>;
|
|
35
|
+
};
|
|
36
|
+
export type DeleteOneInput<S extends AnyObject, T extends TableMetadata> = {
|
|
37
|
+
select?: StrictSelectInput<S, T>;
|
|
38
|
+
include?: StrictIncludeInput<S, T>;
|
|
39
|
+
where: WhereInput<T, true>;
|
|
40
|
+
};
|
|
41
|
+
export type InsertManyInput<T extends TableMetadata> = {
|
|
42
|
+
data: T['schema'][];
|
|
43
|
+
};
|
|
44
|
+
export type UpdateManyInput<S extends AnyObject, T extends TableMetadata> = PaginationUtils.End<T['engine']> & {
|
|
45
|
+
select?: StrictSelectInput<S, T>;
|
|
46
|
+
include?: StrictIncludeInput<S, T>;
|
|
47
|
+
data: OptionalObject<UpdateDataInput<T>>;
|
|
48
|
+
where?: WhereInput<T>;
|
|
49
|
+
};
|
|
50
|
+
export type FindManyInput<S extends AnyObject, T extends TableMetadata, C extends boolean> = PaginationUtils.Range<T['engine']> & {
|
|
48
51
|
count?: C;
|
|
49
|
-
select: StrictSelectInput<
|
|
50
|
-
include?: StrictIncludeInput<S,
|
|
51
|
-
where?: WhereInput<T
|
|
52
|
-
order?: OrderInput<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
export type
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export type
|
|
66
|
-
export type
|
|
67
|
-
export type
|
|
68
|
-
export type UpsertOneResult<T extends Database.Schema, S extends AnyObject, R extends RelationMetadata> = S extends never ? void : Record<T, S, R> | undefined;
|
|
69
|
-
export type DeleteOneResult<T extends Database.Schema, S extends AnyObject, R extends RelationMetadata> = S extends never ? void : Record<T, S, R> | undefined;
|
|
70
|
-
export type UpdateManyResult<T extends Database.Schema, S extends AnyObject, R extends RelationMetadata> = S extends never ? void : Record<T, S, R>[];
|
|
52
|
+
select: StrictSelectInput<S, T>;
|
|
53
|
+
include?: StrictIncludeInput<S, T>;
|
|
54
|
+
where?: WhereInput<T>;
|
|
55
|
+
order?: OrderInput<T>;
|
|
56
|
+
};
|
|
57
|
+
export type DeleteManyInput<S extends AnyObject, T extends TableMetadata> = PaginationUtils.End<T['engine']> & {
|
|
58
|
+
select?: StrictSelectInput<S, T>;
|
|
59
|
+
include?: StrictIncludeInput<S, T>;
|
|
60
|
+
where?: WhereInput<T>;
|
|
61
|
+
};
|
|
62
|
+
export type CountInput<T extends TableMetadata> = {
|
|
63
|
+
where?: WhereInput<T>;
|
|
64
|
+
};
|
|
65
|
+
export type InsertOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T>;
|
|
66
|
+
export type UpdateOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T> | undefined;
|
|
67
|
+
export type FindOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T> | undefined;
|
|
68
|
+
export type UpsertOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T>;
|
|
69
|
+
export type DeleteOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T> | undefined;
|
|
70
|
+
export type UpdateManyResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T>[];
|
|
71
71
|
export type InsertManyResult = void;
|
|
72
|
-
export type FindManyResult<
|
|
73
|
-
records: Record<
|
|
74
|
-
cursor?: number | string;
|
|
72
|
+
export type FindManyResult<S extends AnyObject, T extends TableMetadata, C extends boolean> = PaginationUtils.Result<T['engine']> & (C extends true ? {
|
|
73
|
+
records: Record<S, T>[];
|
|
75
74
|
total: number;
|
|
76
75
|
} : {
|
|
77
|
-
records: Record<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export type
|
|
81
|
-
export type
|
|
82
|
-
export type
|
|
83
|
-
export type
|
|
84
|
-
export type
|
|
85
|
-
export type
|
|
86
|
-
export type StrictIncludeInput<S extends AnyObject,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
export type
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
[P in keyof T]?: P extends keyof S ? (IsObject<T[P]> extends true ? null | WhereRelationField<NonNullable<T[P]>> : never) : never;
|
|
76
|
+
records: Record<S, T>[];
|
|
77
|
+
});
|
|
78
|
+
export type DeleteManyResult<S extends AnyObject, T extends TableMetadata> = Record<S, T>[];
|
|
79
|
+
export type Record<S extends AnyObject, T extends TableMetadata> = S extends never ? undefined : PartialObject<SelectFields<T['schema'], T['relations']>, S, false>;
|
|
80
|
+
export type SelectInput<T extends TableMetadata> = PartialProperties<SelectFields<T['schema'], T['relations']>>;
|
|
81
|
+
export type StrictSelectInput<S extends AnyObject, T extends TableMetadata> = StrictObject<S, FlatObject<SelectFields<T['schema'], T['relations']>>>;
|
|
82
|
+
export type InsertDataInput<T extends TableMetadata> = Omit<IsObjectEmpty<T['relations']['changes']> extends true ? T['schema'] : T['schema'] & T['relations']['changes'], T['relations']['indexes']>;
|
|
83
|
+
export type UpdateDataInput<T extends TableMetadata> = AtomicDataInput<Omit<IsObjectEmpty<T['relations']['changes']> extends true ? T['schema'] : T['schema'] & FlatObject<T['relations']['changes']>, T['relations']['indexes']>>;
|
|
84
|
+
export type OrderInput<T extends TableMetadata> = OrderUtils.Input<T>;
|
|
85
|
+
export type StrictIncludeInput<S extends AnyObject, T extends TableMetadata> = IsObjectEmpty<T['relations']['filters']> extends true ? never : {
|
|
86
|
+
[P in keyof T['relations']['filters']]?: P extends keyof S ? StrictIncludeRelation<T['relations']['filters'][P], T['engine']> : never;
|
|
87
|
+
};
|
|
88
|
+
export type StrictIncludeOrder<V extends AnyObject> = OrderUtils.AnyInput<V>;
|
|
89
|
+
export type StrictIncludeRelation<V extends AnyObject, E extends DatabaseEngine> = PaginationUtils.Range<E> & {
|
|
90
|
+
where?: WhereRelationField<V, E>;
|
|
91
|
+
order?: StrictIncludeOrder<V>;
|
|
92
|
+
};
|
|
93
|
+
export type WhereInput<T extends TableMetadata, I extends boolean = false> = WhereInputFilters<T, I extends true ? T['indexes'] : {}> & {
|
|
94
|
+
NOT?: WhereInput<T>;
|
|
95
|
+
AND?: WhereInput<T>[];
|
|
96
|
+
OR?: WhereInput<T>[];
|
|
99
97
|
};
|
|
100
|
-
type
|
|
101
|
-
type
|
|
102
|
-
type
|
|
103
|
-
|
|
98
|
+
type SelectFields<T extends Database.Schema, R extends RelationMetadata> = IsObjectEmpty<R['selects']> extends true ? T : T & R['selects'];
|
|
99
|
+
type WhereOperations<V, E extends DatabaseEngine> = WhereNegate<V> | WhereEqual<V> | WhereGreaterThan<V> | WhereGreaterThanOrEqual<V> | WhereLessThan<V> | WhereLessThanOrEqual<V> | WhereIn<V> | WhereBetween<V> | WhereIsMissing | WhereIsNull | WhereStartsWith<E> | WhereContains<V, E>;
|
|
100
|
+
type WhereField<V, E extends DatabaseEngine> = IsObject<V> extends false ? V | WhereOperations<V, E> : IsNullable<V> extends true ? null | WhereObjectField<NonNullable<V>, E> : WhereObjectField<NonNullable<V>, E>;
|
|
101
|
+
type WhereObjectField<V extends AnyObject, E extends DatabaseEngine> = {
|
|
102
|
+
[P in keyof V]?: WhereField<V[P], E>;
|
|
104
103
|
};
|
|
105
|
-
type WhereRelationField<
|
|
106
|
-
NOT?: WhereRelationField<
|
|
107
|
-
AND?: WhereRelationField<
|
|
108
|
-
OR?: WhereRelationField<
|
|
104
|
+
type WhereRelationField<V extends AnyObject, E extends DatabaseEngine> = WhereObjectField<V, E> & {
|
|
105
|
+
NOT?: WhereRelationField<V, E>;
|
|
106
|
+
AND?: WhereRelationField<V, E>[];
|
|
107
|
+
OR?: WhereRelationField<V, E>[];
|
|
109
108
|
};
|
|
110
|
-
type WhereRelationFilters<
|
|
111
|
-
[P in keyof
|
|
109
|
+
type WhereRelationFilters<V extends AnyObject, E extends DatabaseEngine> = {
|
|
110
|
+
[P in keyof V]?: IsObject<V[P]> extends true ? IsObjectEmpty<V[P]> extends false ? null | WhereRelationField<V[P], E> : null | {} : never;
|
|
112
111
|
};
|
|
113
112
|
type WhereIndexFields<I extends Database.Indexes> = PrimaryIndexes<I> & UniqueIndexes<I>;
|
|
114
|
-
type WhereRequiredFilters<
|
|
113
|
+
type WhereRequiredFilters<V extends AnyObject, I extends Database.Indexes> = {
|
|
115
114
|
[P in keyof WhereIndexFields<I>]: {
|
|
116
|
-
[N in DecomposeIndexName<P>]:
|
|
115
|
+
[N in DecomposeIndexName<P>]: V[N];
|
|
117
116
|
};
|
|
118
117
|
}[keyof WhereIndexFields<I>];
|
|
119
|
-
type WhereOptionalFilters<
|
|
120
|
-
[P in Exclude<keyof
|
|
118
|
+
type WhereOptionalFilters<V extends AnyObject, T extends TableMetadata, I extends Database.Indexes> = {
|
|
119
|
+
[P in Exclude<keyof V, keyof WhereIndexFields<I>>]?: WhereField<V[P], T['engine']>;
|
|
121
120
|
};
|
|
122
|
-
type WhereCommonFilters<
|
|
123
|
-
type WhereInputFilters<T extends
|
|
124
|
-
export type WhereOperators = keyof (WhereNegate<any> & WhereEqual<any> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith & WhereContains<any>);
|
|
125
|
-
type WhereNegate<
|
|
126
|
-
not:
|
|
121
|
+
type WhereCommonFilters<V extends AnyObject, T extends TableMetadata, I extends Database.Indexes> = IsObjectEmpty<I> extends true ? WhereObjectField<V, T['engine']> : WhereRequiredFilters<V, I> & WhereOptionalFilters<V, T, I>;
|
|
122
|
+
type WhereInputFilters<T extends TableMetadata, I extends Database.Indexes> = WhereCommonFilters<T['schema'], T, I> & WhereRelationFilters<T['relations']['filters'], T['engine']>;
|
|
123
|
+
export type WhereOperators = keyof (WhereNegate<any> & WhereEqual<any> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith<never> & WhereContains<any, never>);
|
|
124
|
+
type WhereNegate<V> = {
|
|
125
|
+
not: V;
|
|
127
126
|
};
|
|
128
|
-
type WhereEqual<
|
|
129
|
-
equal:
|
|
127
|
+
type WhereEqual<V> = {
|
|
128
|
+
equal: V;
|
|
130
129
|
};
|
|
131
|
-
type WhereGreaterThan<
|
|
132
|
-
gt:
|
|
130
|
+
type WhereGreaterThan<V> = {
|
|
131
|
+
gt: V;
|
|
133
132
|
};
|
|
134
|
-
type WhereGreaterThanOrEqual<
|
|
135
|
-
gte:
|
|
133
|
+
type WhereGreaterThanOrEqual<V> = {
|
|
134
|
+
gte: V;
|
|
136
135
|
};
|
|
137
|
-
type WhereLessThan<
|
|
138
|
-
lt:
|
|
136
|
+
type WhereLessThan<V> = {
|
|
137
|
+
lt: V;
|
|
139
138
|
};
|
|
140
|
-
type WhereLessThanOrEqual<
|
|
141
|
-
lte:
|
|
139
|
+
type WhereLessThanOrEqual<V> = {
|
|
140
|
+
lte: V;
|
|
142
141
|
};
|
|
143
|
-
type WhereIn<
|
|
144
|
-
isIn: IsArray<
|
|
142
|
+
type WhereIn<V> = {
|
|
143
|
+
isIn: IsArray<V> extends true ? V : IsObject<V> extends true ? V : V[];
|
|
145
144
|
};
|
|
146
|
-
type WhereBetween<
|
|
147
|
-
isBetween: [
|
|
145
|
+
type WhereBetween<V> = {
|
|
146
|
+
isBetween: [V, V];
|
|
148
147
|
};
|
|
149
148
|
type WhereIsMissing = {
|
|
150
149
|
isMissing: boolean;
|
|
@@ -152,11 +151,11 @@ export declare namespace Query {
|
|
|
152
151
|
type WhereIsNull = {
|
|
153
152
|
isNull: boolean;
|
|
154
153
|
};
|
|
155
|
-
type WhereStartsWith = {
|
|
154
|
+
type WhereStartsWith<E extends DatabaseEngine> = InsensitiveUtils.Input<E> & {
|
|
156
155
|
startsWith: string;
|
|
157
156
|
};
|
|
158
|
-
type WhereContains<
|
|
159
|
-
contains: IsObject<
|
|
157
|
+
type WhereContains<V, E extends DatabaseEngine> = (V extends string ? InsensitiveUtils.Input<E> : {}) & {
|
|
158
|
+
contains: IsObject<V> extends true ? Partial<V> : V;
|
|
160
159
|
};
|
|
161
160
|
export type AtomicOperators = keyof (AtomicIncrement & AtomicDecrement & AtomicMultiply & AtomicDivide);
|
|
162
161
|
type AtomicDataInput<T extends AnyObject> = AtomicRequiredFields<T> & AtomicOptionalFields<T>;
|
|
@@ -6,10 +6,10 @@ import type { TableSchemas } from './schemas.js';
|
|
|
6
6
|
* Internal relation type.
|
|
7
7
|
*/
|
|
8
8
|
export type RelationMetadata = {
|
|
9
|
+
filters: Record<string, {}>;
|
|
10
|
+
selects: Record<string, {}>;
|
|
11
|
+
changes: Record<string, {}>;
|
|
9
12
|
indexes: string;
|
|
10
|
-
filters: Record<string, unknown>;
|
|
11
|
-
selects: Record<string, unknown>;
|
|
12
|
-
changes: Record<string, unknown>;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Given a relation source name `T`, it produces the source table name.
|
|
@@ -44,23 +44,23 @@ type TableRelation<T, S extends Record<string, Database.Schema>, I extends Recor
|
|
|
44
44
|
relations: infer R;
|
|
45
45
|
} ? N extends string ? R extends AnyObject ? {
|
|
46
46
|
[P in N]: {
|
|
47
|
-
indexes:
|
|
48
|
-
filters: FilterableRelationSchemas<S,
|
|
47
|
+
indexes: RelationIndexes<PropertyType<N, I>, R>;
|
|
48
|
+
filters: FilterableRelationSchemas<S, R>;
|
|
49
49
|
changes: RequiredRelationSchemas<PropertyType<N, S>, S, I, R, true> & OptionalRelationSchemas<PropertyType<N, S>, S, I, R, true>;
|
|
50
50
|
selects: RequiredRelationSchemas<PropertyType<N, S>, S, I, R, false> & OptionalRelationSchemas<PropertyType<N, S>, S, I, R, false>;
|
|
51
51
|
};
|
|
52
52
|
} : {} : {} : {};
|
|
53
53
|
/**
|
|
54
|
-
* Produce an object containing all
|
|
54
|
+
* Produce an object containing all relation indexes.
|
|
55
55
|
*/
|
|
56
|
-
type
|
|
57
|
-
[C in keyof R as
|
|
56
|
+
type RelationIndexes<I extends Database.Indexes, R extends AnyObject> = keyof {
|
|
57
|
+
[C in keyof R as RelationTargetColumn<C> extends keyof PrimaryIndexes<I> ? never : RelationTargetColumn<C>]: never;
|
|
58
58
|
};
|
|
59
59
|
/**
|
|
60
60
|
* Produce an object containing all filterable relation schemas.
|
|
61
61
|
*/
|
|
62
|
-
type FilterableRelationSchemas<S extends Record<string, Database.Schema>,
|
|
63
|
-
[C in keyof R as RelationTargetAlias<C>]:
|
|
62
|
+
type FilterableRelationSchemas<S extends Record<string, Database.Schema>, R extends AnyObject> = {
|
|
63
|
+
[C in keyof R as RelationTargetAlias<C>]: Omit<PropertyType<RelationSourceTable<R[C]>, S>, RelationSourceColumn<R[C]>>;
|
|
64
64
|
};
|
|
65
65
|
/**
|
|
66
66
|
* Produce an object containing only required relation schemas.
|