@carbonorm/carbonnode 3.8.4 → 3.9.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 +48 -1
- package/dist/api/C6Constants.d.ts +4 -0
- package/dist/api/orm/builders/AggregateBuilder.d.ts +2 -1
- package/dist/api/orm/builders/ConditionBuilder.d.ts +3 -0
- package/dist/api/orm/builders/JoinBuilder.d.ts +8 -0
- package/dist/api/orm/builders/PaginationBuilder.d.ts +1 -1
- package/dist/api/orm/queries/DeleteQueryBuilder.d.ts +2 -0
- package/dist/api/orm/queries/SelectQueryBuilder.d.ts +1 -0
- package/dist/api/orm/queries/UpdateQueryBuilder.d.ts +2 -0
- package/dist/api/orm/queryHelpers.d.ts +5 -0
- package/dist/index.cjs.js +364 -112
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +362 -113
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/fixtures/c6.fixture.ts +39 -0
- package/src/__tests__/fixtures/pu.fixture.ts +72 -0
- package/src/__tests__/sakila-db/C6.js +1 -1
- package/src/__tests__/sakila-db/C6.ts +1 -1
- package/src/__tests__/sqlBuilders.complex.test.ts +199 -1
- package/src/api/C6Constants.ts +2 -0
- package/src/api/orm/builders/AggregateBuilder.ts +39 -2
- package/src/api/orm/builders/ConditionBuilder.ts +66 -4
- package/src/api/orm/builders/JoinBuilder.ts +117 -6
- package/src/api/orm/builders/PaginationBuilder.ts +12 -2
- package/src/api/orm/queries/DeleteQueryBuilder.ts +5 -0
- package/src/api/orm/queries/SelectQueryBuilder.ts +6 -2
- package/src/api/orm/queries/UpdateQueryBuilder.ts +6 -1
- package/src/api/orm/queryHelpers.ts +59 -0
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ CREATE TABLE `carbon_users` (
|
|
|
116
116
|
```
|
|
117
117
|
3) **Profit**
|
|
118
118
|
- C6 will produce 1-1 constants.
|
|
119
|
-
```typescript
|
|
119
|
+
```typescript
|
|
120
120
|
export interface iUsers {
|
|
121
121
|
'user_username'?: string;
|
|
122
122
|
'user_password'?: string;
|
|
@@ -147,6 +147,53 @@ export interface iUsers {
|
|
|
147
147
|
'user_creation_date'?: string | null;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
### Derived table joins
|
|
151
|
+
|
|
152
|
+
The C6 query builder now supports joining derived tables (subselects) so you can project
|
|
153
|
+
single-row lookups and reuse their fields elsewhere in the query. Wrap the derived table
|
|
154
|
+
definition with `derivedTable(...)` to register it, then reference it inside the JOIN tree:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { C6C } from "@carbonorm/carbonnode";
|
|
158
|
+
import { derivedTable, F } from "@carbonorm/carbonnode/api/orm/queryHelpers";
|
|
159
|
+
|
|
160
|
+
const puTarget = derivedTable({
|
|
161
|
+
[C6C.SUBSELECT]: {
|
|
162
|
+
[C6C.SELECT]: [Property_Units.LOCATION],
|
|
163
|
+
[C6C.FROM]: Property_Units.TABLE_NAME,
|
|
164
|
+
[C6C.WHERE]: { [Property_Units.UNIT_ID]: [C6C.EQUAL, unitIdParam] },
|
|
165
|
+
[C6C.LIMIT]: 1,
|
|
166
|
+
},
|
|
167
|
+
[C6C.AS]: 'pu_target',
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const query = {
|
|
171
|
+
[C6C.SELECT]: [
|
|
172
|
+
Property_Units.UNIT_ID,
|
|
173
|
+
Property_Units.LOCATION,
|
|
174
|
+
F(Property_Units.LOCATION, 'pu_target'),
|
|
175
|
+
],
|
|
176
|
+
[C6C.JOIN]: {
|
|
177
|
+
[C6C.INNER]: {
|
|
178
|
+
'parcel_sales ps': { 'ps.parcel_id': [C6C.EQUAL, Property_Units.PARCEL_ID] },
|
|
179
|
+
[puTarget as any]: {},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
[C6C.PAGINATION]: {
|
|
183
|
+
[C6C.ORDER]: {
|
|
184
|
+
[C6C.ST_DISTANCE_SPHERE]: [
|
|
185
|
+
Property_Units.LOCATION,
|
|
186
|
+
F(Property_Units.LOCATION, 'pu_target'),
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Parameters from the subselect are hoisted ahead of the outer query’s bindings and the alias
|
|
194
|
+
(`pu_target` in the example above) is available to `F(...)`, WHERE, ORDER BY, and other
|
|
195
|
+
expressions.
|
|
196
|
+
|
|
150
197
|
interface iDefineUsers {
|
|
151
198
|
'USER_USERNAME': string;
|
|
152
199
|
'USER_PASSWORD': string;
|
|
@@ -50,6 +50,7 @@ export declare const C6Constants: {
|
|
|
50
50
|
INNER: string;
|
|
51
51
|
INTERVAL: string;
|
|
52
52
|
JOIN: string;
|
|
53
|
+
FROM: string;
|
|
53
54
|
LEFT: string;
|
|
54
55
|
LEFT_OUTER: string;
|
|
55
56
|
LESS_THAN: string;
|
|
@@ -81,6 +82,7 @@ export declare const C6Constants: {
|
|
|
81
82
|
SECOND: string;
|
|
82
83
|
SECOND_MICROSECOND: string;
|
|
83
84
|
SELECT: string;
|
|
85
|
+
SUBSELECT: string;
|
|
84
86
|
ST_AREA: string;
|
|
85
87
|
ST_ASBINARY: string;
|
|
86
88
|
ST_ASTEXT: string;
|
|
@@ -206,6 +208,7 @@ export declare const C6C: {
|
|
|
206
208
|
INNER: string;
|
|
207
209
|
INTERVAL: string;
|
|
208
210
|
JOIN: string;
|
|
211
|
+
FROM: string;
|
|
209
212
|
LEFT: string;
|
|
210
213
|
LEFT_OUTER: string;
|
|
211
214
|
LESS_THAN: string;
|
|
@@ -237,6 +240,7 @@ export declare const C6C: {
|
|
|
237
240
|
SECOND: string;
|
|
238
241
|
SECOND_MICROSECOND: string;
|
|
239
242
|
SELECT: string;
|
|
243
|
+
SUBSELECT: string;
|
|
240
244
|
ST_AREA: string;
|
|
241
245
|
ST_ASBINARY: string;
|
|
242
246
|
ST_ASTEXT: string;
|
|
@@ -2,5 +2,6 @@ import { Executor } from "../../executors/Executor";
|
|
|
2
2
|
import { OrmGenerics } from "../../types/ormGenerics";
|
|
3
3
|
export declare abstract class AggregateBuilder<G extends OrmGenerics> extends Executor<G> {
|
|
4
4
|
protected selectAliases: Set<string>;
|
|
5
|
-
|
|
5
|
+
protected assertValidIdentifier(_identifier: string, _context: string): void;
|
|
6
|
+
buildAggregateField(field: string | any[], params?: any[] | Record<string, any>): string;
|
|
6
7
|
}
|
|
@@ -4,7 +4,10 @@ import { SqlBuilderResult } from "../utils/sqlUtils";
|
|
|
4
4
|
import { AggregateBuilder } from "./AggregateBuilder";
|
|
5
5
|
export declare abstract class ConditionBuilder<G extends OrmGenerics> extends AggregateBuilder<G> {
|
|
6
6
|
protected aliasMap: Record<string, string>;
|
|
7
|
+
protected derivedAliases: Set<string>;
|
|
7
8
|
protected initAlias(baseTable: string, joins?: any): void;
|
|
9
|
+
protected registerAlias(alias: string, table: string): void;
|
|
10
|
+
protected assertValidIdentifier(identifier: string, context: string): void;
|
|
8
11
|
protected isColumnRef(ref: string): boolean;
|
|
9
12
|
abstract build(table: string): SqlBuilderResult;
|
|
10
13
|
execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { OrmGenerics } from "../../types/ormGenerics";
|
|
2
2
|
import { ConditionBuilder } from "./ConditionBuilder";
|
|
3
3
|
export declare abstract class JoinBuilder<G extends OrmGenerics> extends ConditionBuilder<G> {
|
|
4
|
+
protected createSelectBuilder(_request: any): {
|
|
5
|
+
build(table: string, isSubSelect: boolean): {
|
|
6
|
+
sql: string;
|
|
7
|
+
params: any[] | Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
4
10
|
buildJoinClauses(joinArgs: any, params: any[] | Record<string, any>): string;
|
|
11
|
+
protected integrateSubSelectParams(subSql: string, subParams: any[] | Record<string, any>, target: any[] | Record<string, any>): string;
|
|
12
|
+
protected buildScalarSubSelect(subRequest: any, params: any[] | Record<string, any>): string;
|
|
5
13
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { OrmGenerics } from "../../types/ormGenerics";
|
|
2
2
|
import { SqlBuilderResult } from "../utils/sqlUtils";
|
|
3
3
|
import { JoinBuilder } from "../builders/JoinBuilder";
|
|
4
|
+
import { SelectQueryBuilder } from "./SelectQueryBuilder";
|
|
4
5
|
export declare class DeleteQueryBuilder<G extends OrmGenerics> extends JoinBuilder<G> {
|
|
6
|
+
protected createSelectBuilder(request: any): SelectQueryBuilder<OrmGenerics>;
|
|
5
7
|
build(table: string): SqlBuilderResult;
|
|
6
8
|
}
|
|
@@ -2,5 +2,6 @@ import { OrmGenerics } from "../../types/ormGenerics";
|
|
|
2
2
|
import { PaginationBuilder } from "../builders/PaginationBuilder";
|
|
3
3
|
import { SqlBuilderResult } from "../utils/sqlUtils";
|
|
4
4
|
export declare class SelectQueryBuilder<G extends OrmGenerics> extends PaginationBuilder<G> {
|
|
5
|
+
protected createSelectBuilder(request: any): SelectQueryBuilder<OrmGenerics>;
|
|
5
6
|
build(table: string, isSubSelect?: boolean): SqlBuilderResult;
|
|
6
7
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { OrmGenerics } from "../../types/ormGenerics";
|
|
2
2
|
import { PaginationBuilder } from '../builders/PaginationBuilder';
|
|
3
3
|
import { SqlBuilderResult } from "../utils/sqlUtils";
|
|
4
|
+
import { SelectQueryBuilder } from "./SelectQueryBuilder";
|
|
4
5
|
export declare class UpdateQueryBuilder<G extends OrmGenerics> extends PaginationBuilder<G> {
|
|
6
|
+
protected createSelectBuilder(request: any): SelectQueryBuilder<OrmGenerics>;
|
|
5
7
|
private trimTablePrefix;
|
|
6
8
|
build(table: string): SqlBuilderResult;
|
|
7
9
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
type DerivedTableSpec = Record<string, any> & {};
|
|
2
|
+
export declare const isDerivedTableKey: (key: string) => boolean;
|
|
3
|
+
export declare const resolveDerivedTable: (key: string) => DerivedTableSpec | undefined;
|
|
4
|
+
export declare const derivedTable: <T extends DerivedTableSpec>(spec: T) => T;
|
|
1
5
|
export declare const A: (tableName: string, alias: string) => string;
|
|
2
6
|
export declare const F: (qualifiedCol: string, alias: string) => string;
|
|
3
7
|
export declare const fieldEq: (leftCol: string, rightCol: string, leftAlias: string, rightAlias: string) => Record<string, string>;
|
|
4
8
|
export declare const distSphere: (fromCol: string, toCol: string, fromAlias: string, toAlias: string) => any[];
|
|
5
9
|
export declare const bbox: (minLng: number, minLat: number, maxLng: number, maxLat: number) => any[];
|
|
6
10
|
export declare const stContains: (envelope: string, shape: string) => any[];
|
|
11
|
+
export {};
|