@@ -12,6 +12,7 @@ import { CasingCache } from 'drizzle-orm/casing';
12
12
import {
13
13
getTableConfig ,
14
14
SQLiteBoolean ,
15
+ SQLiteCustomColumn ,
15
16
SQLiteInteger ,
16
17
SQLiteReal ,
17
18
SQLiteText ,
@@ -44,24 +45,7 @@ export function toPowerSyncTable<T extends SQLiteTableWithColumns<any>>(
44
45
continue ;
45
46
}
46
47
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 ) ;
65
49
}
66
50
const indexes : IndexShorthand = { } ;
67
51
@@ -82,6 +66,34 @@ export function toPowerSyncTable<T extends SQLiteTableWithColumns<any>>(
82
66
return new Table ( columns , { ...options , indexes } ) as Table < Expand < ExtractPowerSyncColumns < T > > > ;
83
67
}
84
68
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
+
85
97
export type DrizzleTablePowerSyncOptions = Omit < TableV2Options , 'indexes' > ;
86
98
87
99
export type DrizzleTableWithPowerSyncOptions = {
0 commit comments