Skip to content

Commit 9b8ebff

Browse files
committed
initial v.1.0
1 parent e955682 commit 9b8ebff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+957
-329
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "database-builder",
3-
"version": "0.0.34",
3+
"version": "0.0.35",
44
"description": "Library to assist in creating and maintaining SQL commands.",
55
"main": "./src/index.js",
66
"types": "./src/index.d.ts",

src/core/column.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export interface Column {
55
value: ValueType;
66
name: string;
77
type: FieldType;
8+
isKeyColumn?: boolean;
9+
isAutoIncrement?: boolean;
810
}

src/core/columns-base-builder.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MetadataTable } from "./../metadata-table";
1+
import { MetadataTable } from "../metadata-table";
22
import { ExpressionOrColumn, Utils, ValueTypeToParse } from "./utils";
33
import { MapperTable } from "../mapper-table";
44
import { Column } from "./column";
@@ -25,48 +25,79 @@ export abstract class ColumnsBaseBuilder<
2525
this.setAllColumns(this.metadata.mapperTable, this.modelToSave);
2626
}
2727

28-
public setColumn(column: string, type: FieldType): TThis {
28+
public setColumn(
29+
column: string,
30+
type: FieldType,
31+
isKeyColumn: boolean,
32+
isAutoIncrement: boolean
33+
): TThis {
2934
this.columns.push({
3035
name: column,
3136
type,
37+
isKeyColumn,
38+
isAutoIncrement
3239
} as TColumn);
3340
return this.getInstance();
3441
}
3542

36-
public set<TReturn extends ValueTypeToParse>(expression: ExpressionOrColumn<TReturn, T>): TThis {
43+
public set<TReturn extends ValueTypeToParse>(
44+
expression: ExpressionOrColumn<TReturn, T>,
45+
isKeyColumn: boolean,
46+
isAutoIncrement: boolean
47+
): TThis {
3748
return this.setColumn(
3849
Utils.getColumn(expression),
3950
Utils.getType(this.metadata.instance, expression),
51+
isKeyColumn,
52+
isAutoIncrement
4053
);
4154
}
4255

4356
public compile(): ColumnsCompiled {
4457
const result: ColumnsCompiled = {
4558
columns: [],
59+
keyColumns: [],
4660
params: [],
4761
};
4862
for (const key in this.columns) {
4963
if (this.columns.hasOwnProperty(key)) {
5064
const column = this.columns[key];
65+
if (column.isKeyColumn) {
66+
result.keyColumns.push(column.name);
67+
}
5168
result.columns.push(this.columnFormat(column));
5269
}
5370
}
5471
return result;
5572
}
5673

74+
protected isCompositeKey(): boolean {
75+
return this.metadata.mapperTable.columns.filter(x => x.isKeyColumn === true).length > 1;
76+
}
77+
5778
protected abstract columnFormat(column: TColumn): string;
5879

5980
protected abstract getInstance(): TThis;
6081

61-
protected abstract setColumnValue(column: string, value: ValueTypeToParse, fieldType: FieldType): TThis;
82+
protected abstract setColumnValue(
83+
column: string,
84+
value: ValueTypeToParse,
85+
fieldType: FieldType,
86+
isKeyColumn: boolean,
87+
isAutoIncrement: boolean
88+
): TThis;
6289

6390
private setAllColumns(mapper: MapperTable, modelWithValue: T): void {
6491
for (const key in mapper.columns) {
6592
if (mapper.columns.hasOwnProperty(key)) {
6693
const column = mapper.columns[key];
67-
this.setColumnValue(column.column,
94+
this.setColumnValue(
95+
column.column,
6896
Utils.getValue(modelWithValue, column.fieldReference),
69-
column.fieldType);
97+
column.fieldType,
98+
column.isKeyColumn,
99+
column.isAutoIncrement
100+
);
70101
}
71102
}
72103
}

src/core/columns-base-compiled.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export interface ColumnsBaseCompiled {
22
columns: string[];
3+
keyColumns: string[];
34
}

src/core/columns-values-builder.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MetadataTable } from "./../metadata-table";
1+
import { MetadataTable } from "../metadata-table";
22
import { ExpressionOrColumn, Utils, ValueTypeToParse } from "./utils";
33
import { ColumnsBaseBuilder } from "./columns-base-builder";
44
import { Column } from "./column";
@@ -16,38 +16,62 @@ export abstract class ColumnsValuesBuilder<
1616
super(metadata, modelToSave);
1717
}
1818

19-
public setColumnValue(column: string, value: ValueTypeToParse, fieldType: FieldType): TThis {
19+
public setColumnValue(
20+
column: string,
21+
value: ValueTypeToParse,
22+
fieldType: FieldType,
23+
isKeyColumn: boolean,
24+
isAutoIncrement: boolean): TThis {
2025
this.columns.push({
2126
name: column,
2227
type: fieldType,
2328
value: Utils.getValueType(value, fieldType),
29+
isKeyColumn,
30+
isAutoIncrement
2431
});
2532
return this.getInstance();
2633
}
2734

28-
public setValue<TReturn extends ValueTypeToParse>(expression: ExpressionOrColumn<TReturn, T>, value: TReturn): TThis {
35+
public setValue<TReturn extends ValueTypeToParse>(
36+
expression: ExpressionOrColumn<TReturn, T>,
37+
value: TReturn,
38+
isKeyColumn: boolean,
39+
isAutoIncrement: boolean
40+
): TThis {
2941
return this.setColumnValue(
3042
Utils.getColumn(expression),
3143
value,
3244
Utils.getType(value),
45+
isKeyColumn,
46+
isAutoIncrement
3347
);
3448
}
3549

36-
public set<TReturn extends ValueTypeToParse>(expression: ExpressionOrColumn<TReturn, T>): TThis {
50+
public set<TReturn extends ValueTypeToParse>(
51+
expression: ExpressionOrColumn<TReturn, T>,
52+
isKeyColumn: boolean,
53+
isAutoIncrement: boolean
54+
): TThis {
3755
return this.setValue(
3856
expression,
3957
this.getValueByExpression(expression),
58+
isKeyColumn,
59+
isAutoIncrement
4060
);
4161
}
4262

4363
public compile(): ColumnsCompiled {
4464
const result: ColumnsCompiled = {
4565
columns: [],
66+
keyColumns: [],
4667
params: [],
4768
};
4869
this.columns.forEach((column) => {
49-
result.columns.push(this.columnFormat(column));
50-
result.params.push(column.value);
70+
const columnName = this.columnFormat(column);
71+
if (columnName !== void 0) {
72+
result.columns.push(columnName);
73+
result.params.push(column.value);
74+
}
5175
});
5276
return result;
5377
}

src/core/executable-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DatabaseBase, DatabaseObject, DatabaseResult, DatabaseTransaction } from "./../definitions/database-definition";
1+
import { DatabaseBase, DatabaseObject, DatabaseResult, DatabaseTransaction } from "../definitions/database-definition";
22
import { QueryCompiled } from "./query-compiled";
33

44
export class ExecutableBuilder {

src/core/lambda-metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Condition } from "./../crud/enums/condition";
1+
import { Condition } from "../crud/enums/condition";
22

33
export interface LambdaMetadata {
44
left: string;

src/core/projections-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Projection } from "./../crud/enums/projection";
1+
import { Projection } from "../crud/enums/projection";
22
import { ExpressionOrColumn, TypeProjection, Utils } from "./utils";
33
import { ProjectionCompiled } from "..";
44
import { ProjectionsUtils } from "./projections-utils";

src/core/projections-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Projection } from "./../crud/enums/projection";
1+
import { Projection } from "../crud/enums/projection";
22
import { ExpressionOrColumn, Utils } from "./utils";
33
import { ProjectionCompiled } from "..";
44

src/core/row-result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MapperTable } from "./../mapper-table";
1+
import { MapperTable } from "../mapper-table";
22
import { ExpressionOrColumn, Utils } from "./utils";
33
import { DatabaseHelper } from "..";
44
import { FieldType } from "./enums/field-type";

0 commit comments

Comments
 (0)