Skip to content

Commit

Permalink
example-tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriztiaan committed Jan 15, 2025
1 parent 2289dfb commit 14b2de8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
20 changes: 12 additions & 8 deletions demos/react-native-supabase-todolist/app/views/todos/lists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LIST_TABLE, TODO_TABLE, ListRecord } from '../../../library/powersync/A
import { useSystem } from '../../../library/powersync/system';
import { useQuery, useStatus } from '@powersync/react-native';
import { ListItemWidget } from '../../../library/widgets/ListItemWidget';
import { sql } from 'kysely';

const description = (total: number, completed: number = 0) => {
return `${total - completed} pending, ${completed} completed`;
Expand All @@ -31,15 +32,18 @@ const ListsViewWidget: React.FC = () => {
const createNewList = async (name: string) => {
const userID = await system.supabaseConnector.userId();

const res = await system.powersync.execute(
`INSERT INTO ${LIST_TABLE} (id, created_at, name, owner_id) VALUES (uuid(), datetime(), ?, ?) RETURNING *`,
[name, userID]
);
const res =
await system.kyselyDb.insertInto('lists') // or LIST_TABLE if it's a variable
.values({
id: sql`uuid()`,
created_at: sql`datetime()`,
name,
owner_id: userID,
})
// If you want all columns returned, use returningAll()
.returningAll()
.execute();

const resultRecord = res.rows?.item(0);
if (!resultRecord) {
throw new Error('Could not create list');
}
};

const deleteList = async (id: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import Logger from 'js-logger';
import { KVStorage } from '../storage/KVStorage';
import { AppConfig } from '../supabase/AppConfig';
import { SupabaseConnector } from '../supabase/SupabaseConnector';
import { AppSchema } from './AppSchema';
import { AppSchema, Database } from './AppSchema';
import { PhotoAttachmentQueue } from './PhotoAttachmentQueue';
import { configureFts } from '../fts/fts_setup';
import { PowerSyncKyselyDatabase, wrapPowerSyncWithKysely } from '@powersync/kysely-driver';

Logger.useDefaults();

Expand All @@ -21,6 +22,7 @@ export class System {
supabaseConnector: SupabaseConnector;
powersync: PowerSyncDatabase;
attachmentQueue: PhotoAttachmentQueue | undefined = undefined;
kyselyDb: PowerSyncKyselyDatabase<Database>;

constructor() {
this.kvStorage = new KVStorage();
Expand All @@ -32,6 +34,9 @@ export class System {
dbFilename: 'sqlite.db'
}
});

this.kyselyDb = wrapPowerSyncWithKysely<Database>(this.powersync);

/**
* The snippet below uses OP-SQLite as the default database adapter.
* You will have to uninstall `@journeyapps/react-native-quick-sqlite` and
Expand Down

0 comments on commit 14b2de8

Please sign in to comment.