UNPKG

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

Version:

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

54 lines 2.08 kB
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } import { ReplicacheGenericSQLiteReadImpl } from "./replicache-generic-sqlite-read-impl"; import { ReplicacheGenericSQLiteWriteImpl } from "./replicache-generic-sqlite-write-impl"; export class ReplicacheGenericStore { constructor(name, _dbm) { this.name = name; this._dbm = _dbm; _defineProperty(this, "_closed", false); } async read() { const db = await this._getDb(); const tx = db.transaction(); await tx.start(true); return new ReplicacheGenericSQLiteReadImpl(tx); } async withRead(fn) { const read = await this.read(); try { return await fn(read); } finally { read.release(); } } async write() { const db = await this._getDb(); const tx = db.transaction(); await tx.start(false); return new ReplicacheGenericSQLiteWriteImpl(tx); } async withWrite(fn) { const write = await this.write(); try { return await fn(write); } finally { write.release(); } } async close() { await this._dbm.close(this.name); this._closed = true; } get closed() { return this._closed; } async _getDb() { return await this._dbm.open(this.name); } } export function getCreateReplicacheSQLiteKVStore(db) { return name => new ReplicacheGenericStore(name, db); } //# sourceMappingURL=replicache-generic-sqlite-store.js.map