Giter VIP home page Giter VIP logo

replicache-transaction's Introduction

replicache-transaction

This is an adapter from Replicache's WriteTransaction to some key/value storage.

It's useful when you want to reuse Replicache mutator functions on the backend. All you have to do is provide a suitable implementation of the "Storage" interface, for example against your backend SQL database and then execute each of the mutations in a Replicache push request using them.

ReplicacheTransaction also implements an in-memory cache for entries over the lifetime of the transaction so that repeated reads and writes for same key don't go back and forth to the database.

Usage

import mutators from './my-mutators.ts';

class MyStorage implements Storage {
  // ...
}

const myStorage = new MyStorage(dbconn, spaceID, version);
const tx = new ReplicacheTransaction(storage, clientID);

const createTodo = mutators.createTodo;
await createTodo(tx, {title: 'Hello, shared mutators', complete: false});

await tx.flush();

See replicache-express for a complete example.

Important: Sort Order

It is important that the getEntries() method returns keys in order of their UTF-8 byte encoding. This is a collation option in most databases. See https://blog.replicache.dev/blog/replicache-11-adventures-in-text-encoding for more information.

Contributing

PRs and feature requests are welcome!

replicache-transaction's People

Contributors

aboodman avatar arv avatar cesara avatar

Stargazers

 avatar

Watchers

 avatar  avatar

replicache-transaction's Issues

Error publishing to Cloudflare: "generating random values ... can only be performed while handling a request"

This was reported by a user. Debugging with him what's happening is that replicache-transaction relies on replicache for some helper functions (probably wasn't a great idea). And replicache has some load-time code that calls crypto.randomUUID().

The crypto namespace is implemented by CF workers, but you're not allowed to use it outside of a request, apparently.

Not sure what the right solution is here. I think the user can work around either by undefining crypto, or else dynamically loading the module. But other users of replicache-transaction on cf will hit the same problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.