Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alterx/gundb-expo-sqlite-adapter
An adapter that implements the RAD interface and writes to SQLite (expo-sqlite)
https://github.com/alterx/gundb-expo-sqlite-adapter
expo expo-sqlite gundb sqlite
Last synced: 13 days ago
JSON representation
An adapter that implements the RAD interface and writes to SQLite (expo-sqlite)
- Host: GitHub
- URL: https://github.com/alterx/gundb-expo-sqlite-adapter
- Owner: alterx
- License: mit
- Created: 2021-08-21T17:55:41.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-21T17:00:08.000Z (over 2 years ago)
- Last Synced: 2024-10-08T18:10:37.254Z (about 1 month ago)
- Topics: expo, expo-sqlite, gundb, sqlite
- Language: TypeScript
- Homepage:
- Size: 54.7 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# GunDB Expo SQLite Adapter
This is an adapter that implements the RAD interface and writes to SQLite (expo-sqlite)
## Installing
Use `pnpm`, `npm` or `yarn` to install the dependencies:
```
$ npm i @altrx/gundb-expo-sqlite-adapter
```### Basic Usage:
See full example [here](https://github.com/alterx/gundb-expo-sqlite)
```jsx harmony
import React, { useEffect, useState } from 'react';
import { StyleSheet, Text, TextInput, View, Button } from 'react-native';
import Constants from 'expo-constants';
import * as SQLite from 'expo-sqlite';import WebviewCrypto from 'react-native-webview-crypto';
import { registerRootComponent } from 'expo';import 'gun/lib/mobile'; // most important!
import Gun from 'gun/gun';
import SEA from 'gun/sea';
import 'gun/lib/promise';
import 'gun/lib/radix';
import 'gun/lib/radisk';
import 'gun/lib/store';
import { makeStoreAdapter } from '@altrx/gundb-expo-sqlite-adapter';makeStoreAdapter(Gun);
const gun = new Gun({
localStorage: false,
radisk: true,
sqlite: {
SQLite,
databaseName: 'todo.db',
onOpen: () => {
console.log('DB OPENED');
},
onError: (err) => {
console.log('ERROR');
},
onReady: (err) => {
console.log('READY');
},
},
});const node = gun.get('hello');
export default function App() {
const [name, setName] = useState('');useEffect(() => {
node.once((data, key) => {
let name = data?.name;
setName(name);
});async function doWork() {
const workTest = await SEA.work('test', null, null, {
name: 'SHA-256',
encode: 'hex',
});
console.log(workTest);
const pair = await SEA.pair();
const other = await SEA.pair();
const msg = await SEA.sign('I wrote this message! You did not.', pair);
const test = await SEA.verify(msg, pair.pub); // message gets printed
const test2 = await SEA.verify(msg, other.pub); // error
console.log('No message', test2);
console.log('Message', test);gun.on('auth', () => {
console.log('authenticated with keypair');
});const namespace = gun.user();
namespace.auth(pair);
}
doWork();
}, []);return (
Hello {name}
setName(value)}
style={styles.input}
/>
{
node.put({ name });
setName(name);
}}
/>
);
}const styles = StyleSheet.create({
container: {
backgroundColor: '#fff',
flex: 1,
paddingTop: Constants.statusBarHeight,
},
welcome: {
fontSize: 20,
fontWeight: 'bold',
textAlign: 'center',
},
flexRow: {
flexDirection: 'row',
},
input: {
borderColor: '#4630eb',
borderRadius: 4,
borderWidth: 1,
flex: 1,
height: 48,
margin: 16,
padding: 8,
},
});registerRootComponent(App);
```
## License
Licensed under [MIT](https://github.com/alterx/gundb-expo-sqlite-adapter/blob/master/LICENSE.md).