Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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)

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).