Git Product home page Git Product logo

odem's Introduction

Hitchy's Odem Build Status

an object document management for hitchy

License

MIT

Usage

const { Model, FileAdapter } = require( "hitchy-odem" );

const fileBackend = new FileAdapter( "../my-data-store" );

const User = Model.define( "user", {
	// regular attributes
	name: { 
		type: "string",
		required: true,
		trim: true,
		minLength: 4,
		maxLength: 16,
	},
	secret: { 
		type: "string",
		required: true,
		process: value => createHash( value ),
	},
	level: { 
		type: "integer",
		default: 1,
		min: 1,
		max: 10,
	},
	lastLogin: { 
		type: "date",
	},
	
	// computed properties
	hasLoggedInBefore: item => item.lastLogin != null,

	// life cycle hooks
	onSaved: [
		item => {
			item.secret = createHash( item.secret );
		} 
	]
}, { adapter: fileBackend } );

// static methods
User.create = function( name, secret ) {
	const user = new User();
	
	user.name = name;
	user.secret = secret;
	user.level = 0;

	return user.save();
};


User.create( "John Doe", "very-secret" )
	.then( user => {
		user.level = 3;
		return user.save();
	} )
	.then( () => User.findByAttribute( "level", 3 ) )
	.then( list => {
		// list[0].uuid === user.uuid
	} );

odem's People

Contributors

soletan avatar iriberri avatar

Watchers

James Cloos avatar

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.