Releases: tinyplex/tinybase
v5.3.4
v5.3.3
v5.3.2
This release updates dependencies and annotates some pure functions to improve transpilation.
v5.3.1
This release updates dependencies.
v5.3.0
This release is focussed on a few API improvements and quality-of-life changes. These include:
React SSR support
Thanks to contributor Muhammad Muhajir (@muhajirdev) for ensuring that TinyBase runs in server-side rendering environments!
In the persisters module...
All Persister objects now expose information about whether they are loading or saving. To access this Status, use:
- The getStatus method, which will return 0 when it is idle, 1 when it is loading, and 2 when it is saving.
- The addStatusListener method, which lets you add a StatusListener function and which is called whenever the status changes.
These make it possible to track background load and save activities, so that, for example, you can show a status-bar spinner of asynchronous persistence activity.
In the synchronizers module...
Synchronizers are a sub-class of Persister, so all Synchronizer objects now also have:
- The getStatus method, which will return 0 when it is idle, 1 when it is 'loading' (ie inbound syncing), and 2 when it is 'saving' (ie outbound syncing).
- The addStatusListener method, which lets you add a StatusListener function and which is called whenever the status changes.
In the ui-react module...
There are corresponding hooks so that you can build these status changes into a React UI easily:
- The usePersisterStatus hook, which will return the status for an explicitly provided, or context-derived Persister.
- The usePersisterStatusListener hook, which lets you add your own StatusListener function to a Persister.
- The usePersister hook, which lets you get direct access to a Persister from within your UI.
And correspondingly for Synchronizers:
- The useSynchronizerStatus hook, which will return the status for an explicitly provided, or context-derived Synchronizer.
- The useSynchronizerStatusListener hook, which lets you add your own StatusListener function to a Synchronizer.
- The useSynchronizer hook, which lets you get direct access to a Synchronizer from within your UI.
In addition, this module also now includes hooks for injecting objects into the Provider context scope imperatively, much like the existing useProvideStore hook:
- The useProvideMetrics hook, which lets you imperatively register Metrics objects.
- The useProvideIndexes hook, which lets you register Indexes objects.
- The useProvideRelationships hook, which lets you register Relationships objects.
- The useProvideQueries hook, which lets you register Queries objects.
- The useProvideCheckpoints hook, which lets you register Checkpoints objects.
- The useProvidePersister hook, which lets you register Persister objects.
- The useProvideSynchronizer hook, which lets you register Synchronizer objects.
All of these new methods have extensive documentation, each with examples to show how to use them.
Please provide feedback on this new release on GitHub!
v5.2.3
This release addresses a rendering bug in the ui-react-inspector when there were multiple tables in a Store
v5.2.2
This fixes a small global React context problem.
v5.2.1
This release updates dependencies, fixes some new lint issues, and updates the type definitions to reflect the removal of the persisters and synchronizers module from the master tinybase module.
v5.2.0
This release introduces new Persisters for... PostgreSQL! TinyBase now has two new Persister modules:
- The persister-postgres module provides the PostgresPersister, which uses the excellent postgres module to bind to regular PostgreSQL databases, generally on a server.
- The persister-pglite module provides the PglitePersister, which uses the new and exciting pglite module for running PostgreSQL... in a browser!
Conceptually, things behave in the same way as they do for the various SQLite persisters. Simply use the createPostgresPersister function (or the similar createPglitePersister function) to persist your TinyBase data:
import postgres from 'postgres';
import {createPostgresPersister} from 'tinybase/persisters/persister-postgres';
import {createStore} from 'tinybase';
// Create a TinyBase Store.
const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
// Create a postgres connection and Persister.
const sql = postgres('postgres://localhost:5432/tinybase');
const pgPersister = await createPostgresPersister(store, sql, 'my_tinybase');
// Save Store to the database.
await pgPersister.save();
console.log(await sql`SELECT * FROM my_tinybase;`);
// -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
And, as per usual, you can update the database and have TinyBase automatically reflect those changes:
// If separately the database gets updated...
const json = '[{"pets":{"felix":{"species":"cat"}}},{}]';
await sql`UPDATE my_tinybase SET store = ${json} WHERE _id = '_';`;
// ... then changes are loaded back. Reactive auto-load is also supported!
await pgPersister.load();
console.log(store.getTables());
// -> {pets: {felix: {species: 'cat'}}}
// As always, don't forget to tidy up.
pgPersister.destroy();
await sql.end();
Note that these two Persister objects support both the json and tabular modes for saving TinyBase data into the database. See the DatabasePersisterConfig type for more details. (Note however that, like the SQLite Persisters, only the json mode is supported for MergeableStore instances, due to their additional CRDT metadata.)
Please provide feedback on this new release on GitHub!