UNPKG

@react-native-replicache/replicache-generic-sqlite

Version:

> Plug-in React Native compatibility bindings for [Replicache](https://replicache.dev/).

25 lines (20 loc) 716 B
import type { KVStore, ReadonlyJSONValue } from "replicache"; import { ReplicacheGenericSQLiteReadImpl } from "./replicache-generic-sqlite-read-impl"; export class ReplicacheGenericSQLiteWriteImpl extends ReplicacheGenericSQLiteReadImpl implements Awaited<ReturnType<KVStore["write"]>> { async put(key: string, value: ReadonlyJSONValue) { const jsonValueString = JSON.stringify(value); await this._assertTx().execute( "INSERT OR REPLACE INTO entry (key, value) VALUES (?, ?)", [key, jsonValueString], ); } async del(key: string) { await this._assertTx().execute("DELETE FROM entry WHERE key = ?", [key]); } async commit() { // Do nothing and wait for release. } }