Code Monkey home page Code Monkey logo

adelia's Introduction

Build Status Coverage Status

adelia

🐧 Antarctic-friendly ORM for Node

AdΓ©lie penguins on an iceberg

Photo (c) by Jason Auch

Design Principles

Adelia is meant to be a fast, simple, promise-based ORM for Node, loosely inspired to Martin Fowler's ActiveRecord pattern popularized by Ruby on Rails. Due to the async IO nature of Node and DB clients, the API must be async. Adelia uses Promises to offer a clean, uncluttered API that's easy to compose and reason about.

Features

  • Accessors: has, get, set, unset.
  • Persistence: save, delete.
  • Query: find, findById, findAll, findByQuery, countAll.
  • Relationships: hasOne, hasMany, belongsTo, hasAndBelongsToMany.
  • Specialization: create.

Configuration

Set these environment variables in your script:

  • DB one of the supported databases: mysql (default), or sqlite (experimental).

MySQL

Set these variables to configure Adelia to use a MySQL database server:

  • MYSQL_HOST host of the MySQL database server.
  • MYSQL_PORT port of the MySQL database server.
  • MYSQL_USER username to connect to the MySQL database server.
  • MYSQL_PASSWORD password of the user of the MySQL database server.
  • MYSQL_DB name of the MySQL database.

This assumes you already have a MySQL server to use. For local development, see the Development section below.

SQLite

Set this variable to configure Adelia to use a SQLite database:

  • SQLITE_DB path to the SQLite database file.

Usage

Adelia has a concise, promise-based API that allows you to perform chained operations to query and fetch model objects, access their properties, persist, and delete them. Here's an example:

const Model = require('adelia').Model;

// Creates a specialized model class
const Penguin = Model.create('penguin');

// Instantiates a penguin
const emperor = new Penguin({
  species: 'Emperor'
});

let emperor_id;

// Saves the penguin to DB
emperor.save()
	.then(model => model.get('id'))
	.then(id => { emperor_id = id; });

// Fetches a model from the DB
Penguin.find(emperor_id)
	.then(model => model.get('species'))
	.then(name => console.log(`My species is ${name}`));
// => My species is Emperor

Status

  • MySQL support: STABLE
  • SQLite support: EXPERIMENTAL

MySQL support is currently stable, with some known issues. SQLite support is currently experimental. Tests are failing locally and in TravisCI. If you'd like to use Adelia on SQLite and can contribute fixes and enhancements, please submit a PR!

Contributing

Thank you for your interest in Adelia! Feel free to open issues or submit a PR. See the Contributing Guidelines for detailed instructions.

Development

Adelia is a Node module. If you are unsure what to do, follow these steps:

Installing a local MySQL server

For development, it's best to use a local MySQL server. I use MAMP on Mac OS X, but you can also run MySQL server in a Docker container.

Install dependencies

npm install

Run tests

The default test target should be sufficient for most contributors:

npm test

If you want to run tests for MySQL alone, run:

npm run test-mysql

There are also SQLite specific tests:

npm run test-sqlite

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

License

MIT

Copyright (c) 2016, 2017 Claudio Procida

adelia's People

Contributors

claudiopro avatar

Watchers

 avatar

adelia's Issues

Design a logo for Adelia

I'd love to give Adelia a nice logo to brand the library.

Requirements:

  • Colorful
  • Kawaii
  • Penguin 🐧

[SQLite] Model.save({ignore: true}) throws error

Apparently INSERT IGNORE is not supported by SQLite:

  base model
    save
      βœ“ persists a new model
      βœ“ updates an existing model (38ms)
      βœ“ opts.force inserts a model when primary key is set
{ [Error: SQLITE_ERROR: near "IGNORE": syntax error] errno: 1, code: 'SQLITE_ERROR' }
      1) opts.ignore inserts ignore a model

Steps to reproduce:

DEBUG=true npm run test-sqlite

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.