tinyplex / tinybase

The reactive data store for local‑first apps.
https://tinybase.org
MIT License
3.23k stars 65 forks source link

Add expo-sqlite-next-persister #114

Closed alanjhughes closed 7 months ago

alanjhughes commented 8 months ago

Summary

We'd like to add a new persister to support the next version of expo-sqlite which is a ground up rewrite. The plan would be to deprecate the legacy persister and API once the new api has been available for an SDK cycle or two.

How did you test this change?

Tested in the example project we used for the original persister. Can be seen here

jamesgpearce commented 7 months ago

Once the old one is gone, are you ok with this being called 'next' for ever?

alanjhughes commented 7 months ago

It's ok with me but I'll defer to @brentvatne

jamesgpearce commented 7 months ago

Amazing. Thanks!

brentvatne commented 7 months ago

ideally we'd remove the next from the name after the old one is gone. this won't be until about april.

tobiascornille commented 6 months ago

@alanjhughes Are you planning on creating a simpler example project without the syncing using CR-SQLite? I'm asking because I'm running into problems with a simple set up:

db.ts

db.execSync(`CREATE TABLE IF NOT EXISTS test (id PRIMARY KEY, name TEXT);`);

App.tsx

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

  const addData = useCallback(
    () => store.setCell("test", nanoid(10), "name", "testtest"),
    [store],
  );

When addData is called, it is not saved to the SQL database. I also cannot see data I insert using SQL in TinyBase.

If I add console.info to the createExpoSqliteNextPersister I get

 INFO  BEGIN undefined
 INFO  BEGIN undefined
 INFO  BEGIN undefined
 INFO  BEGIN undefined