Coder Social home page Coder Social logo

chest's Introduction

⚠️ This package is in its alpha stage. You can use it experimentally, but not in production yet. The binary format is not stable yet, so data might be lost. Stay tuned!


Chest

A type-safe in-memory database with amazing developer experience.

documentation · examples · how it works · FAQ

What's a database? It's just a place where you can persist data beyond your app's lifetime. Chest offers exactly that: persistent variables called chests.

var counter = Chest<int>('counter', ifNew: () => 0);
await counter.open();
print('This program ran ${counter.value} times.');
counter.value++;
await counter.close();

But isn't treating databases like variables inefficient? Not at all! To be clear, you don't need to read or save the whole object every time you make a change. Chest allows you to only change part of a value, even fields marked with final.

var me = Chest('me', ifNew: () => User());
await me.open();
me.value; // Decodes the whole user.
me.pet.value; // Only decodes the pet.
me.pet.favoriteFood.color.value = Color.red; // Only changes the color.

The important thing is that me is not a User, but a Reference<User>. Only when you use the .value getters or setters, you actually decode or change a subtree of the data.

This is especially handy if you're dealing with large maps:

var users = Chest<Map<String, User>>('users', ifNew: () => {});
await users.open();
var marcel = users['marcel'].value; // Only decodes Marcel.
users['jonas'].value = User(...); // Only saves Jonas.

Hang on. How does Chest know how to handle my types? Chest comes with its own encoding called tape. Some types already have built-in tapers (serializers for objects). You can annotate your types with @tape and let Chest generate tapers automatically:

// Run `dart pub run build_runner build` in the command line.
part 'this_file.g.dart';

@tape
class Fruit {
  final String name;
  final Color color;
}

Other perks

  • ❤️ Amazing developer experience. Just like you can inspect your program with Dart's DevTools, you can inspect, debug, and edit your database with ChestTools live in your browser.
  • 🎈 Lightweight. Chest is written in pure Dart and has no native dependencies. That means it works on any platform.

chest's People

Contributors

marcelgarus avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

mracipayam

chest's Issues

Set up chesttools

Similar to Dart's DevTools, ChestTools should allow inspecting and debugging the Chest database.

Rename

The name "Cassette" is long, difficult to spell correctly (even I had to look it up), and difficult to say quickly. It's a cool reference to Tape, but this package isn't even tightly coupled to Tape, so I'd rather opt for a short, one-syllable name like "Chest".

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.