tinyplex / tinybase

The reactive data store for local‑first apps.

Home Page:https://tinybase.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

expo-sqlite-next-persister not working

tobiascornille opened this issue · comments

Describe the bug

If I try to use createExpoSqliteNextPersister and follow the changes as here, the connection to the database does not seem to work. In the console I can only see INFO BEGIN undefined being logged.

Tagging @alanjhughes @brentvatne since they submitted the expo-sqlite-next-persister PR #114

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

Here are some code snippets:
Working:

import * as SQLite from "expo-sqlite";

export const dbName = "test.db";

export const db = SQLite.openDatabase(dbName);

export function initDatabase() {
  console.error("Initializing db", db);
  db.exec(
    [
      {
        sql: `CREATE TABLE IF NOT EXISTS "todo" ("id" PRIMARY KEY, "text", "completed" INTEGER DEFAULT 0);`,
        args: [],
      },
    ],
    false,
    () => {},
  );
}
  const store = useStore();

  useEffect(() => {
    initDatabase();
  }, []);

  const persister = useCreatePersister(
    store,
    (store) =>
      createExpoSqlitePersister(
        store,
        db,
        {
          mode: "tabular",
          tables: {
            load: { todo: { tableId: "todo", rowIdColumnName: "id" } },
            save: { todo: { tableName: "todo", rowIdColumnName: "id" } },
          },
        },
        console.info,
      ),
    [db],
    async (persister) => {
      await persister.startAutoLoad();
      await persister.startAutoSave();
    },
  );

Not working:

import * as SQLite from "expo-sqlite/next";

export const dbName = "test.db";

export const db = SQLite.openDatabaseSync(dbName);

export function initDatabase() {
  console.error("Initializing db", db);
  db.execAsync(
    `CREATE TABLE IF NOT EXISTS "todo" ("id" PRIMARY KEY, "text", "completed" INTEGER DEFAULT 0);`,
  );
}
  useEffect(() => {
    initDatabase();
  }, []);

  const persister = useCreatePersister(
    store,
    (store) =>
      createExpoSqliteNextPersister(
        store,
        db,
        {
          mode: "tabular",
          tables: {
            load: { todo: { tableId: "todo", rowIdColumnName: "id" } },
            save: { todo: { tableName: "todo", rowIdColumnName: "id" } },
          },
        },
        console.info,
      ),
    [db],
    async (persister) => {
      await persister.startAutoLoad();
      await persister.startAutoSave();
    },
  );

Expected behavior

No response

Screenshots or Videos

No response

Platform

"expo": "^50.0.0-preview.7",
"expo-sqlite": "~13.2.0",
"react-native": "0.73.1",
"tinybase": "4.5.10",

I'm testing on an Android Emulator with Android 14.0

Additional context

No response

we made some changes to the expo-sqlite/next API during the beta, we'll need to update the persister. cc @alanjhughes

Standing by to accept the PR! It would be cool to unbreak this. Thanks!

Working on it at the moment. Should be ready soon, just investigating an issue.