Coder Social home page Coder Social logo

freezer's Introduction

Freezer

Freezer is inspired by / ripped off from Rich Hickey's talk, The Database as a Value and Datomic.

Freezer is an immutable value store. All changes to the store create a new database, as opposed to changing the database in place. Once you have pulled a database out of the store, it never changes. It is a fixed view of the store at that point in time.

Freezer is made up of a few basic components:

  • FRZStore is the top-level thing. The store is where you go to get the current database or get a transactor to perform changes.
  • FRZDatabase is how you get data out of the store. It is immutable. It never changes in place.
  • FRZTransactor is responsible for adding or removing values from the store.

IDs

IDs are used to group key-value pairs into a single entity. They can be any arbitrary string.

Keys

Freezer does not store objects. Instead, it stores an arbitrary collection of key-value pairs, grouped by an ID.

A collection of keys, grouped by ID, may be transformed into, for example, a Mantle model object. But note that model object is simply a view on the data. It is not the thing itself.

Changes

Stores provide a RACSignal of changes which are applied to the store. This signal can be filtered, throttled, etc. as needed to find out about the changes your app cares about.

Thread-safety

Freezer is completely thread-safe. Databases may be read from in any thread and FRZTransactor may add or remove values in any thread.

If the database is immutable... does that mean the store grows without bound?

Yuuuuuuuuuup. But you can call -[FRZTransactor trim:] to trim the store down to the latest database.

Should I use this?

Nooooooooope. Or at least not yet. Freezer's still in a constant state of flux.

freezer's People

Contributors

joshaber avatar mdiep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

freezer's Issues

SQLite VACUUM

We should run VACUUM. Probably as part of trimming.

Reify transactions

Transactions exist currently in the database, but we don't expose them to users. It could be useful:

  • Timestamp for changes.
  • List of changes.

Related to #3.

Implement attributes as columns on a single table?

Currently each attribute is its own table. We could instead implement each attribute as a column on one table. This could help address #5.

The downside is that we'd probably end up with a super wide table. I'm not sure how Sqlite feels about that.

Need any indexes?

We currently don't use any indexes. It'd probably make sense to index on key. Maybe attribute too?

Move back to a single table

In light of #5, #12, #19, I think it'd make sense to move back to using a single table.

๐Ÿ‘

  • Simper, more consistent implementation.
  • Faster key-based reads.

๐Ÿ‘Ž

  • The value column will just be a blob, making it harder for us to leverage SQLite magic.
    • We could maybe mitigate that with custom functions which unpack the blob?
  • Less space-efficient, presumably.

Cache attribute information

Reads and writes require that we look up attribute information (type, cardinality, etc.). We should cache that.

We'd get this for free if we did #8.

Move to a different backend?

Sqlite's awesome, LevelDB might be more awesome.

๐Ÿ‘

  • Faster than Sqlite
  • Snapshots are a non-persistent version of our immutable databases.
  • More thread-safety out of the box.
  • Sorted keys could allow for a bit more flexibility.

๐Ÿ‘Ž

  • Outside dependency.
  • Snapshots can't be persisted.
  • C++

Speed up key-based reads

Currently key-based reads require walking over each of attribute tables and checking if they have an entry for the key. This means it's gonna slow down as you add more attributes.

A couple thoughts on speeding it up:

  • Partition keys so that we can known based on the they that it could only have certain attributes.
  • Keep an index of the attributes which a key has.

Sqlite database grows without bound

Currently the sqlite database just keeps adding things. That's less than ideal. We should have some way of trimming it.

Some things:

  • We could trim down to the most recent level attribute-value for all keys.
  • But it's tricky to know that someone's not holding on to an old database.
  • How does this interact with #3?

More sophisticated querying?

Should Freezer provide more sophisticated querying?

  • Most query APIs are heavily stringly typed.
  • Could we use Sqlite functions to get more typing?

Re-think terminology of key/attribute/value

From @mdiep.

I think the dissonance for me is that it feels like I'm mutating a dictionary, but the names don't convey that

I agree. It's tricky because dictionaries are key -> value, but Freezer's more like key -> (attribute, value).

Inserting is O(n) (lolcry)

Currently on both branches, inserting is O(n), n = number of objects in the previous "database." This is because they create a new list of objects for each insert. That's... less than ideal.

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.