@@ -48,7 +48,7 @@ function prepareRowTableSchema(data: TTableDescription = {}): SchemaData[] {
4848 const preparedColumns = Columns ?. map ( ( column ) => {
4949 const { Id, Name, NotNull, Type, Family, DefaultFromSequence, DefaultFromLiteral} = column ;
5050
51- const isKeyColumn = Boolean ( KeyColumnIds ?. find ( ( keyColumnId ) => keyColumnId === Id ) ) ;
51+ const keyColumnIndex = KeyColumnIds ?. findIndex ( ( keyColumnId ) => keyColumnId === Id ) ?? - 1 ;
5252
5353 const familyName = Family ? families [ Family ] . Name : undefined ;
5454 const prefferedPoolKind = Family
@@ -59,7 +59,7 @@ function prepareRowTableSchema(data: TTableDescription = {}): SchemaData[] {
5959 return {
6060 id : Id ,
6161 name : Name ,
62- isKeyColumn ,
62+ keyColumnIndex ,
6363 type : Type ,
6464 notNull : NotNull ,
6565 autoIncrement : Boolean ( DefaultFromSequence ) ,
@@ -69,8 +69,8 @@ function prepareRowTableSchema(data: TTableDescription = {}): SchemaData[] {
6969 columnCodec,
7070 } ;
7171 } ) ;
72- const keyColumns = preparedColumns ?. filter ( ( column ) => column . isKeyColumn ) || [ ] ;
73- const otherColumns = preparedColumns ?. filter ( ( column ) => ! column . isKeyColumn ) || [ ] ;
72+ const keyColumns = preparedColumns ?. filter ( ( column ) => column . keyColumnIndex !== - 1 ) || [ ] ;
73+ const otherColumns = preparedColumns ?. filter ( ( column ) => column . keyColumnIndex === - 1 ) || [ ] ;
7474
7575 return [ ...keyColumns , ...otherColumns ] ;
7676}
@@ -92,32 +92,31 @@ function prepareExternalTableSchema(data: TExternalTableDescription = {}): Schem
9292
9393function prepareColumnTableSchema ( data : TColumnTableDescription = { } ) : SchemaData [ ] {
9494 const { Schema = { } , Sharding = { } } = data ;
95- const { Columns, KeyColumnNames } = Schema ;
95+ const { Columns, KeyColumnIds } = Schema ;
9696 const { HashSharding = { } } = Sharding ;
9797 const { Columns : HashColumns = [ ] } = HashSharding ;
9898
9999 const preparedColumns = Columns ?. map ( ( column ) => {
100100 const { Id, Name, Type, NotNull} = column ;
101101
102- const isKeyColumn = Boolean (
103- KeyColumnNames ?. find ( ( keyColumnName ) => keyColumnName === Name ) ,
104- ) ;
102+ const keyColumnIndex = KeyColumnIds ?. findIndex ( ( keyColumnId ) => keyColumnId === Id ) ?? - 1 ;
103+
105104 const isPartitioningKeyColumn = Boolean (
106105 HashColumns ?. find ( ( hashColumnName ) => hashColumnName === Name ) ,
107106 ) ;
108107
109108 return {
110109 id : Id ,
111110 name : Name ,
112- isKeyColumn ,
111+ keyColumnIndex ,
113112 isPartitioningKeyColumn,
114113 type : Type ,
115114 notNull : NotNull ,
116115 } ;
117116 } ) ;
118117
119- const keyColumns = preparedColumns ?. filter ( ( column ) => column . isKeyColumn ) || [ ] ;
120- const otherColumns = preparedColumns ?. filter ( ( column ) => ! column . isKeyColumn ) || [ ] ;
118+ const keyColumns = preparedColumns ?. filter ( ( column ) => column . keyColumnIndex !== - 1 ) || [ ] ;
119+ const otherColumns = preparedColumns ?. filter ( ( column ) => column . keyColumnIndex === - 1 ) || [ ] ;
121120
122121 return [ ...keyColumns , ...otherColumns ] ;
123122}
0 commit comments