Skip to content

Commit 70f560f

Browse files
committed
feat: add barebones opsqlite demo
1 parent 829bf47 commit 70f560f

Some content is hidden

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

51 files changed

+8137
-4140
lines changed

Diff for: demos/react-native-barebones-opsqlite/.gitignore

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
**/.xcode.env.local
24+
25+
# Android/IntelliJ
26+
#
27+
build/
28+
.idea
29+
.gradle
30+
local.properties
31+
*.iml
32+
*.hprof
33+
.cxx/
34+
*.keystore
35+
!debug.keystore
36+
37+
# node.js
38+
#
39+
node_modules/
40+
npm-debug.log
41+
yarn-error.log
42+
43+
# fastlane
44+
#
45+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
46+
# screenshots whenever they are needed.
47+
# For more information about the recommended setup visit:
48+
# https://docs.fastlane.tools/best-practices/source-control/
49+
50+
**/fastlane/report.xml
51+
**/fastlane/Preview.html
52+
**/fastlane/screenshots
53+
**/fastlane/test_output
54+
55+
# Bundle artifact
56+
*.jsbundle
57+
58+
# Ruby / CocoaPods
59+
**/Pods/
60+
/vendor/bundle/
61+
62+
# Temporary files created by Metro to check the health of the file watcher
63+
.metro-health-check*
64+
65+
# testing
66+
/coverage
67+
68+
# Yarn
69+
.yarn/*
70+
!.yarn/patches
71+
!.yarn/plugins
72+
!.yarn/releases
73+
!.yarn/sdks
74+
!.yarn/versions
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

Diff for: demos/react-native-barebones-opsqlite/App.tsx

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import '@azure/core-asynciterator-polyfill';
2+
import React, { useEffect } from 'react';
3+
import type {PropsWithChildren} from 'react';
4+
import {
5+
SafeAreaView,
6+
ScrollView,
7+
StatusBar,
8+
StyleSheet,
9+
Text,
10+
useColorScheme,
11+
View,
12+
} from 'react-native';
13+
14+
import {
15+
Colors,
16+
DebugInstructions,
17+
Header,
18+
LearnMoreLinks,
19+
ReloadInstructions,
20+
} from 'react-native/Libraries/NewAppScreen';
21+
import { OPSqliteOpenFactory } from '@powersync/op-sqlite';
22+
import { column, Schema, Table, PowerSyncDatabase } from '@powersync/react-native';
23+
24+
/**
25+
* A placeholder connector which doesn't do anything but used to confirm connect can run.
26+
*/
27+
class DummyConnector {
28+
async fetchCredentials() {
29+
return {
30+
endpoint: '',
31+
token: '',
32+
};
33+
}
34+
35+
async uploadData() {}
36+
}
37+
38+
const customers = new Table({ name: column.text });
39+
40+
const schema = new Schema({ customers });
41+
42+
let powerSync: PowerSyncDatabase | null = null;
43+
44+
const setupDatabase = async () => {
45+
if (powerSync) return powerSync;
46+
47+
const factory = new OPSqliteOpenFactory({
48+
dbFilename: 'powersync.db',
49+
});
50+
51+
powerSync = new PowerSyncDatabase({
52+
schema,
53+
database: factory,
54+
});
55+
56+
await powerSync.init();
57+
return powerSync;
58+
};
59+
60+
type SectionProps = PropsWithChildren<{
61+
title: string;
62+
}>;
63+
64+
function Section({children, title}: SectionProps): React.JSX.Element {
65+
const isDarkMode = useColorScheme() === 'dark';
66+
return (
67+
<View style={styles.sectionContainer}>
68+
<Text
69+
style={[
70+
styles.sectionTitle,
71+
{
72+
color: isDarkMode ? Colors.white : Colors.black,
73+
},
74+
]}>
75+
{title}
76+
</Text>
77+
<Text
78+
style={[
79+
styles.sectionDescription,
80+
{
81+
color: isDarkMode ? Colors.light : Colors.dark,
82+
},
83+
]}>
84+
{children}
85+
</Text>
86+
</View>
87+
);
88+
}
89+
90+
function App(): React.JSX.Element {
91+
const isDarkMode = useColorScheme() === 'dark';
92+
93+
const backgroundStyle = {
94+
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
95+
};
96+
97+
useEffect(() => {
98+
const initDB = async () => {
99+
try {
100+
const db = await setupDatabase();
101+
102+
// Test database operations
103+
await db.execute('INSERT INTO customers(id, name) VALUES(uuid(), ?)', ['Fred']);
104+
const result = await db.getAll('SELECT * FROM customers');
105+
console.log('Customers:', result);
106+
107+
// Connect with dummy connector
108+
await db.connect(new DummyConnector());
109+
} catch (error) {
110+
console.error('Database initialization error:', error);
111+
}
112+
};
113+
114+
initDB();
115+
}, []);
116+
117+
return (
118+
<SafeAreaView style={backgroundStyle}>
119+
<StatusBar
120+
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
121+
backgroundColor={backgroundStyle.backgroundColor}
122+
/>
123+
<ScrollView
124+
contentInsetAdjustmentBehavior="automatic"
125+
style={backgroundStyle}>
126+
<Header />
127+
<View
128+
style={{
129+
backgroundColor: isDarkMode ? Colors.black : Colors.white,
130+
}}>
131+
<Section title="Step One">
132+
Edit <Text style={styles.highlight}>App.tsx</Text> to change this
133+
screen and then come back to see your edits.
134+
</Section>
135+
<Section title="See Your Changes">
136+
<ReloadInstructions />
137+
</Section>
138+
<Section title="Debug">
139+
<DebugInstructions />
140+
</Section>
141+
<Section title="Learn More">
142+
Read the docs to discover what to do next:
143+
</Section>
144+
<LearnMoreLinks />
145+
</View>
146+
</ScrollView>
147+
</SafeAreaView>
148+
);
149+
}
150+
151+
const styles = StyleSheet.create({
152+
sectionContainer: {
153+
marginTop: 32,
154+
paddingHorizontal: 24,
155+
},
156+
sectionTitle: {
157+
fontSize: 24,
158+
fontWeight: '600',
159+
},
160+
sectionDescription: {
161+
marginTop: 8,
162+
fontSize: 18,
163+
fontWeight: '400',
164+
},
165+
highlight: {
166+
fontWeight: '700',
167+
},
168+
});
169+
170+
export default App;

Diff for: demos/react-native-barebones-opsqlite/Gemfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source 'https://rubygems.org'
2+
3+
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4+
ruby ">= 2.6.10"
5+
6+
# Exclude problematic versions of cocoapods and activesupport that causes build failures.
7+
gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1'
8+
gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0'
9+
gem 'xcodeproj', '< 1.26.0'
10+
gem 'concurrent-ruby', '< 1.3.4'

Diff for: demos/react-native-barebones-opsqlite/Gemfile.lock

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
CFPropertyList (3.0.7)
5+
base64
6+
nkf
7+
rexml
8+
activesupport (7.2.2.1)
9+
base64
10+
benchmark (>= 0.3)
11+
bigdecimal
12+
concurrent-ruby (~> 1.0, >= 1.3.1)
13+
connection_pool (>= 2.2.5)
14+
drb
15+
i18n (>= 1.6, < 2)
16+
logger (>= 1.4.2)
17+
minitest (>= 5.1)
18+
securerandom (>= 0.3)
19+
tzinfo (~> 2.0, >= 2.0.5)
20+
addressable (2.8.7)
21+
public_suffix (>= 2.0.2, < 7.0)
22+
algoliasearch (1.27.5)
23+
httpclient (~> 2.8, >= 2.8.3)
24+
json (>= 1.5.1)
25+
atomos (0.1.3)
26+
base64 (0.2.0)
27+
benchmark (0.4.0)
28+
bigdecimal (3.1.9)
29+
claide (1.1.0)
30+
cocoapods (1.15.2)
31+
addressable (~> 2.8)
32+
claide (>= 1.0.2, < 2.0)
33+
cocoapods-core (= 1.15.2)
34+
cocoapods-deintegrate (>= 1.0.3, < 2.0)
35+
cocoapods-downloader (>= 2.1, < 3.0)
36+
cocoapods-plugins (>= 1.0.0, < 2.0)
37+
cocoapods-search (>= 1.0.0, < 2.0)
38+
cocoapods-trunk (>= 1.6.0, < 2.0)
39+
cocoapods-try (>= 1.1.0, < 2.0)
40+
colored2 (~> 3.1)
41+
escape (~> 0.0.4)
42+
fourflusher (>= 2.3.0, < 3.0)
43+
gh_inspector (~> 1.0)
44+
molinillo (~> 0.8.0)
45+
nap (~> 1.0)
46+
ruby-macho (>= 2.3.0, < 3.0)
47+
xcodeproj (>= 1.23.0, < 2.0)
48+
cocoapods-core (1.15.2)
49+
activesupport (>= 5.0, < 8)
50+
addressable (~> 2.8)
51+
algoliasearch (~> 1.0)
52+
concurrent-ruby (~> 1.1)
53+
fuzzy_match (~> 2.0.4)
54+
nap (~> 1.0)
55+
netrc (~> 0.11)
56+
public_suffix (~> 4.0)
57+
typhoeus (~> 1.0)
58+
cocoapods-deintegrate (1.0.5)
59+
cocoapods-downloader (2.1)
60+
cocoapods-plugins (1.0.0)
61+
nap
62+
cocoapods-search (1.0.1)
63+
cocoapods-trunk (1.6.0)
64+
nap (>= 0.8, < 2.0)
65+
netrc (~> 0.11)
66+
cocoapods-try (1.2.0)
67+
colored2 (3.1.2)
68+
concurrent-ruby (1.3.3)
69+
connection_pool (2.5.0)
70+
drb (2.2.1)
71+
escape (0.0.4)
72+
ethon (0.16.0)
73+
ffi (>= 1.15.0)
74+
ffi (1.17.1)
75+
fourflusher (2.3.1)
76+
fuzzy_match (2.0.4)
77+
gh_inspector (1.1.3)
78+
httpclient (2.8.3)
79+
i18n (1.14.7)
80+
concurrent-ruby (~> 1.0)
81+
json (2.9.1)
82+
logger (1.6.5)
83+
minitest (5.25.4)
84+
molinillo (0.8.0)
85+
nanaimo (0.3.0)
86+
nap (1.1.0)
87+
netrc (0.11.0)
88+
nkf (0.2.0)
89+
public_suffix (4.0.7)
90+
rexml (3.4.0)
91+
ruby-macho (2.5.1)
92+
securerandom (0.4.1)
93+
typhoeus (1.4.1)
94+
ethon (>= 0.9.0)
95+
tzinfo (2.0.6)
96+
concurrent-ruby (~> 1.0)
97+
xcodeproj (1.25.1)
98+
CFPropertyList (>= 2.3.3, < 4.0)
99+
atomos (~> 0.1.3)
100+
claide (>= 1.0.2, < 2.0)
101+
colored2 (~> 3.1)
102+
nanaimo (~> 0.3.0)
103+
rexml (>= 3.3.6, < 4.0)
104+
105+
PLATFORMS
106+
ruby
107+
108+
DEPENDENCIES
109+
activesupport (>= 6.1.7.5, != 7.1.0)
110+
cocoapods (>= 1.13, != 1.15.1, != 1.15.0)
111+
concurrent-ruby (< 1.3.4)
112+
xcodeproj (< 1.26.0)
113+
114+
RUBY VERSION
115+
ruby 3.2.2p53
116+
117+
BUNDLED WITH
118+
2.5.14

0 commit comments

Comments
 (0)