Skip to content

Commit 396b1dd

Browse files
fix
1 parent b5aab78 commit 396b1dd

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

packages/common/src/db/schema/Schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RowType, Table } from './Table.js';
22

33
type SchemaType = Record<string, Table<any>>;
44

5-
type SchemaTableType<S extends SchemaType> = {
5+
export type SchemaTableType<S extends SchemaType> = {
66
[K in keyof S]: RowType<S[K]>;
77
};
88

packages/drizzle-driver/src/utils/schema.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { column, IndexShorthand, Schema, Table, type BaseColumnType, type TableV2Options } from '@powersync/common';
1+
import {
2+
column,
3+
IndexShorthand,
4+
Schema,
5+
SchemaTableType,
6+
Table,
7+
type BaseColumnType,
8+
type TableV2Options
9+
} from '@powersync/common';
210
import { InferSelectModel, isTable, Relations } from 'drizzle-orm';
311
import {
412
getTableConfig,
@@ -143,8 +151,8 @@ export class DrizzleAppSchema<
143151
constructor(drizzleSchema: T) {
144152
super(toPowerSyncTables(drizzleSchema));
145153
// This is just used for typing
146-
this.types = {} as Expand<TablesFromSchemaEntries<T>>;
154+
this.types = {} as SchemaTableType<Expand<TablesFromSchemaEntries<T>>>;
147155
}
148156

149-
types: Expand<TablesFromSchemaEntries<T>>;
157+
types: SchemaTableType<Expand<TablesFromSchemaEntries<T>>>;
150158
}

packages/drizzle-driver/tests/sqlite/schema.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ describe('toPowerSyncTable', () => {
2929
expect(convertedList).toEqual(expectedLists);
3030
});
3131

32+
it('basic conversion class', () => {
33+
const lists = sqliteTable('lists', {
34+
id: text('id').primaryKey(),
35+
name: text('name').notNull(),
36+
owner_id: text('owner_id'),
37+
counter: integer('counter'),
38+
completion: real('completion')
39+
});
40+
const convertedList = new DrizzleAppSchema({ lists });
41+
42+
const a: (typeof convertedList)['types']['lists'] = {
43+
name: 'd',
44+
completion: 1,
45+
counter: 0,
46+
id: '1',
47+
owner_id: null
48+
};
49+
});
50+
3251
it('classed based types', () => {
3352
const lists = sqliteTable('lists', {
3453
id: text('id').primaryKey(),

0 commit comments

Comments
 (0)