1- import { MetadataTable } from "./. ./metadata-table" ;
1+ import { MetadataTable } from "../metadata-table" ;
22import { ExpressionOrColumn , Utils , ValueTypeToParse } from "./utils" ;
33import { MapperTable } from "../mapper-table" ;
44import { 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 }
0 commit comments