Skip to content

Commit af08596

Browse files
use tableV2
1 parent 3fd7031 commit af08596

File tree

8 files changed

+38
-58
lines changed

8 files changed

+38
-58
lines changed

demos/django-react-native-todolist/app/views/todos/edit/[id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { View, Text, ActivityIndicator } from 'react-native';
22
import { useLocalSearchParams } from 'expo-router';
33
import { useQuery } from '@powersync/react';
4-
import { LIST_TABLE, ListRecord } from '../../../../library/models/ListModel';
54
import { ListTodosWidget } from '../../../../library/widgets/ListTodosWidget';
5+
import { LIST_TABLE, ListRecord } from '../../../../library/powersync/AppSchema';
66

77
const TodoView = () => {
88
const params = useLocalSearchParams<{ id: string }>();

demos/django-react-native-todolist/app/views/todos/lists.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import prompt from 'react-native-prompt-android';
66
import { useSystem } from '../../../library/stores/system';
77
import { ListItemWidget } from '../../../library/widgets/ListItemWidget';
88
import { Stack } from 'expo-router';
9-
import { LIST_TABLE } from '../../../library/models/ListModel';
109
import { useQuery } from '@powersync/react';
10+
import { LIST_TABLE } from '../../../library/powersync/AppSchema';
1111

1212
const App = () => {
1313
const system = useSystem();

demos/django-react-native-todolist/library/models/ListModel.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

demos/django-react-native-todolist/library/models/TodoModel.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
import { Column, ColumnType, Index, IndexedColumn, Schema, Table } from '@powersync/react-native';
1+
import { column, Schema, TableV2 } from '@powersync/react-native';
22

3-
export const AppSchema = new Schema([
4-
new Table({
5-
name: 'todos',
6-
columns: [
7-
new Column({ name: 'list_id', type: ColumnType.TEXT }),
8-
new Column({ name: 'photo_id', type: ColumnType.TEXT }),
9-
new Column({ name: 'created_at', type: ColumnType.TEXT }),
10-
new Column({ name: 'completed_at', type: ColumnType.TEXT }),
11-
new Column({ name: 'description', type: ColumnType.TEXT }),
12-
new Column({ name: 'completed', type: ColumnType.INTEGER }),
13-
new Column({ name: 'created_by', type: ColumnType.TEXT }),
14-
new Column({ name: 'completed_by', type: ColumnType.TEXT })
15-
],
16-
indexes: [
17-
new Index({
18-
name: 'list',
19-
columns: [new IndexedColumn({ name: 'list_id' })]
20-
})
21-
]
22-
}),
23-
new Table({
24-
name: 'lists',
25-
columns: [
26-
new Column({ name: 'created_at', type: ColumnType.TEXT }),
27-
new Column({ name: 'name', type: ColumnType.TEXT }),
28-
new Column({ name: 'owner_id', type: ColumnType.TEXT })
29-
]
30-
})
31-
]);
3+
export const LIST_TABLE = 'lists';
4+
export const TODO_TABLE = 'todos';
5+
6+
const todos = new TableV2(
7+
{
8+
list_id: column.text,
9+
created_at: column.text,
10+
completed_at: column.text,
11+
description: column.text,
12+
created_by: column.text,
13+
completed_by: column.text,
14+
completed: column.integer,
15+
photo_id: column.text
16+
},
17+
{ indexes: { list: ['list_id'] } }
18+
);
19+
20+
const lists = new TableV2({
21+
created_at: column.text,
22+
name: column.text,
23+
owner_id: column.text
24+
});
25+
26+
export const AppSchema = new Schema({
27+
lists,
28+
todos
29+
});
30+
31+
export type Database = (typeof AppSchema)['types'];
32+
export type TodoRecord = Database['todos'];
33+
export type ListRecord = Database['lists'];

demos/django-react-native-todolist/library/widgets/ListItemWidget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
2-
import { LIST_TABLE, ListRecord } from '../models/ListModel';
32
import { Alert, View } from 'react-native';
43
import { ListItem, Icon } from 'react-native-elements';
54
import { router } from 'expo-router';
65
import { usePowerSync } from '@powersync/react';
6+
import { LIST_TABLE, ListRecord } from '../powersync/AppSchema';
77

88
export const ListItemWidget: React.FC<{
99
record: ListRecord;

demos/django-react-native-todolist/library/widgets/ListTodosWidget.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from 'react';
2-
import { ListRecord } from '../models/ListModel';
32
import { ScrollView, StatusBar, View } from 'react-native';
43
import { usePowerSync, useQuery } from '@powersync/react';
54
import { Stack } from 'expo-router';
65
import { FAB } from 'react-native-elements';
76
import { TodoItemWidget } from './TodoItemWidget';
8-
import { TODO_TABLE, TodoRecord } from '../models/TodoModel';
97
import prompt from 'react-native-prompt-android';
8+
import { ListRecord, TODO_TABLE, TodoRecord } from '../powersync/AppSchema';
109

1110
export const ListTodosWidget: React.FC<{
1211
record: ListRecord;
@@ -19,7 +18,7 @@ export const ListTodosWidget: React.FC<{
1918
<View style={{ flexGrow: 1 }}>
2019
<Stack.Screen
2120
options={{
22-
title: record.name
21+
title: record.name!
2322
}}
2423
/>
2524
<FAB

demos/django-react-native-todolist/library/widgets/TodoItemWidget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { ActivityIndicator, Alert, View } from 'react-native';
33
import { ListItem, Icon } from 'react-native-elements';
4-
import { TODO_TABLE, TodoRecord } from '../models/TodoModel';
54
import { usePowerSync } from '@powersync/react';
5+
import { TODO_TABLE, TodoRecord } from '../powersync/AppSchema';
66

77
export const TodoItemWidget: React.FC<{
88
record: TodoRecord;

0 commit comments

Comments
 (0)