@taylordb/query-builder 0.1.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/README.md +113 -0
- package/dist/example.d.ts +1 -0
- package/dist/example.js +51 -0
- package/dist/example.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/insert-query-builder.d.ts +6 -0
- package/dist/insert-query-builder.js +9 -0
- package/dist/insert-query-builder.js.map +1 -0
- package/dist/internal-types.d.ts +19 -0
- package/dist/internal-types.js +2 -0
- package/dist/internal-types.js.map +1 -0
- package/dist/query-builder.d.ts +15 -0
- package/dist/query-builder.js +101 -0
- package/dist/query-builder.js.map +1 -0
- package/dist/sample/basic-example.d.ts +1 -0
- package/dist/sample/basic-example.js +55 -0
- package/dist/sample/basic-example.js.map +1 -0
- package/dist/sample/sample-1/index.d.ts +1 -0
- package/dist/sample/sample-1/index.js +68 -0
- package/dist/sample/sample-1/index.js.map +1 -0
- package/dist/sample/sample-1/taylorclient.types.d.ts +150 -0
- package/dist/sample/sample-1/taylorclient.types.js +9 -0
- package/dist/sample/sample-1/taylorclient.types.js.map +1 -0
- package/dist/src/@types/aggregate.d.ts +28 -0
- package/dist/src/@types/aggregate.js +3 -0
- package/dist/src/@types/aggregate.js.map +1 -0
- package/dist/src/@types/delete.d.ts +2 -0
- package/dist/src/@types/delete.js +3 -0
- package/dist/src/@types/delete.js.map +1 -0
- package/dist/src/@types/insert.d.ts +8 -0
- package/dist/src/@types/insert.js +3 -0
- package/dist/src/@types/insert.js.map +1 -0
- package/dist/src/@types/internal-types.d.ts +24 -0
- package/dist/src/@types/internal-types.js +3 -0
- package/dist/src/@types/internal-types.js.map +1 -0
- package/dist/src/@types/query-builder.d.ts +7 -0
- package/dist/src/@types/query-builder.js +3 -0
- package/dist/src/@types/query-builder.js.map +1 -0
- package/dist/src/@types/type-helpers.d.ts +27 -0
- package/dist/src/@types/type-helpers.js +3 -0
- package/dist/src/@types/type-helpers.js.map +1 -0
- package/dist/src/@types/update.d.ts +5 -0
- package/dist/src/@types/update.js +3 -0
- package/dist/src/@types/update.js.map +1 -0
- package/dist/src/__tests__/query-builder.spec.d.ts +1 -0
- package/dist/src/__tests__/query-builder.spec.js +129 -0
- package/dist/src/__tests__/query-builder.spec.js.map +1 -0
- package/dist/src/__tests__/taylorclient.types.d.ts +150 -0
- package/dist/src/__tests__/taylorclient.types.js +9 -0
- package/dist/src/__tests__/taylorclient.types.js.map +1 -0
- package/dist/src/aggregation-query-builder.d.ts +27 -0
- package/dist/src/aggregation-query-builder.js +80 -0
- package/dist/src/aggregation-query-builder.js.map +1 -0
- package/dist/src/batch-query-builder.d.ts +16 -0
- package/dist/src/batch-query-builder.js +28 -0
- package/dist/src/batch-query-builder.js.map +1 -0
- package/dist/src/delete-query-builder.d.ts +16 -0
- package/dist/src/delete-query-builder.js +36 -0
- package/dist/src/delete-query-builder.js.map +1 -0
- package/dist/src/executor.d.ts +12 -0
- package/dist/src/executor.js +37 -0
- package/dist/src/executor.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/insert-query-builder.d.ts +17 -0
- package/dist/src/insert-query-builder.js +68 -0
- package/dist/src/insert-query-builder.js.map +1 -0
- package/dist/src/query-builder.d.ts +52 -0
- package/dist/src/query-builder.js +202 -0
- package/dist/src/query-builder.js.map +1 -0
- package/dist/src/selection-builder.d.ts +10 -0
- package/dist/src/selection-builder.js +20 -0
- package/dist/src/selection-builder.js.map +1 -0
- package/dist/src/update-query-builder.d.ts +17 -0
- package/dist/src/update-query-builder.js +43 -0
- package/dist/src/update-query-builder.js.map +1 -0
- package/dist/src/where-query-builder.d.ts +14 -0
- package/dist/src/where-query-builder.js +68 -0
- package/dist/src/where-query-builder.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/where-query-builder.d.ts +12 -0
- package/dist/where-query-builder.js +55 -0
- package/dist/where-query-builder.js.map +1 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# @taylordb/query-builder
|
|
2
|
+
|
|
3
|
+
<img src="../../docs/media/logo.png" width="200" />
|
|
4
|
+
|
|
5
|
+
This package contains the official TypeScript query builder for TaylorDB. It provides a type-safe and intuitive API for building and executing queries against your TaylorDB database.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Type-Safe Queries**: Leverage your database schema to get full type safety and autocompletion for your queries.
|
|
10
|
+
- **Fluent API**: Chain methods together to build complex queries with ease.
|
|
11
|
+
- **CRUD Operations**: Full support for `select`, `insert`, `update`, and `delete` operations.
|
|
12
|
+
- **Advanced Filtering**: Filter your data with a rich set of operators and logical conjunctions.
|
|
13
|
+
- **Pagination and Sorting**: Easily paginate and sort your query results.
|
|
14
|
+
- **Batch Queries**: Execute multiple queries in a single request for improved performance.
|
|
15
|
+
- **Aggregation Queries**: Perform powerful aggregation queries with grouping and aggregate functions.
|
|
16
|
+
|
|
17
|
+
## Getting Started
|
|
18
|
+
|
|
19
|
+
First, you'll need to generate a `taylorclient.types.ts` file from your TaylorDB schema. You can do this using the TaylorDB CLI:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx @taylordb/cli generate-schema
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Once you have your types file, you can create a new query builder instance:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { createQueryBuilder } from '@taylordb/query-builder';
|
|
29
|
+
import { TaylorDatabase } from './taylorclient.types';
|
|
30
|
+
|
|
31
|
+
const qb = createQueryBuilder<TaylorDatabase>({
|
|
32
|
+
baseUrl: 'YOUR_TAYLORDB_BASE_URL',
|
|
33
|
+
apiKey: 'YOUR_TAYLORDB_API_KEY',
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
### Selecting Data
|
|
40
|
+
|
|
41
|
+
You can select data from a table using the `selectFrom` method. You can specify which fields to return, and you can filter, sort, and paginate the results.
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
const customers = await qb
|
|
45
|
+
.selectFrom('customers')
|
|
46
|
+
.select(['firstName', 'lastName'])
|
|
47
|
+
.where('firstName', '=', 'John')
|
|
48
|
+
.orderBy('lastName', 'asc')
|
|
49
|
+
.paginate(1, 10)
|
|
50
|
+
.execute();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Inserting Data
|
|
54
|
+
|
|
55
|
+
You can insert data into a table using the `insertInto` method.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const newCustomer = await qb
|
|
59
|
+
.insertInto('customers')
|
|
60
|
+
.values({
|
|
61
|
+
firstName: 'Jane',
|
|
62
|
+
lastName: 'Doe',
|
|
63
|
+
})
|
|
64
|
+
.execute();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Updating Data
|
|
68
|
+
|
|
69
|
+
You can update data in a table using the `update` method.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const updatedCustomer = await qb
|
|
73
|
+
.update('customers')
|
|
74
|
+
.set({ lastName: 'Smith' })
|
|
75
|
+
.where('id', '=', 1)
|
|
76
|
+
.execute();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Deleting Data
|
|
80
|
+
|
|
81
|
+
You can delete data from a table using the `deleteFrom` method.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const result = await qb.deleteFrom('customers').where('id', '=', 1).execute();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Batch Queries
|
|
88
|
+
|
|
89
|
+
You can execute multiple queries in a single batch request for improved performance. The result will be a tuple that corresponds to the results of each query in the batch.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const [customers, newCustomer] = await qb
|
|
93
|
+
.batch([
|
|
94
|
+
qb.selectFrom('customers').select(['firstName', 'lastName']),
|
|
95
|
+
qb.insertInto('customers').values({ firstName: 'John', lastName: 'Doe' }),
|
|
96
|
+
])
|
|
97
|
+
.execute();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Aggregation Queries
|
|
101
|
+
|
|
102
|
+
You can perform powerful aggregation queries using the `aggregateFrom` method. You can group by one or more fields and specify aggregate functions to apply.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const aggregates = await qb
|
|
106
|
+
.aggregateFrom('customers')
|
|
107
|
+
.groupBy('firstName', 'asc')
|
|
108
|
+
.groupBy('lastName', 'desc')
|
|
109
|
+
.withAggregates({
|
|
110
|
+
id: ['count', 'sum'],
|
|
111
|
+
})
|
|
112
|
+
.execute();
|
|
113
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/example.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createQueryBuilder } from './query-builder';
|
|
2
|
+
// --- End of Sample Database Definition ---
|
|
3
|
+
const qb = createQueryBuilder();
|
|
4
|
+
// Example 1: Simple select with a where clause
|
|
5
|
+
const simpleSelect = qb
|
|
6
|
+
.selectFrom('customers')
|
|
7
|
+
.select(['id', 'name', 'email'])
|
|
8
|
+
.where('email', '=', 'test@example.com')
|
|
9
|
+
.compile();
|
|
10
|
+
console.log('--- Simple Select ---');
|
|
11
|
+
console.log(simpleSelect);
|
|
12
|
+
// Example 2: Select with multiple conditions (AND)
|
|
13
|
+
const andConditions = qb
|
|
14
|
+
.selectFrom('customers')
|
|
15
|
+
.select(['id', 'name'])
|
|
16
|
+
.where('name', '=', 'John Doe')
|
|
17
|
+
.where('phone', '!=', '555-1234')
|
|
18
|
+
.compile();
|
|
19
|
+
console.log('\n--- AND Conditions ---');
|
|
20
|
+
console.log(andConditions);
|
|
21
|
+
// Example 3: Select with OR conditions
|
|
22
|
+
const orConditions = qb
|
|
23
|
+
.selectFrom('customers')
|
|
24
|
+
.select(['id', 'name'])
|
|
25
|
+
.where('name', '=', 'John Doe')
|
|
26
|
+
.orWhere('email', 'contains', '@example.com')
|
|
27
|
+
.compile();
|
|
28
|
+
console.log('\n--- OR Conditions ---');
|
|
29
|
+
console.log(orConditions);
|
|
30
|
+
// Example 4: Nested conditions
|
|
31
|
+
const nestedConditions = qb
|
|
32
|
+
.selectFrom('customers')
|
|
33
|
+
.select(['id', 'name'])
|
|
34
|
+
.where(qb => qb.where('name', 'startsWith', 'J').where('email', 'endsWith', '.com'))
|
|
35
|
+
.orWhere(qb => qb.where('phone', 'contains', '555'))
|
|
36
|
+
.compile();
|
|
37
|
+
console.log('\n--- Nested Conditions ---');
|
|
38
|
+
console.log(nestedConditions);
|
|
39
|
+
// Example 5: Relational select
|
|
40
|
+
const relationalSelect = qb
|
|
41
|
+
.selectFrom('customers')
|
|
42
|
+
.select([
|
|
43
|
+
'id',
|
|
44
|
+
'name',
|
|
45
|
+
qb => qb.selectFrom('orders').select(['id', 'address']),
|
|
46
|
+
])
|
|
47
|
+
.where('id', '=', 1)
|
|
48
|
+
.compile();
|
|
49
|
+
console.log('\n--- Relational Select ---');
|
|
50
|
+
console.log(relationalSelect);
|
|
51
|
+
//# sourceMappingURL=example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example.js","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAuBnD,4CAA4C;AAE5C,MAAM,EAAE,GAAG,kBAAkB,EAAkB,CAAC;AAEhD,+CAA+C;AAC/C,MAAM,YAAY,GAAG,EAAE;KACpB,UAAU,CAAC,WAAW,CAAC;KACvB,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,kBAAkB,CAAC;KACvC,OAAO,EAAE,CAAC;AAEb,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC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AAC,6BAA6B,CAAC,CAAC;AAC3C,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAE9B,+BAA+B;AAC/B,MAAM,gBAAgB,GAAG,EAAE;KACxB,UAAU,CAAC,WAAW,CAAC;KACvB,MAAM,CAAC;IACN,IAAI;IACJ,MAAM;IACN,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;CACxD,CAAC;KACD,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;KACnB,OAAO,EAAE,CAAC;AAEb,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC3C,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createQueryBuilder } from './query-builder';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insert-query-builder.js","sourceRoot":"","sources":["../src/insert-query-builder.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,kBAAkB;IAI7B,MAAM,CAAC,KAA6B;QAClC,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACzD,OAAO;YACL,OAAO,EAAE,GAAG,EAAE,CAAC,kBAAkB;SAClC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type AnyDB = Record<string, Record<string, any>>;
|
|
2
|
+
export type WhereClause = {
|
|
3
|
+
field: string;
|
|
4
|
+
operator: string;
|
|
5
|
+
value: any;
|
|
6
|
+
};
|
|
7
|
+
export type FilterGroup = {
|
|
8
|
+
conjunction: 'and' | 'or';
|
|
9
|
+
filters: (WhereClause | FilterGroup)[];
|
|
10
|
+
};
|
|
11
|
+
export type QueryNode = {
|
|
12
|
+
from: string;
|
|
13
|
+
selects: (string | QueryNode)[];
|
|
14
|
+
filters: FilterGroup;
|
|
15
|
+
pagination?: {
|
|
16
|
+
limit?: number;
|
|
17
|
+
offset?: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-types.js","sourceRoot":"","sources":["../src/internal-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnyDB } from './internal-types';
|
|
2
|
+
import { FilterableQueryBuilder } from './where-query-builder';
|
|
3
|
+
import { InsertQueryBuilder } from './insert-query-builder';
|
|
4
|
+
export declare class QueryBuilder<DB extends AnyDB, TableName extends keyof DB> extends FilterableQueryBuilder<DB, TableName> {
|
|
5
|
+
select<K extends keyof DB[TableName] | ((builder: RootQueryBuilder<DB>) => any)>(fields: K[]): QueryBuilder<DB, TableName>;
|
|
6
|
+
limit(count: number): QueryBuilder<DB, TableName>;
|
|
7
|
+
offset(count: number): QueryBuilder<DB, TableName>;
|
|
8
|
+
paginate(page: number, limit: number): QueryBuilder<DB, TableName>;
|
|
9
|
+
compile(): string;
|
|
10
|
+
}
|
|
11
|
+
export declare class RootQueryBuilder<DB extends AnyDB> {
|
|
12
|
+
selectFrom<TableName extends keyof DB & string>(from: TableName): QueryBuilder<DB, TableName>;
|
|
13
|
+
insertInto<TableName extends keyof DB & string>(_from: TableName): InsertQueryBuilder<DB, TableName>;
|
|
14
|
+
}
|
|
15
|
+
export declare function createQueryBuilder<DB extends AnyDB>(): RootQueryBuilder<DB>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { jsonToGraphQLQuery } from 'json-to-graphql-query';
|
|
2
|
+
import { FilterableQueryBuilder } from './where-query-builder';
|
|
3
|
+
import { InsertQueryBuilder } from './insert-query-builder';
|
|
4
|
+
export class QueryBuilder extends FilterableQueryBuilder {
|
|
5
|
+
select(fields) {
|
|
6
|
+
const newSelects = fields.map(field => {
|
|
7
|
+
if (typeof field === 'function') {
|
|
8
|
+
const builder = createQueryBuilder();
|
|
9
|
+
const subQuery = field(builder);
|
|
10
|
+
return subQuery._node;
|
|
11
|
+
}
|
|
12
|
+
return field;
|
|
13
|
+
});
|
|
14
|
+
return new QueryBuilder({
|
|
15
|
+
...this._node,
|
|
16
|
+
selects: [...this._node.selects, ...newSelects],
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
limit(count) {
|
|
20
|
+
return new QueryBuilder({
|
|
21
|
+
...this._node,
|
|
22
|
+
pagination: { ...this._node.pagination, limit: count },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
offset(count) {
|
|
26
|
+
return new QueryBuilder({
|
|
27
|
+
...this._node,
|
|
28
|
+
pagination: { ...this._node.pagination, offset: count },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
paginate(page, limit) {
|
|
32
|
+
return this.offset((page - 1) * limit).limit(limit);
|
|
33
|
+
}
|
|
34
|
+
compile() {
|
|
35
|
+
const buildFilters = (group) => {
|
|
36
|
+
if (group.filters.length === 0)
|
|
37
|
+
return undefined;
|
|
38
|
+
return {
|
|
39
|
+
conjunction: group.conjunction,
|
|
40
|
+
filtersSet: group.filters.map(f => {
|
|
41
|
+
if ('conjunction' in f) {
|
|
42
|
+
return buildFilters(f);
|
|
43
|
+
}
|
|
44
|
+
return { field: f.field, operator: f.operator, value: f.value };
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const buildSelects = (selects) => {
|
|
49
|
+
return selects.reduce((acc, field) => {
|
|
50
|
+
if (typeof field === 'string') {
|
|
51
|
+
acc[field] = true;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const subQuery = new QueryBuilder(field).compile();
|
|
55
|
+
// This is a simplification; parsing the compiled subquery would be complex.
|
|
56
|
+
const from = field.from;
|
|
57
|
+
const subSelects = buildSelects(field.selects);
|
|
58
|
+
const filters = buildFilters(field.filters);
|
|
59
|
+
const pagination = field.pagination;
|
|
60
|
+
acc[from] = {
|
|
61
|
+
...(Object.keys(subSelects).length > 0 && { records: subSelects }),
|
|
62
|
+
...(filters && { __args: { filtersSet: filters } }),
|
|
63
|
+
...(pagination && { __args: { pagination } }),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return acc;
|
|
67
|
+
}, {});
|
|
68
|
+
};
|
|
69
|
+
const mainSelects = buildSelects(this._node.selects);
|
|
70
|
+
const mainFilters = buildFilters(this._node.filters);
|
|
71
|
+
const mainPagination = this._node.pagination;
|
|
72
|
+
const query = {
|
|
73
|
+
query: {
|
|
74
|
+
[this._node.from]: {
|
|
75
|
+
...(Object.keys(mainSelects).length > 0 && { records: mainSelects }),
|
|
76
|
+
__args: {
|
|
77
|
+
...(mainFilters && { filtersSet: mainFilters }),
|
|
78
|
+
...(mainPagination && { pagination: mainPagination }),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
return jsonToGraphQLQuery(query, { pretty: true });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export class RootQueryBuilder {
|
|
87
|
+
selectFrom(from) {
|
|
88
|
+
return new QueryBuilder({
|
|
89
|
+
from: from,
|
|
90
|
+
selects: [],
|
|
91
|
+
filters: { conjunction: 'and', filters: [] },
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
insertInto(_from) {
|
|
95
|
+
return new InsertQueryBuilder();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export function createQueryBuilder() {
|
|
99
|
+
return new RootQueryBuilder();
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=query-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-builder.js","sourceRoot":"","sources":["../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W,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAC;SAC3C,CAAC,CAAC;IACL,CAAC;IAED,UAAU,CACR,KAAgB;QAEhB,OAAO,IAAI,kBAAkB,EAAiB,CAAC;IACjD,CAAC;CACF;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,gBAAgB,EAAM,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_js_1 = require("../src/index.js");
|
|
4
|
+
// --- End of Sample Database Definition ---
|
|
5
|
+
const qb = (0, index_js_1.createQueryBuilder)({
|
|
6
|
+
baseUrl: process.env.TAYLORDB_BASE_URL,
|
|
7
|
+
apiKey: process.env.TAYLORDB_API_KEY,
|
|
8
|
+
});
|
|
9
|
+
// Example 1: Simple select with a where clause
|
|
10
|
+
const simpleSelect = qb
|
|
11
|
+
.selectFrom('customers')
|
|
12
|
+
.select(['id', 'name', 'email'])
|
|
13
|
+
.where('email', '=', 'test@example.com')
|
|
14
|
+
.compile();
|
|
15
|
+
console.log('--- Simple Select ---');
|
|
16
|
+
console.log(simpleSelect);
|
|
17
|
+
// Example 2: Select with multiple conditions (AND)
|
|
18
|
+
const andConditions = qb
|
|
19
|
+
.selectFrom('customers')
|
|
20
|
+
.select(['id', 'name'])
|
|
21
|
+
.where('name', '=', 'John Doe')
|
|
22
|
+
.where('phone', '!=', '555-1234')
|
|
23
|
+
.compile();
|
|
24
|
+
console.log('\n--- AND Conditions ---');
|
|
25
|
+
console.log(andConditions);
|
|
26
|
+
// Example 3: Select with OR conditions
|
|
27
|
+
const orConditions = qb
|
|
28
|
+
.selectFrom('customers')
|
|
29
|
+
.select(['id', 'name'])
|
|
30
|
+
.where('name', '=', '2')
|
|
31
|
+
.where(qb => qb.where('name', '=', '3').orWhere('name', '=', '4'))
|
|
32
|
+
.orWhere('email', 'contains', '@example.com')
|
|
33
|
+
.compile();
|
|
34
|
+
console.log('\n--- OR Conditions ---');
|
|
35
|
+
console.log(orConditions);
|
|
36
|
+
// Example 4: Nested conditions
|
|
37
|
+
const nestedConditions = qb
|
|
38
|
+
.selectFrom('customers')
|
|
39
|
+
.select(['id', 'name'])
|
|
40
|
+
.where(qb => qb.where('name', 'startsWith', 'J').where('email', 'endsWith', '.com'))
|
|
41
|
+
.orWhere(qb => qb.where('phone', 'contains', '555'))
|
|
42
|
+
.compile();
|
|
43
|
+
console.log('\n--- Nested Conditions ---');
|
|
44
|
+
console.log(nestedConditions);
|
|
45
|
+
// Example 5: Relational select with useLink
|
|
46
|
+
const relationalSelect = qb
|
|
47
|
+
.selectFrom('customers')
|
|
48
|
+
.select(['id', 'name'])
|
|
49
|
+
.where(qb => qb.where('name', 'startsWith', 'J').where('email', 'endsWith', '.com'))
|
|
50
|
+
.where('id', '=', 1)
|
|
51
|
+
.paginate(1, 10)
|
|
52
|
+
.compile();
|
|
53
|
+
console.log('\n--- Relational Select ---');
|
|
54
|
+
console.log(relationalSelect);
|
|
55
|
+
//# sourceMappingURL=basic-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-example.js","sourceRoot":"","sources":["../../sample/basic-example.ts"],"names":[],"mappings":";;AACA,8CAAqD;AAuBrD,4CAA4C;AAE5C,MAAM,EAAE,GAAG,IAAA,6BAAkB,EAAiB;IAC5C,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAkB;IACvC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAiB;CACtC,CAAC,CAAC;AAEH,+CAA+C;AAC/C,MAAM,YAAY,GAAG,EAAE;KACpB,UAAU,CAAC,WAAW,CAAC;KACvB,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,kBAAkB,CAAC;KACvC,OA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AC,CAAC,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CACvE;KACA,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;KACnD,OAAO,EAAE,CAAC;AAEb,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC3C,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAE9B,4CAA4C;AAC5C,MAAM,gBAAgB,GAAG,EAAE;KACxB,UAAU,CAAC,WAAW,CAAC;KACvB,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;KACtB,KAAK,CAAC,EAAE,CAAC,EAAE,CACV,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CACvE;KACA,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;KACnB,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;KACf,OAAO,EAAE,CAAC;AAEb,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC3C,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const query_builder_js_1 = require("../../src/query-builder.js");
|
|
4
|
+
async function main() {
|
|
5
|
+
const qb = (0, query_builder_js_1.createQueryBuilder)({
|
|
6
|
+
baseUrl: process.env.TAYLORDB_BASE_URL,
|
|
7
|
+
apiKey: process.env.TAYLORDB_API_KEY,
|
|
8
|
+
});
|
|
9
|
+
// Example 1: Selecting data with filtering, sorting, and pagination
|
|
10
|
+
console.log('--- Selecting Customers ---');
|
|
11
|
+
const customers = await qb
|
|
12
|
+
.selectFrom('customers')
|
|
13
|
+
.select(['firstName', 'lastName'])
|
|
14
|
+
.where('firstName', 'contains', 'J')
|
|
15
|
+
.orderBy('lastName', 'asc')
|
|
16
|
+
.paginate(1, 10)
|
|
17
|
+
.execute();
|
|
18
|
+
console.log(customers);
|
|
19
|
+
// Example 2: Inserting a new customer
|
|
20
|
+
console.log('\n--- Inserting a Customer ---');
|
|
21
|
+
const newCustomer = await qb
|
|
22
|
+
.insertInto('customers')
|
|
23
|
+
.values({
|
|
24
|
+
firstName: 'John',
|
|
25
|
+
lastName: 'Doe',
|
|
26
|
+
})
|
|
27
|
+
.execute();
|
|
28
|
+
console.log(newCustomer);
|
|
29
|
+
// Example 3: Updating a customer
|
|
30
|
+
console.log('\n--- Updating a Customer ---');
|
|
31
|
+
const updatedCustomer = await qb
|
|
32
|
+
.update('customers')
|
|
33
|
+
.set({ lastName: 'Smith' })
|
|
34
|
+
.where('id', '=', newCustomer[0].id)
|
|
35
|
+
.execute();
|
|
36
|
+
console.log(updatedCustomer);
|
|
37
|
+
// Example 4: Deleting a customer
|
|
38
|
+
console.log('\n--- Deleting a Customer ---');
|
|
39
|
+
const deleteResult = await qb
|
|
40
|
+
.deleteFrom('customers')
|
|
41
|
+
.where('id', '=', newCustomer[0].id)
|
|
42
|
+
.execute();
|
|
43
|
+
console.log(deleteResult);
|
|
44
|
+
// Example 5: Batching queries
|
|
45
|
+
console.log('\n--- Batching Queries ---');
|
|
46
|
+
await qb
|
|
47
|
+
.batch([
|
|
48
|
+
qb.selectFrom('customers').select(['firstName', 'lastName']),
|
|
49
|
+
qb
|
|
50
|
+
.insertInto('customers')
|
|
51
|
+
.values({ firstName: 'Batch', lastName: 'User' }),
|
|
52
|
+
])
|
|
53
|
+
.execute();
|
|
54
|
+
// Example 6: Aggregation query
|
|
55
|
+
console.log('\n--- Aggregation Query ---');
|
|
56
|
+
const aggregates = await qb
|
|
57
|
+
.aggregateFrom('customers')
|
|
58
|
+
.groupBy('firstName', 'asc')
|
|
59
|
+
.groupBy('lastName', 'desc')
|
|
60
|
+
.withAggregates({
|
|
61
|
+
id: ['sum', 'empty'],
|
|
62
|
+
updatedAt: ['daysRange'],
|
|
63
|
+
})
|
|
64
|
+
.execute();
|
|
65
|
+
console.log(JSON.stringify(aggregates, null, 2));
|
|
66
|
+
}
|
|
67
|
+
main().catch(console.error);
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../sample/sample-1/index.ts"],"names":[],"mappings":";;AAAA,iEAAgE;AAGhE,KAAK,UAAU,IAAI;IACjB,MAAM,EAAE,GAAG,IAAA,qCAAkB,EAAiB;QAC5C,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAkB;QACvC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAiB;KACtC,CAAC,CAAC;IAEH,oEAAoE;IACpE,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,MAAM,EAAE;SACvB,UAAU,CAAC,WAAW,CAAC;SACvB,MAAM,CAAC,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;SACjC,KAAK,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,CAAC;SACnC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;SAC1B,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;SACf,OAAO,EAAE,CAAC;IACb,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAEvB,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAC9C,MAAM,WAAW,GAAG,MAAM,EAAE;SACzB,UAAU,CAAC,WAAW,CAAC;SACvB,MAAM,CAAC;QACN,SAAS,EAAE,MAAM;QACjB,QAAQ,EAAE,KAAK;KAChB,CAAC;SACD,OAAO,EAAE,CAAC;IACb,OAAO,CAAC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AAM,CAAC;SAC3B,cAAc,CAAC;QACd,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;QACpB,SAAS,EAAE,CAAC,WAAW,CAAC;KACzB,CAAC;SACD,OAAO,EAAE,CAAC;IACb,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 TaylorDB
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
type IsWithinOperatorValue = 'pastWeek' | 'pastMonth' | 'pastYear' | 'nextWeek' | 'nextMonth' | 'nextYear' | 'daysFromNow' | 'daysAgo' | 'currentWeek' | 'currentMonth' | 'currentYear';
|
|
8
|
+
type DefaultDateFilterValue = ('today' | 'tomorrow' | 'yesterday' | 'oneWeekAgo' | 'oneWeekFromNow' | 'oneMonthAgo' | 'oneMonthFromNow') | ['exactDay' | 'exactTimestamp', string] | ['daysAgo' | 'daysFromNow', number];
|
|
9
|
+
export type Filters = {
|
|
10
|
+
text: {
|
|
11
|
+
'=': string;
|
|
12
|
+
'!=': string;
|
|
13
|
+
caseEqual: string;
|
|
14
|
+
hasAnyOf: string[];
|
|
15
|
+
contains: string;
|
|
16
|
+
startsWith: string;
|
|
17
|
+
endsWith: string;
|
|
18
|
+
doesNotContain: string;
|
|
19
|
+
};
|
|
20
|
+
number: {
|
|
21
|
+
'=': number;
|
|
22
|
+
'!=': number;
|
|
23
|
+
'>': number;
|
|
24
|
+
'>=': number;
|
|
25
|
+
'<': number;
|
|
26
|
+
'<=': number;
|
|
27
|
+
hasAnyOf: number[];
|
|
28
|
+
hasNoneOf: number[];
|
|
29
|
+
};
|
|
30
|
+
checkbox: {
|
|
31
|
+
'=': number;
|
|
32
|
+
};
|
|
33
|
+
link: {
|
|
34
|
+
hasAnyOf: number[];
|
|
35
|
+
hasAllOf: number[];
|
|
36
|
+
isExactly: number[];
|
|
37
|
+
'=': number;
|
|
38
|
+
hasNoneOf: number[];
|
|
39
|
+
};
|
|
40
|
+
date: {
|
|
41
|
+
'=': DefaultDateFilterValue;
|
|
42
|
+
'!=': DefaultDateFilterValue;
|
|
43
|
+
'<': DefaultDateFilterValue;
|
|
44
|
+
'>': DefaultDateFilterValue;
|
|
45
|
+
'<=': DefaultDateFilterValue;
|
|
46
|
+
'>=': DefaultDateFilterValue;
|
|
47
|
+
isWithIn: IsWithinOperatorValue | {
|
|
48
|
+
value: 'daysAgo' | 'daysFromNow';
|
|
49
|
+
date: number;
|
|
50
|
+
};
|
|
51
|
+
isEmpty: boolean;
|
|
52
|
+
isNotEmpty: boolean;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
type Aggregates = {
|
|
56
|
+
number: {
|
|
57
|
+
sum: number;
|
|
58
|
+
average: number;
|
|
59
|
+
median: number;
|
|
60
|
+
min: number | null;
|
|
61
|
+
max: number | null;
|
|
62
|
+
range: number;
|
|
63
|
+
standardDeviation: number;
|
|
64
|
+
histogram: Record<string, number>;
|
|
65
|
+
empty: number;
|
|
66
|
+
filled: number;
|
|
67
|
+
unique: number;
|
|
68
|
+
percentEmpty: number;
|
|
69
|
+
percentFilled: number;
|
|
70
|
+
percentUnique: number;
|
|
71
|
+
};
|
|
72
|
+
date: {
|
|
73
|
+
empty: number;
|
|
74
|
+
filled: number;
|
|
75
|
+
unique: number;
|
|
76
|
+
percentEmpty: number;
|
|
77
|
+
percentFilled: number;
|
|
78
|
+
percentUnique: number;
|
|
79
|
+
min: number | null;
|
|
80
|
+
max: number | null;
|
|
81
|
+
daysRange: number | null;
|
|
82
|
+
monthRange: number | null;
|
|
83
|
+
};
|
|
84
|
+
link: {
|
|
85
|
+
empty: number;
|
|
86
|
+
filled: number;
|
|
87
|
+
percentEmpty: number;
|
|
88
|
+
percentFilled: number;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
export type ColumnType<S, U, I, T> = {
|
|
92
|
+
raw: S;
|
|
93
|
+
insert: I;
|
|
94
|
+
update: U;
|
|
95
|
+
type: T;
|
|
96
|
+
};
|
|
97
|
+
export type DateColumnType = ColumnType<string | undefined, string | undefined, string | undefined, 'date'>;
|
|
98
|
+
export type TextColumnType = ColumnType<string | undefined, string | undefined, string | null, 'text'>;
|
|
99
|
+
export type LinkColumnType<T extends string> = ColumnType<object, number[] | {
|
|
100
|
+
newIds: number[];
|
|
101
|
+
deletedIds: number[];
|
|
102
|
+
} | undefined, number[] | undefined, 'link'> & {
|
|
103
|
+
linkedTo: T;
|
|
104
|
+
};
|
|
105
|
+
export type NumberColumnType = ColumnType<number | undefined, number | undefined, number | undefined, 'number'>;
|
|
106
|
+
export type CheckboxColumnType = ColumnType<boolean | undefined, boolean | undefined, boolean | undefined, 'checkbox'>;
|
|
107
|
+
export type SelectTable = {
|
|
108
|
+
id: NumberColumnType;
|
|
109
|
+
name: TextColumnType;
|
|
110
|
+
color: TextColumnType;
|
|
111
|
+
};
|
|
112
|
+
export type AttachmentTable = {
|
|
113
|
+
id: NumberColumnType;
|
|
114
|
+
name: TextColumnType;
|
|
115
|
+
metadata: TextColumnType;
|
|
116
|
+
size: NumberColumnType;
|
|
117
|
+
fileType: TextColumnType;
|
|
118
|
+
url: TextColumnType;
|
|
119
|
+
};
|
|
120
|
+
export type CollaboratorsTable = {
|
|
121
|
+
id: NumberColumnType;
|
|
122
|
+
name: TextColumnType;
|
|
123
|
+
emailAddress: TextColumnType;
|
|
124
|
+
avatar: TextColumnType;
|
|
125
|
+
};
|
|
126
|
+
export interface Tables {
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
*
|
|
130
|
+
* Internal tables, these tables can not be queried directly.
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
selectTable: SelectTable;
|
|
134
|
+
attachmentTable: AttachmentTable;
|
|
135
|
+
collaboratorsTable: CollaboratorsTable;
|
|
136
|
+
customers: CustomersTable;
|
|
137
|
+
}
|
|
138
|
+
export interface TaylorDatabase {
|
|
139
|
+
filters: Filters;
|
|
140
|
+
aggregates: Aggregates;
|
|
141
|
+
tables: Tables;
|
|
142
|
+
}
|
|
143
|
+
interface CustomersTable {
|
|
144
|
+
id: NumberColumnType;
|
|
145
|
+
createdAt: DateColumnType;
|
|
146
|
+
updatedAt: DateColumnType;
|
|
147
|
+
firstName: TextColumnType;
|
|
148
|
+
lastName: TextColumnType;
|
|
149
|
+
}
|
|
150
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 TaylorDB
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
//# sourceMappingURL=taylorclient.types.js.map
|