@taylordb/query-builder 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/dist/cjs/aggregation-query-builder.d.ts +92 -0
- package/dist/cjs/aggregation-query-builder.js +92 -0
- package/dist/cjs/aggregation-query-builder.js.map +1 -1
- package/dist/cjs/batch-query-builder.d.ts +36 -0
- package/dist/cjs/batch-query-builder.js +36 -0
- package/dist/cjs/batch-query-builder.js.map +1 -1
- package/dist/cjs/delete-query-builder.d.ts +17 -0
- package/dist/cjs/delete-query-builder.js +17 -0
- package/dist/cjs/delete-query-builder.js.map +1 -1
- package/dist/cjs/insert-query-builder.d.ts +68 -0
- package/dist/cjs/insert-query-builder.js +71 -0
- package/dist/cjs/insert-query-builder.js.map +1 -1
- package/dist/cjs/query-builder.d.ts +217 -0
- package/dist/cjs/query-builder.js +188 -0
- package/dist/cjs/query-builder.js.map +1 -1
- package/dist/cjs/selection-builder.d.ts +11 -0
- package/dist/cjs/selection-builder.js +11 -0
- package/dist/cjs/selection-builder.js.map +1 -1
- package/dist/cjs/update-query-builder.d.ts +32 -0
- package/dist/cjs/update-query-builder.js +32 -0
- package/dist/cjs/update-query-builder.js.map +1 -1
- package/dist/cjs/where-query-builder.d.ts +59 -0
- package/dist/cjs/where-query-builder.js +6 -0
- package/dist/cjs/where-query-builder.js.map +1 -1
- package/dist/esm/aggregation-query-builder.d.ts +92 -0
- package/dist/esm/aggregation-query-builder.js +92 -0
- package/dist/esm/aggregation-query-builder.js.map +1 -1
- package/dist/esm/batch-query-builder.d.ts +36 -0
- package/dist/esm/batch-query-builder.js +36 -0
- package/dist/esm/batch-query-builder.js.map +1 -1
- package/dist/esm/delete-query-builder.d.ts +17 -0
- package/dist/esm/delete-query-builder.js +17 -0
- package/dist/esm/delete-query-builder.js.map +1 -1
- package/dist/esm/insert-query-builder.d.ts +68 -0
- package/dist/esm/insert-query-builder.js +71 -0
- package/dist/esm/insert-query-builder.js.map +1 -1
- package/dist/esm/query-builder.d.ts +217 -0
- package/dist/esm/query-builder.js +188 -0
- package/dist/esm/query-builder.js.map +1 -1
- package/dist/esm/selection-builder.d.ts +11 -0
- package/dist/esm/selection-builder.js +11 -0
- package/dist/esm/selection-builder.js.map +1 -1
- package/dist/esm/update-query-builder.d.ts +32 -0
- package/dist/esm/update-query-builder.js +32 -0
- package/dist/esm/update-query-builder.js.map +1 -1
- package/dist/esm/where-query-builder.d.ts +59 -0
- package/dist/esm/where-query-builder.js +6 -0
- package/dist/esm/where-query-builder.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 TaylorDB
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -111,3 +111,45 @@ const aggregates = await qb
|
|
|
111
111
|
})
|
|
112
112
|
.execute();
|
|
113
113
|
```
|
|
114
|
+
|
|
115
|
+
## Recipes
|
|
116
|
+
|
|
117
|
+
### Select with Relations
|
|
118
|
+
|
|
119
|
+
You can use the `with` method to fetch related records from a linked table.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// Assuming 'customers' has a link field 'orders' to the 'orders' table
|
|
123
|
+
const customersWithOrders = await qb
|
|
124
|
+
.selectFrom('customers')
|
|
125
|
+
.select(['firstName', 'lastName'])
|
|
126
|
+
.with({
|
|
127
|
+
orders: qb => qb.select(['orderDate', 'total']),
|
|
128
|
+
})
|
|
129
|
+
.execute();
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Cross-Filters
|
|
133
|
+
|
|
134
|
+
You can filter records in one table based on the values in a linked table.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// Get all customers who have placed an order with a total greater than 100
|
|
138
|
+
const highValueCustomers = await qb
|
|
139
|
+
.selectFrom('customers')
|
|
140
|
+
.where('orders', 'hasAnyOf', qb => qb.where('total', '>', 100))
|
|
141
|
+
.execute();
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Conditional Updates
|
|
145
|
+
|
|
146
|
+
You can use `where` clauses to update only the records that match a specific condition.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// Update the status of all orders placed before a certain date
|
|
150
|
+
const { affectedRecords } = await qb
|
|
151
|
+
.update('orders')
|
|
152
|
+
.set({ status: 'archived' })
|
|
153
|
+
.where('orderDate', '<', '2023-01-01')
|
|
154
|
+
.execute();
|
|
155
|
+
```
|
|
@@ -2,23 +2,115 @@ import type { AggregateNode, AggregateRecord } from './@types/aggregate.js';
|
|
|
2
2
|
import type { AnyDB } from './@types/internal-types.js';
|
|
3
3
|
import { Executor } from './executor.js';
|
|
4
4
|
import { FilterableQueryBuilder } from './where-query-builder.js';
|
|
5
|
+
/**
|
|
6
|
+
* A query builder for performing aggregation queries.
|
|
7
|
+
* @template DB - The database type.
|
|
8
|
+
* @template TableName - The name of the table to aggregate from.
|
|
9
|
+
* @template TGroupBy - The fields to group by.
|
|
10
|
+
* @template TAggregations - The aggregations to perform.
|
|
11
|
+
*/
|
|
5
12
|
export declare class AggregationQueryBuilder<DB extends AnyDB, TableName extends keyof DB, TGroupBy extends readonly (keyof DB[TableName] & string)[] = [], TAggregations extends {
|
|
6
13
|
[K in keyof DB[TableName] & string]?: readonly (keyof DB[TableName][K]['aggregations'])[];
|
|
7
14
|
} = object> extends FilterableQueryBuilder<DB, TableName> {
|
|
8
15
|
#private;
|
|
9
16
|
constructor(node: AggregateNode, executor: Executor);
|
|
17
|
+
/**
|
|
18
|
+
* Groups the results by a specified field.
|
|
19
|
+
* @param field - The field to group by.
|
|
20
|
+
* @param direction - The sort direction for the grouping.
|
|
21
|
+
* @returns A new `AggregationQueryBuilder` instance with the grouping applied.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const userCounts = await qb
|
|
26
|
+
* .aggregateFrom('users')
|
|
27
|
+
* .groupBy('role')
|
|
28
|
+
* .withAggregates({ id: ['count'] })
|
|
29
|
+
* .execute();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
10
32
|
groupBy<const TField extends keyof DB[TableName] & string>(field: TField, direction?: 'asc' | 'desc'): AggregationQueryBuilder<DB, TableName, [
|
|
11
33
|
...TGroupBy,
|
|
12
34
|
TField
|
|
13
35
|
], TAggregations>;
|
|
36
|
+
/**
|
|
37
|
+
* Specifies the aggregations to perform.
|
|
38
|
+
* @param aggregates - An object where the keys are field names and the values are arrays of aggregation functions.
|
|
39
|
+
* @returns A new `AggregationQueryBuilder` instance with the aggregations applied.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const userStats = await qb
|
|
44
|
+
* .aggregateFrom('users')
|
|
45
|
+
* .withAggregates({
|
|
46
|
+
* id: ['count'],
|
|
47
|
+
* age: ['avg', 'sum'],
|
|
48
|
+
* })
|
|
49
|
+
* .execute();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
14
52
|
withAggregates<const T extends {
|
|
15
53
|
[K in keyof DB[TableName] & string]?: readonly (keyof DB[TableName][K]['aggregations'])[];
|
|
16
54
|
}>(aggregates: T): AggregationQueryBuilder<DB, TableName, TGroupBy, TAggregations & T>;
|
|
55
|
+
/**
|
|
56
|
+
* Sets the maximum number of records to return.
|
|
57
|
+
* @param count - The maximum number of records.
|
|
58
|
+
* @returns A new `AggregationQueryBuilder` instance with the limit applied.
|
|
59
|
+
*/
|
|
17
60
|
limit(count: number): AggregationQueryBuilder<DB, TableName, TGroupBy, TAggregations>;
|
|
61
|
+
/**
|
|
62
|
+
* Sets the number of records to skip.
|
|
63
|
+
* @param count - The number of records to skip.
|
|
64
|
+
* @returns A new `AggregationQueryBuilder` instance with the offset applied.
|
|
65
|
+
*/
|
|
18
66
|
offset(count: number): AggregationQueryBuilder<DB, TableName, TGroupBy, TAggregations>;
|
|
67
|
+
/**
|
|
68
|
+
* Paginates the results.
|
|
69
|
+
* @param page - The page number to retrieve.
|
|
70
|
+
* @param limit - The number of records per page.
|
|
71
|
+
* @returns A new `AggregationQueryBuilder` instance with pagination applied.
|
|
72
|
+
*/
|
|
19
73
|
paginate(page: number, limit: number): AggregationQueryBuilder<DB, TableName, TGroupBy, TAggregations>;
|
|
74
|
+
/**
|
|
75
|
+
* Sorts the results by a specified field.
|
|
76
|
+
* @param field - The field to sort by.
|
|
77
|
+
* @param direction - The sort direction ('asc' or 'desc').
|
|
78
|
+
* @returns A new `AggregationQueryBuilder` instance with the sorting applied.
|
|
79
|
+
*/
|
|
20
80
|
orderBy(field: keyof DB[TableName], direction?: 'asc' | 'desc'): AggregationQueryBuilder<DB, TableName, TGroupBy, TAggregations>;
|
|
81
|
+
/**
|
|
82
|
+
* Executes the aggregation query.
|
|
83
|
+
* @returns A promise that resolves with an array of the aggregation results.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const userCounts = await qb
|
|
88
|
+
* .aggregateFrom('users')
|
|
89
|
+
* .groupBy('role')
|
|
90
|
+
* .withAggregates({ id: ['count'] })
|
|
91
|
+
* .execute();
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
21
94
|
execute(): Promise<AggregateRecord<DB, TableName, TGroupBy, TAggregations>[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Subscribes to the results of the aggregation query.
|
|
97
|
+
* @param callback - A callback function that will be called with the results of the aggregation query.
|
|
98
|
+
* @returns A function to unsubscribe from the query.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const unsubscribe = qb
|
|
103
|
+
* .aggregateFrom('users')
|
|
104
|
+
* .groupBy('role')
|
|
105
|
+
* .withAggregates({ id: ['count'] })
|
|
106
|
+
* .subscribe((userCounts) => {
|
|
107
|
+
* console.log('User counts by role:', userCounts);
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* // To stop listening for updates
|
|
111
|
+
* unsubscribe();
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
22
114
|
subscribe(callback: (result: AggregateRecord<DB, TableName, TGroupBy, TAggregations>[]) => void): Promise<{
|
|
23
115
|
unsubscribe: () => Promise<void>;
|
|
24
116
|
}>;
|
|
@@ -2,12 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AggregationQueryBuilder = void 0;
|
|
4
4
|
const where_query_builder_js_1 = require("./where-query-builder.js");
|
|
5
|
+
/**
|
|
6
|
+
* A query builder for performing aggregation queries.
|
|
7
|
+
* @template DB - The database type.
|
|
8
|
+
* @template TableName - The name of the table to aggregate from.
|
|
9
|
+
* @template TGroupBy - The fields to group by.
|
|
10
|
+
* @template TAggregations - The aggregations to perform.
|
|
11
|
+
*/
|
|
5
12
|
class AggregationQueryBuilder extends where_query_builder_js_1.FilterableQueryBuilder {
|
|
6
13
|
#node;
|
|
7
14
|
constructor(node, executor) {
|
|
8
15
|
super(node, executor);
|
|
9
16
|
this.#node = node;
|
|
10
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Groups the results by a specified field.
|
|
20
|
+
* @param field - The field to group by.
|
|
21
|
+
* @param direction - The sort direction for the grouping.
|
|
22
|
+
* @returns A new `AggregationQueryBuilder` instance with the grouping applied.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const userCounts = await qb
|
|
27
|
+
* .aggregateFrom('users')
|
|
28
|
+
* .groupBy('role')
|
|
29
|
+
* .withAggregates({ id: ['count'] })
|
|
30
|
+
* .execute();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
11
33
|
groupBy(field, direction = 'asc') {
|
|
12
34
|
const newGrouping = {
|
|
13
35
|
field,
|
|
@@ -18,6 +40,22 @@ class AggregationQueryBuilder extends where_query_builder_js_1.FilterableQueryBu
|
|
|
18
40
|
groupings: [...(this.#node.groupings || []), newGrouping],
|
|
19
41
|
}, this._executor);
|
|
20
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Specifies the aggregations to perform.
|
|
45
|
+
* @param aggregates - An object where the keys are field names and the values are arrays of aggregation functions.
|
|
46
|
+
* @returns A new `AggregationQueryBuilder` instance with the aggregations applied.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const userStats = await qb
|
|
51
|
+
* .aggregateFrom('users')
|
|
52
|
+
* .withAggregates({
|
|
53
|
+
* id: ['count'],
|
|
54
|
+
* age: ['avg', 'sum'],
|
|
55
|
+
* })
|
|
56
|
+
* .execute();
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
21
59
|
withAggregates(aggregates) {
|
|
22
60
|
const newAggregates = { ...this.#node.aggregations };
|
|
23
61
|
for (const key in aggregates) {
|
|
@@ -28,21 +66,43 @@ class AggregationQueryBuilder extends where_query_builder_js_1.FilterableQueryBu
|
|
|
28
66
|
aggregations: newAggregates,
|
|
29
67
|
}, this._executor);
|
|
30
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Sets the maximum number of records to return.
|
|
71
|
+
* @param count - The maximum number of records.
|
|
72
|
+
* @returns A new `AggregationQueryBuilder` instance with the limit applied.
|
|
73
|
+
*/
|
|
31
74
|
limit(count) {
|
|
32
75
|
return new AggregationQueryBuilder({
|
|
33
76
|
...this.#node,
|
|
34
77
|
pagination: { ...this.#node.pagination, limit: count },
|
|
35
78
|
}, this._executor);
|
|
36
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Sets the number of records to skip.
|
|
82
|
+
* @param count - The number of records to skip.
|
|
83
|
+
* @returns A new `AggregationQueryBuilder` instance with the offset applied.
|
|
84
|
+
*/
|
|
37
85
|
offset(count) {
|
|
38
86
|
return new AggregationQueryBuilder({
|
|
39
87
|
...this.#node,
|
|
40
88
|
pagination: { ...this.#node.pagination, offset: count },
|
|
41
89
|
}, this._executor);
|
|
42
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Paginates the results.
|
|
93
|
+
* @param page - The page number to retrieve.
|
|
94
|
+
* @param limit - The number of records per page.
|
|
95
|
+
* @returns A new `AggregationQueryBuilder` instance with pagination applied.
|
|
96
|
+
*/
|
|
43
97
|
paginate(page, limit) {
|
|
44
98
|
return this.offset((page - 1) * limit).limit(limit);
|
|
45
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Sorts the results by a specified field.
|
|
102
|
+
* @param field - The field to sort by.
|
|
103
|
+
* @param direction - The sort direction ('asc' or 'desc').
|
|
104
|
+
* @returns A new `AggregationQueryBuilder` instance with the sorting applied.
|
|
105
|
+
*/
|
|
46
106
|
orderBy(field, direction = 'asc') {
|
|
47
107
|
const newSorting = {
|
|
48
108
|
field: field,
|
|
@@ -53,10 +113,42 @@ class AggregationQueryBuilder extends where_query_builder_js_1.FilterableQueryBu
|
|
|
53
113
|
sorting: [...(this.#node.sorting || []), newSorting],
|
|
54
114
|
}, this._executor);
|
|
55
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Executes the aggregation query.
|
|
118
|
+
* @returns A promise that resolves with an array of the aggregation results.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const userCounts = await qb
|
|
123
|
+
* .aggregateFrom('users')
|
|
124
|
+
* .groupBy('role')
|
|
125
|
+
* .withAggregates({ id: ['count'] })
|
|
126
|
+
* .execute();
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
56
129
|
async execute() {
|
|
57
130
|
const response = await this._executor.execute(this);
|
|
58
131
|
return response;
|
|
59
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Subscribes to the results of the aggregation query.
|
|
135
|
+
* @param callback - A callback function that will be called with the results of the aggregation query.
|
|
136
|
+
* @returns A function to unsubscribe from the query.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const unsubscribe = qb
|
|
141
|
+
* .aggregateFrom('users')
|
|
142
|
+
* .groupBy('role')
|
|
143
|
+
* .withAggregates({ id: ['count'] })
|
|
144
|
+
* .subscribe((userCounts) => {
|
|
145
|
+
* console.log('User counts by role:', userCounts);
|
|
146
|
+
* });
|
|
147
|
+
*
|
|
148
|
+
* // To stop listening for updates
|
|
149
|
+
* unsubscribe();
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
60
152
|
subscribe(callback) {
|
|
61
153
|
return this._executor.subscribe([this], callback);
|
|
62
154
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregation-query-builder.js","sourceRoot":"","sources":["../../src/aggregation-query-builder.ts"],"names":[],"mappings":";;;A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CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D,CAAC;IACJ,CAAC;CACF;AA1OD,0DA0OC"}
|
|
@@ -10,12 +10,48 @@ type InferExecuteResult<TBuilder> = TBuilder extends {
|
|
|
10
10
|
execute: () => Promise<any>;
|
|
11
11
|
} ? Awaited<ReturnType<TBuilder['execute']>> : never;
|
|
12
12
|
export type AreAllBuildersSubscribable<TBuilders extends readonly AnyQueryBuilder[]> = TBuilders[number] extends AnySubscribableQueryBuilder ? true : false;
|
|
13
|
+
/**
|
|
14
|
+
* A query builder for executing multiple queries in a single batch.
|
|
15
|
+
* @template TBuilders - An array of query builders to execute.
|
|
16
|
+
*/
|
|
13
17
|
export declare class BatchQueryBuilder<const TBuilders extends readonly AnyQueryBuilder[]> {
|
|
14
18
|
#private;
|
|
15
19
|
constructor(builders: TBuilders, executor: Executor);
|
|
20
|
+
/**
|
|
21
|
+
* Executes the batch query.
|
|
22
|
+
* @returns A promise that resolves with an array of the results from each query in the batch.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const [users, newUser] = await qb.batch([
|
|
27
|
+
* qb.selectFrom('users').select(['id', 'name']),
|
|
28
|
+
* qb.insertInto('users').values({ name: 'New User' }).returning(['id', 'name']),
|
|
29
|
+
* ]).execute();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
16
32
|
execute(): Promise<{
|
|
17
33
|
-readonly [K in keyof TBuilders]: InferExecuteResult<TBuilders[K]>;
|
|
18
34
|
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Subscribes to the results of the batch query.
|
|
37
|
+
* This is only possible if all queries in the batch are subscribable (select and aggregate).
|
|
38
|
+
* @param callback - A callback function that will be called with the results of the batch query.
|
|
39
|
+
* @returns A function to unsubscribe from the query.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const unsubscribe = qb.batch([
|
|
44
|
+
* qb.selectFrom('users').select(['id', 'name']),
|
|
45
|
+
* qb.aggregateFrom('users').groupBy('role').withAggregates({ id: ['count'] }),
|
|
46
|
+
* ]).subscribe(([users, userAggregates]) => {
|
|
47
|
+
* console.log('Users:', users);
|
|
48
|
+
* console.log('User Aggregates:', userAggregates);
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // To stop listening for updates
|
|
52
|
+
* unsubscribe();
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
19
55
|
subscribe(callback: (...results: {
|
|
20
56
|
-readonly [K in keyof TBuilders]: InferExecuteResult<TBuilders[K]>;
|
|
21
57
|
}) => void): Promise<{
|
|
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BatchQueryBuilder = void 0;
|
|
4
4
|
const aggregation_query_builder_js_1 = require("./aggregation-query-builder.js");
|
|
5
5
|
const query_builder_js_1 = require("./query-builder.js");
|
|
6
|
+
/**
|
|
7
|
+
* A query builder for executing multiple queries in a single batch.
|
|
8
|
+
* @template TBuilders - An array of query builders to execute.
|
|
9
|
+
*/
|
|
6
10
|
class BatchQueryBuilder {
|
|
7
11
|
#builders;
|
|
8
12
|
#executor;
|
|
@@ -10,9 +14,41 @@ class BatchQueryBuilder {
|
|
|
10
14
|
this.#builders = builders;
|
|
11
15
|
this.#executor = executor;
|
|
12
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Executes the batch query.
|
|
19
|
+
* @returns A promise that resolves with an array of the results from each query in the batch.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const [users, newUser] = await qb.batch([
|
|
24
|
+
* qb.selectFrom('users').select(['id', 'name']),
|
|
25
|
+
* qb.insertInto('users').values({ name: 'New User' }).returning(['id', 'name']),
|
|
26
|
+
* ]).execute();
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
13
29
|
async execute() {
|
|
14
30
|
return this.#executor.execute(this);
|
|
15
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Subscribes to the results of the batch query.
|
|
34
|
+
* This is only possible if all queries in the batch are subscribable (select and aggregate).
|
|
35
|
+
* @param callback - A callback function that will be called with the results of the batch query.
|
|
36
|
+
* @returns A function to unsubscribe from the query.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const unsubscribe = qb.batch([
|
|
41
|
+
* qb.selectFrom('users').select(['id', 'name']),
|
|
42
|
+
* qb.aggregateFrom('users').groupBy('role').withAggregates({ id: ['count'] }),
|
|
43
|
+
* ]).subscribe(([users, userAggregates]) => {
|
|
44
|
+
* console.log('Users:', users);
|
|
45
|
+
* console.log('User Aggregates:', userAggregates);
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // To stop listening for updates
|
|
49
|
+
* unsubscribe();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
16
52
|
subscribe(callback) {
|
|
17
53
|
const builders = this.#builders.filter(builder => builder instanceof aggregation_query_builder_js_1.AggregationQueryBuilder ||
|
|
18
54
|
builder instanceof query_builder_js_1.QueryBuilder);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-query-builder.js","sourceRoot":"","sources":["../../src/batch-query-builder.ts"],"names":[],"mappings":";;;AAAA,iFAAyE;AAIzE,yDAAkD;AAuBlD,MAAa,iBAAiB;IAG5B,SAAS,CAAY;IACrB,SAAS,CAAW;IAEpB,YAAY,QAAmB,EAAE,QAAkB;QACjD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,KAAK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;;;;;;;;;;;;;;OAmBG;IACH,SAAS,CACP,QAIS;QAET,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CACpC,OAAO,CAAC,EAAE,CACR,OAAO,YAAY,sDAAuB;YAC1C,OAAO,YAAY,+BAAY,CAClC,CAAC;QAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CACb,wEAAwE,CACzE,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAe,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO;QACL,MAAM,KAAK,GAAG,6DAA6D,CAAC;QAE5E,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YAC5C,OAAO,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,KAAK;YACL,SAAS,EAAE;gBACT,QAAQ;aACT;SACF,CAAC;IACJ,CAAC;CACF;AArFD,8CAqFC"}
|
|
@@ -2,9 +2,26 @@ import type { DeleteNode } from './@types/delete.js';
|
|
|
2
2
|
import type { AnyDB } from './@types/internal-types.js';
|
|
3
3
|
import { Executor } from './executor.js';
|
|
4
4
|
import { FilterableQueryBuilder } from './where-query-builder.js';
|
|
5
|
+
/**
|
|
6
|
+
* A query builder for deleting records from the database.
|
|
7
|
+
* @template DB - The database type.
|
|
8
|
+
* @template TableName - The name of the table to delete from.
|
|
9
|
+
*/
|
|
5
10
|
export declare class DeleteQueryBuilder<DB extends AnyDB, TableName extends keyof DB> extends FilterableQueryBuilder<DB, TableName> {
|
|
6
11
|
#private;
|
|
7
12
|
constructor(node: DeleteNode, executor: Executor);
|
|
13
|
+
/**
|
|
14
|
+
* Executes the delete query.
|
|
15
|
+
* @returns A promise that resolves with the number of affected records.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const { affectedRecords } = await qb
|
|
20
|
+
* .deleteFrom('users')
|
|
21
|
+
* .where('id', '=', 1)
|
|
22
|
+
* .execute();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
8
25
|
execute(): Promise<{
|
|
9
26
|
affectedRecords: number;
|
|
10
27
|
}>;
|
|
@@ -2,12 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DeleteQueryBuilder = void 0;
|
|
4
4
|
const where_query_builder_js_1 = require("./where-query-builder.js");
|
|
5
|
+
/**
|
|
6
|
+
* A query builder for deleting records from the database.
|
|
7
|
+
* @template DB - The database type.
|
|
8
|
+
* @template TableName - The name of the table to delete from.
|
|
9
|
+
*/
|
|
5
10
|
class DeleteQueryBuilder extends where_query_builder_js_1.FilterableQueryBuilder {
|
|
6
11
|
#node;
|
|
7
12
|
constructor(node, executor) {
|
|
8
13
|
super(node, executor);
|
|
9
14
|
this.#node = node;
|
|
10
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Executes the delete query.
|
|
18
|
+
* @returns A promise that resolves with the number of affected records.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const { affectedRecords } = await qb
|
|
23
|
+
* .deleteFrom('users')
|
|
24
|
+
* .where('id', '=', 1)
|
|
25
|
+
* .execute();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
11
28
|
async execute() {
|
|
12
29
|
const response = await this._executor.execute(this);
|
|
13
30
|
return response[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-query-builder.js","sourceRoot":"","sources":["../../src/delete-query-builder.ts"],"names":[],"mappings":";;;AAGA,qEAAkE;AAElE,MAAa,kBAGX,SAAQ,+CAAqC;IAC7C,KAAK,CAAa;IAElB,YAAY,IAAgB,EAAE,QAAkB;QAC9C,KAAK,CAAC,IAAI,E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AC,CAAC;IACrB,CAAC;IAED,OAAO;QACL,MAAM,KAAK,GAAG,6DAA6D,CAAC;QAE5E,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;QAE3C,OAAO;YACL,KAAK;YACL,SAAS,EAAE;gBACT,QAAQ;aACT;SACF,CAAC;IACJ,CAAC;IAED,gBAAgB;QACd,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS;YAC/B,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;gBAC7C,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE;gBACvC,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;IACJ,CAAC;CACF;AApDD,gDAoDC"}
|
|
@@ -3,14 +3,82 @@ import type { AnyDB } from './@types/internal-types.js';
|
|
|
3
3
|
import { NonLinkColumnNames } from './@types/query-builder.js';
|
|
4
4
|
import { ResolveSelection } from './@types/type-helpers.js';
|
|
5
5
|
import { Executor } from './executor.js';
|
|
6
|
+
/**
|
|
7
|
+
* A query builder for creating new records in the database.
|
|
8
|
+
* @template DB - The database type.
|
|
9
|
+
* @template TableName - The name of the table to insert into.
|
|
10
|
+
* @template Selection - The type of the selected fields.
|
|
11
|
+
*/
|
|
6
12
|
export declare class InsertQueryBuilder<DB extends AnyDB, TableName extends keyof DB, Selection = {
|
|
7
13
|
id: number;
|
|
8
14
|
}> {
|
|
9
15
|
#private;
|
|
10
16
|
constructor(node: InsertNode, executor: Executor);
|
|
17
|
+
/**
|
|
18
|
+
* The values to insert into the table.
|
|
19
|
+
* @param values - An object or array of objects representing the records to create.
|
|
20
|
+
* @returns The `InsertQueryBuilder` instance for chaining.
|
|
21
|
+
*
|
|
22
|
+
* @example Single Record Insertion
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const newUser = await qb
|
|
25
|
+
* .insertInto('users')
|
|
26
|
+
* .values({ name: 'John Doe', email: 'john.doe@example.com' })
|
|
27
|
+
* .executeTakeFirst();
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example Multiple Record Insertion
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const newUsers = await qb
|
|
33
|
+
* .insertInto('users')
|
|
34
|
+
* .values([{ name: 'John Doe' }, { name: 'Jane Doe' }])
|
|
35
|
+
* .execute();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
11
38
|
values(values: Insertable<DB[TableName]> | Insertable<DB[TableName]>[]): InsertQueryBuilder<DB, TableName, Selection>;
|
|
39
|
+
/**
|
|
40
|
+
* The fields to return after the insert operation.
|
|
41
|
+
* @param fields - An array of field names to return.
|
|
42
|
+
* @returns The `InsertQueryBuilder` instance for chaining.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const newUser = await qb
|
|
47
|
+
* .insertInto('users')
|
|
48
|
+
* .values({ name: 'John Doe' })
|
|
49
|
+
* .returning(['id', 'name'])
|
|
50
|
+
* .executeTakeFirst();
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
12
53
|
returning<const TFields extends readonly NonLinkColumnNames<DB[TableName]>[]>(fields: TFields): InsertQueryBuilder<DB, TableName, ResolveSelection<DB, TableName, TFields, object>>;
|
|
54
|
+
/**
|
|
55
|
+
* Executes the insert query.
|
|
56
|
+
* @returns A promise that resolves with an array of the selected fields from the inserted records.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const newUsers = await qb
|
|
61
|
+
* .insertInto('users')
|
|
62
|
+
* .values([{ name: 'John Doe' }, { name: 'Jane Doe' }])
|
|
63
|
+
* .returning(['id', 'name'])
|
|
64
|
+
* .execute();
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
13
67
|
execute(): Promise<Selection[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Executes the insert query and returns the first result.
|
|
70
|
+
* @returns A promise that resolves with the first inserted record, or `null` if no records were inserted.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const newUser = await qb
|
|
75
|
+
* .insertInto('users')
|
|
76
|
+
* .values({ name: 'John Doe' })
|
|
77
|
+
* .returning(['id', 'name'])
|
|
78
|
+
* .executeTakeFirst();
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
executeTakeFirst(): Promise<Selection | null>;
|
|
14
82
|
compile(): {
|
|
15
83
|
query: string;
|
|
16
84
|
variables: Record<string, any>;
|