Giter VIP home page Giter VIP logo

firenze's Introduction

firenze.js

Build Status npm Join the chat at https://gitter.im/fahad19/firenze

A database agnostic adapter-based object relational mapper (ORM) targetting node.js and the browser.

Visit http://firenze.js.org for documentation.

Key features

  • Database agnostic Adapter based architecture
  • Intituitive query builder
  • Migrations API (with rollback)
  • Highly extensible with Behavior pattern for Collections and Models
  • Promise based workflow
  • Strong and flexible validation system
  • CLI support
  • API for Transactions for supported adapters
  • Footprint of ~40kB minified file

The project is still under active development, and more features are expected to land in future releases.

Installation

With npm:

$ npm install --save firenze

Or Bower:

$ bower install --save firenze

Available adapters

Supports v0.2.x:

Available behaviors

Testing

Tests are written with mocha, and can be run via npm:

$ npm test

Thanks

The project couldn't have happened if there weren't other projects to be inspired from. A big thanks goes to these open source projects that directly or indirectly helped make it possible:

License

MIT © Fahad Ibnay Heylaal

firenze's People

Contributors

fahad19 avatar gitter-badger avatar mortonfox 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  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

firenze's Issues

Promise as a class

return bluebird from within the module, so adapters can re-use it. also would be useful if lazy-promises are implemented in later versions.

/* src/Promise.js */

module.exports = require('bluebird');

Model: Throw error if collection class isn't an instance

Maybe I'm missing something but I don't think Model.collection() is exhibiting the expected behavior in the case where it's being called from a Model with a badly-configured collectionClass.

The way I see it, if new C(options) isn't an instance, that function should throw an error, not return a new object (which won't be an instance either). There also doesn't really seem to be the need for the isInstance() function as, excluding the duplicated code block, it's called just the once.

Relevant code: https://github.com/fahad19/firenze/blob/master/src/Model.js#L418-L440

PS - Low hanging fruit for duplicated code: #37

Database should also accept an instance of Adapter

Right now, the class itself is passed when creating a new Database instance:

var f = require('firenze');

var db = new f.Database({
  adapter: MysqlAdapter
});

Make it possible so an instance can be set too, that way some adapters can be configured in a certain way:

var db = new f.Database(
  adapter: new MysqlAdapter(customConfig)
);

Shortcut method for finding a record

model.find(1);

// which should be equivalent to:
model.find('first', {
  conditions: {
    id: 1
  }
});

OR:

model.findById();
model.findByKey();
model.findBy(field, options = {});

count not working

From the examples for fetching records and counting in the guide I am getting .find(...).where(...).count(...).then is not a function

My function looks like this

router.get('/count', function (req, res, next) {
  var users = new UsersCollection();
  users.find()
    .where({})
    .count()
    .then(function (count) {
      console.log('Total number of published posts:', count);
    });
});

Browser support?

Hey, awesome project! Wondering whether browser support is in the roadmap?

[security] Parameterized queries / prepared statements

Knex (the query builder this ORM uses) does not construct prepared statements to make queries. Parameterized queries are the correct way to construct SQL statements to efficiently and safely protect against SQLi attacks.

I'm aware of at least two other libraries that correctly construct SQL queries, and each supports a variety of databases (although sequel does not support sqlite):

Perhaps this library could switch from Knex to one of those? (My personal preference is with node-sql since it supports sqlite).

Collection: global conditions

like:

var posts = new Posts({
  conditions: {
    published: true
  }
});

all future posts.find()s would return published posts only.

Lazy queries

Since they are all promises, figure a way out for for making the actual query only after .then() is called.

Model: callbacks

support callbacks like these at Model level:

  • beforeValidate()
  • afterValidate()
  • beforeSave()
  • afterSave()
  • beforeDelete()
  • afterDelete()

also support these methods without callbacks too (by passing something like {callbacks: false} in options:

  • save()
  • delete()
  • validate()

sum() column function not working properly

I am trying to get the sum of a column but it's not working properly. it returns an array of rows rather than a single value. My code looks like this:

pendings.find()
    .select(function (column) {
      return column('amount')
        .sum();
    })
    .all()
    .then(function (models) {}):

Getting Data Out

I'm fairly new to this and I've figured out how to use firenze to query a database and get results but I cannot get my results to the global scope to use elsewhere in my code. How do you get the results out?

var f = require('firenze');
var Database = f.Database;
var MysqlAdapter = require('firenze-adapter-mysql');

var db = new Database({
    adapter: MysqlAdapter,
    host: '127.0.0.1',
    database: 'jlg',
    user: 'root',
    password: ''
});

var Records = db.createCollection({
  table: 'questions',
  alias: 'qs',
});

var questions = new Records();
var STORE_RESULTS_HERE = "";

questions.find()
  .where({
    id: 1
  })
  .first()
  .then(function (questions) {

    // or convert to plain object
    var questionObject = questions.toJSON();
    var answer = questionObject.answer;
   STORE_RESULTS_HERE = answer;
  });

 console.log(STORE_RESULTS_HERE); //returns empty string

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.