Skip to content

Instantly share code, notes, and snippets.

@Gregoor
Last active January 11, 2017 11:18
Show Gist options
  • Save Gregoor/c2e1b90438e2974558bfe0df2049a535 to your computer and use it in GitHub Desktop.
Save Gregoor/c2e1b90438e2974558bfe0df2049a535 to your computer and use it in GitHub Desktop.
DreamBase

DreamBase

Relational Storage, Hierarchical Retrieval

Present Database Models

Some of the following points are not necessary given the model, but are in every widely used version of it. If you disagree, let me know.

Relational

Pros
  • normalization
  • simple updates
  • complex querires possible, with DSL
  • schema enforcement
Cons
  • queries can get expensive
    • requires caching
  • learn and interop with DSL and backend language
  • schema has to be created/updated

Document

Pros
  • fast retrieval
  • shape of results often matches shape needed for UI
  • no DSL needed
  • no schema needed
Cons
  • redundancies
    • complicated updates
  • complicated joins
  • no schema enforcement

Solution

  • model data relationally, normalized
  • hierarchical retrieval, cached on a DB-level, like materialized views (refreshed incrementally)
  • no DSL, document FFI and build language specific libs
  • "declarative schema"
    • migrations only for destructive operations necessary
class User extends Record {
static fields = {
name: 'string',
email: ['string', ['lowercase', 'trim']],
posts: [Post]
};
}
class Post extends Record {
static fields = {
title: 'string'
}
}
const lukes = User
.select('name', 'email', {posts: ['title']})
.where('name', 'Luke')
console.log(lukes);
/*
[
{name: 'Luke', email: 'luke@example.com', posts: [{title: 'About my father'}, {title: 'Vertigo'}]}
]
*/
User({id: 3}).posts.insert({title: 'New post'});
schemer({
users: {
fields: {
name: ['text', {null: false}],
email: ['text', {null: false}]
}
},
posts: {
fields: {
title: ['text', {null: false}],
content: ['text', {null: false}]
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment