@@ -12,6 +12,7 @@ import { CasingCache } from 'drizzle-orm/casing';
1212import {
1313 getTableConfig ,
1414 SQLiteBoolean ,
15+ SQLiteCustomColumn ,
1516 SQLiteInteger ,
1617 SQLiteReal ,
1718 SQLiteText ,
@@ -44,24 +45,7 @@ export function toPowerSyncTable<T extends SQLiteTableWithColumns<any>>(
4445 continue ;
4546 }
4647
47- let mappedType : BaseColumnType < number | string | null > ;
48- switch ( drizzleColumn . columnType ) {
49- case SQLiteText [ entityKind ] :
50- case SQLiteTextJson [ entityKind ] :
51- mappedType = column . text ;
52- break ;
53- case SQLiteInteger [ entityKind ] :
54- case SQLiteTimestamp [ entityKind ] :
55- case SQLiteBoolean [ entityKind ] :
56- mappedType = column . integer ;
57- break ;
58- case SQLiteReal [ entityKind ] :
59- mappedType = column . real ;
60- break ;
61- default :
62- throw new Error ( `Unsupported column type: ${ drizzleColumn . columnType } ` ) ;
63- }
64- columns [ name ] = mappedType ;
48+ columns [ name ] = mapDrizzleColumnToType ( drizzleColumn ) ;
6549 }
6650 const indexes : IndexShorthand = { } ;
6751
@@ -82,6 +66,34 @@ export function toPowerSyncTable<T extends SQLiteTableWithColumns<any>>(
8266 return new Table ( columns , { ...options , indexes } ) as Table < Expand < ExtractPowerSyncColumns < T > > > ;
8367}
8468
69+ function mapDrizzleColumnToType ( drizzleColumn : SQLiteColumn < any , object > ) : BaseColumnType < number | string | null > {
70+ switch ( drizzleColumn . columnType ) {
71+ case SQLiteText [ entityKind ] :
72+ case SQLiteTextJson [ entityKind ] :
73+ return column . text ;
74+ case SQLiteInteger [ entityKind ] :
75+ case SQLiteTimestamp [ entityKind ] :
76+ case SQLiteBoolean [ entityKind ] :
77+ return column . integer ;
78+ case SQLiteReal [ entityKind ] :
79+ return column . real ;
80+ case SQLiteCustomColumn [ entityKind ] :
81+ const sqlName = ( drizzleColumn as SQLiteCustomColumn < any > ) . getSQLType ( ) ;
82+ switch ( sqlName ) {
83+ case 'text' :
84+ return column . text ;
85+ case 'integer' :
86+ return column . integer ;
87+ case 'real' :
88+ return column . real ;
89+ default :
90+ throw new Error ( `Unsupported custom column type: ${ drizzleColumn . columnType } : ${ sqlName } ` ) ;
91+ }
92+ default :
93+ throw new Error ( `Unsupported column type: ${ drizzleColumn . columnType } ` ) ;
94+ }
95+ }
96+
8597export type DrizzleTablePowerSyncOptions = Omit < TableV2Options , 'indexes' > ;
8698
8799export type DrizzleTableWithPowerSyncOptions = {
0 commit comments