TinyBase logoTinyBase β

getDb

The getDb method returns a reference to the database connection the Store is being persisted to.

getDb(): SQLiteDBConnection
returnsSQLiteDBConnection

A reference to the database connection.

Example

This example creates a Persister object against a newly-created Store and then gets the database connection back out again.

import {
  CapacitorSQLite,
  SQLiteConnection,
} from '@capacitor-community/sqlite';
import {createStore} from 'tinybase';
import {createCapacitorSqlitePersister} from 'tinybase/persisters/persister-capacitor-sqlite';

const sqlite = new SQLiteConnection(CapacitorSQLite);
const db = await sqlite.createConnection(
  'my.db',
  false,
  'no-encryption',
  1,
  false,
);
await db.open();

const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
const persister = createCapacitorSqlitePersister(store, db, 'my_tinybase');

console.log(persister.getDb() == db);
// -> true

await persister.destroy();

Since

9.6.0