Skip to content

Commit 94cb550

Browse files
committed
setup test app
1 parent 9449db5 commit 94cb550

File tree

91 files changed

+22441
-22896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+22441
-22896
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Replace the credentials below with your Supabase, PowerSync and Expo project details.
2-
EXPO_PUBLIC_SUPABASE_URL=https://foo.supabase.co
3-
EXPO_PUBLIC_SUPABASE_ANON_KEY=foo
2+
EXPO_PUBLIC_SUPABASE_URL=https://biibqyczmuyrnwvchjff.supabase.co
3+
EXPO_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJpaWJxeWN6bXV5cm53dmNoamZmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Mjk3NzkzMDYsImV4cCI6MjA0NTM1NTMwNn0.k6fAihkyri-RiDETk3iRJAout3dcda01qr4pREMrH1g
44
EXPO_PUBLIC_SUPABASE_BUCKET= # Optional. Only required when syncing attachments and using Supabase Storage. See packages/powersync-attachments.
5-
EXPO_PUBLIC_POWERSYNC_URL=https://foo.powersync.journeyapps.com
6-
EXPO_PUBLIC_EAS_PROJECT_ID=foo # Optional. Only required when using EAS.
5+
EXPO_PUBLIC_POWERSYNC_URL=https://65e45c66af1654843aebe529.powersync.journeyapps.com
6+
EXPO_PUBLIC_EAS_PROJECT_ID= # Optional. Only required when using EAS.

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

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,34 @@ import { FAB, Text } from '@rneui/themed';
55
import prompt from 'react-native-prompt-android';
66

77
import { router, Stack } from 'expo-router';
8-
import { LIST_TABLE, TODO_TABLE, ListRecord } from '../../../library/powersync/AppSchema';
8+
import { LIST_TABLE, TODO_TABLE, ListRecord, TodoRecord } from '../../../library/powersync/AppSchema';
99
import { useSystem } from '../../../library/powersync/system';
10-
import { useQuery, useStatus } from '@powersync/react-native';
10+
import { PowerSyncDatabase, useQuery, useStatus } from '@powersync/react-native';
1111
import { ListItemWidget } from '../../../library/widgets/ListItemWidget';
1212

1313
const description = (total: number, completed: number = 0) => {
1414
return `${total - completed} pending, ${completed} completed`;
1515
};
1616

17+
const createSlowQuery = (id: number) => {
18+
return async (db: PowerSyncDatabase) => {
19+
console.log(`Query ${id} started on connection ${db.database.name}`);
20+
21+
// Real query with artificial delay using SQLite's sleep function
22+
const result = await db.get(`
23+
WITH RECURSIVE r(i) AS (
24+
SELECT 1
25+
UNION ALL
26+
SELECT i+1 FROM r WHERE i<1000
27+
)
28+
SELECT (SELECT sqlite_sleep(2)), COUNT(*) FROM r;
29+
`);
30+
31+
console.log(`Query ${id} completed on connection ${db.database.name}`);
32+
return result;
33+
};
34+
};
35+
1736
const ListsViewWidget: React.FC = () => {
1837
const system = useSystem();
1938
const status = useStatus();
@@ -31,15 +50,82 @@ const ListsViewWidget: React.FC = () => {
3150
const createNewList = async (name: string) => {
3251
const { userID } = await system.supabaseConnector.fetchCredentials();
3352

34-
const res = await system.powersync.execute(
35-
`INSERT INTO ${LIST_TABLE} (id, created_at, name, owner_id) VALUES (uuid(), datetime(), ?, ?) RETURNING *`,
36-
[name, userID]
37-
);
53+
const queries = [
54+
() => system.powersync.get<ListRecord>(`SELECT l.* FROM lists l WHERE l.name = ?`, ['Shopping list']),
55+
() => system.powersync.get<ListRecord>(`SELECT l.* FROM lists l WHERE l.name = ?`, ['Test']),
56+
() => system.powersync.get<ListRecord>(`SELECT l.* FROM lists l WHERE l.name = ?`, ['Test 2'])
57+
// const lists3 = await system.powersync.get<ListRecord>(
58+
// `SELECT l.*, (SELECT sqlite_sleep(2)) FROM lists l WHERE l.name = ?`,
59+
// ['Test 3']
60+
// );
61+
// const lists4 = await system.powersync.get<ListRecord>(
62+
// `SELECT l.*, (SELECT sqlite_sleep(2)) FROM lists l WHERE l.name = ?`,
63+
// ['Test 4']
64+
// );
65+
];
66+
const startTime = Date.now();
67+
const promises = [];
68+
for (let i = 0; i < 10; i++) {
69+
// Run each query type 3 times
70+
// for (const query of queries) {
71+
// const promise = query()
72+
// .then((result) => {
73+
// const elapsed = Date.now() - startTime;
74+
// console.log(`[+${elapsed.toFixed(5)}ms] Query ${i})} completed `);
75+
// console.log(`Query ${i} completed with result:`, result);
76+
// })
77+
// .catch((error) => {
78+
// const elapsed = Date.now() - startTime;
79+
// console.log(`[+${elapsed.toFixed(5)}ms] Query ${i})} completed `);
80+
// console.error(`Query ${i} error:`, error);
81+
// });
82+
83+
// promises.push(promise);
84+
// }
85+
// }
86+
const promise = system.powersync
87+
.get<ListRecord>(
88+
`
89+
WITH RECURSIVE r(i) AS (
90+
SELECT 1
91+
UNION ALL
92+
SELECT i+1 FROM r
93+
WHERE i<2000000
94+
),
95+
-- Do some heavy computation to create delay
96+
computed AS (
97+
SELECT COUNT(*) as cnt,
98+
SUM(i) as sum,
99+
AVG(i) as avg
100+
FROM r
101+
)
102+
SELECT l.*
103+
FROM lists l, computed
104+
WHERE l.name = 'Shopping list'
105+
LIMIT 1
106+
`
107+
)
108+
.then((result) => {
109+
console.log(`Query ${i} completed with result:`, result);
110+
})
111+
.catch((error) => {
112+
console.error(`Query ${i} error:`, error);
113+
});
38114

39-
const resultRecord = res.rows?.item(0);
40-
if (!resultRecord) {
41-
throw new Error('Could not create list');
115+
promises.push(promise);
42116
}
117+
await Promise.all(promises);
118+
console.log('All queries completed');
119+
// console.log('Todos:', todos);
120+
// const res = await system.powersync.execute(
121+
// `INSERT INTO ${LIST_TABLE} (id, created_at, name, owner_id) VALUES (uuid(), datetime(), ?, ?) RETURNING *`,
122+
// [name, userID]
123+
// );
124+
125+
// const resultRecord = res.rows?.item(0);
126+
// if (!resultRecord) {
127+
// throw new Error('Could not create list');
128+
// }
43129
};
44130

45131
const deleteList = async (id: string) => {

demos/react-native-supabase-todolist/library/powersync/system.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AppConfig } from '../supabase/AppConfig';
1111
import { SupabaseConnector } from '../supabase/SupabaseConnector';
1212
import { AppSchema } from './AppSchema';
1313
import { PhotoAttachmentQueue } from './PhotoAttachmentQueue';
14+
// import { OPSqliteOpenFactory } from '@powersync/op-sqlite'; // Add this import
1415

1516
Logger.useDefaults();
1617

@@ -31,6 +32,10 @@ export class System {
3132
dbFilename: 'sqlite.db'
3233
}
3334
});
35+
// const factory = new OPSqliteOpenFactory({
36+
// dbFilename: 'sqlite.db'
37+
// });
38+
// this.powersync = new PowerSyncDatabase({ database: factory, schema: AppSchema });
3439
/**
3540
* The snippet below uses OP-SQLite as the default database adapter.
3641
* You will have to uninstall `@journeyapps/react-native-quick-sqlite` and
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
2+
3+
# dependencies
4+
node_modules/
5+
6+
# Expo
7+
.expo/
8+
dist/
9+
web-build/
10+
11+
# Native
12+
*.orig.*
13+
*.jks
14+
*.p8
15+
*.p12
16+
*.key
17+
*.mobileprovision
18+
19+
# Metro
20+
.metro-health-check*
21+
22+
# debug
23+
npm-debug.*
24+
yarn-debug.*
25+
yarn-error.*
26+
27+
# macOS
28+
.DS_Store
29+
*.pem
30+
31+
# local env files
32+
.env*.local
33+
34+
# typescript
35+
*.tsbuildinfo
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { StatusBar } from 'expo-status-bar';
2+
import React from 'react';
3+
import { StyleSheet, Text, View } from 'react-native';
4+
5+
export default function App() {
6+
return (
7+
<View style={styles.container}>
8+
<Text>Open up App.js to start working on your app!</Text>
9+
<StatusBar style="auto" />
10+
</View>
11+
);
12+
}
13+
14+
const styles = StyleSheet.create({
15+
container: {
16+
flex: 1,
17+
backgroundColor: '#fff',
18+
alignItems: 'center',
19+
justifyContent: 'center',
20+
},
21+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Android/IntelliJ
6+
#
7+
build/
8+
.idea
9+
.gradle
10+
local.properties
11+
*.iml
12+
*.hprof
13+
.cxx/
14+
15+
# Bundle artifacts
16+
*.jsbundle

0 commit comments

Comments
 (0)