Adapter based JavaScript ORM for Node.js and the browser

Overview

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

Comments
  • [security] Parameterized queries / prepared statements

    [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):

    • https://github.com/brianc/node-sql
    • https://hiddentao.github.io/squel/

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

    opened by taoeffect 6
  • count not working

    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);
        });
    });
    
    opened by joeolaoye 2
  • Getting Data Out

    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
    
    opened by Wemperer 2
  • Model: Throw error if collection class isn't an instance

    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

    opened by alexweber 2
  • Database should also accept an instance of Adapter

    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)
    );
    
    opened by fahad19 1
  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    fahad19/firenze now has a Chat Room on Gitter

    @fahad19 has just created a chat room. You can visit it here: https://gitter.im/fahad19/firenze.

    This pull-request adds this badge to your README.md:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

    opened by gitter-badger 0
  • Shortcut method for finding a record

    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 = {});
    
    opened by fahad19 0
  • sum() column function not working properly

    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) {}):
    
    opened by joeolaoye 1
  • Validation: process multiple rules per field, without stopping at first fail

    Validation: process multiple rules per field, without stopping at first fail

    By default, whenever a rule fails, that rule's message is returned and other rules (if any) are not processed for a particular field.

    Allow an option to process multiple rules per field upon failure too.

    For example, in CakePHP: http://book.cakephp.org/2.0/en/models/data-validation.html#last

    Model 
    opened by fahad19 0
  • Model: new instance with default values

    Model: new instance with default values

    For example:

    var Post = db.createModelClass({
      schema: {
        created: {
          type: 'date',
          default: function () {
            return new Date();
          }
        }
      }
    });
    
    Model 
    opened by fahad19 0
Releases(v0.3.1)
Owner
Fahad Heylaal
Fahad Heylaal
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite datab

MikroORM 5.4k Dec 31, 2022
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used

null 30.1k Jan 3, 2023
The Blog system developed by nest.js based on node.js and the database orm used typeorm, the development language used TypeScript

考拉的 Nest 实战学习系列 readme 中有很多要说的,今天刚开源还没来及更新,晚些慢慢写,其实本人最近半年多没怎么写后端代码,主要在做低代码和中台么内容,操作的也不是原生数据库而是元数据Meta,文中的原生数据库操作也当作复习下,数据库的操作为了同时适合前端和Node开发小伙伴,所以并不是很

程序员成长指北 148 Dec 22, 2022
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js

bookshelf.js Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features both Promise-based and traditional callback i

Bookshelf.js 6.3k Jan 2, 2023
A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.

Dittorm A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud. Installatio

Waline 21 Dec 25, 2022
An easy-to-use multi SQL dialect ORM tool for Node.js

Sequelize Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction s

Sequelize 27.3k Jan 4, 2023
An SQL-friendly ORM for Node.js

Objection.js Objection.js is an ORM for Node.js that aims to stay out of your way and make it as easy as possible to use the full power of SQL and the

Vincit 6.9k Jan 5, 2023
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server & SQLite

Prisma Quickstart • Website • Docs • Examples • Blog • Slack • Twitter • Prisma 1 What is Prisma? Prisma is a next-generation ORM that consists of the

Prisma 28k Jan 2, 2023
A high performance MongoDB ORM for Node.js

Iridium A High Performance, IDE Friendly ODM for MongoDB Iridium is designed to offer a high performance, easy to use and above all, editor friendly O

Sierra Softworks 570 Dec 14, 2022
A javascript REST ORM that is offline and real-time capable

Rekord Rekord is an ORM - a way to define properties and relationships - that interacts with local storage, a RESTful service, and a real-time service

Rekord 177 Oct 18, 2022
This is a demo sample of linking NODEJS via ORM and MYSQL

Demons(Demo of Nodejs with SQL) This is a demo sample of linking NODEJS with ORM and MYSQL Connecting Node to SQL is a hard task and not much help is

Shivam Sourav Jha 3 Apr 14, 2022
A typescript data mapping tool. To support mutual transforming between domain model and orm entity.

ts-data-mapper A typescript mapping tool supports mutual transforming between domain model and orm entity. In most case, domain model is not fully com

zed 8 Mar 26, 2022
Ecommerce-backend-nestjs - Ecommerce app with Nestjs + Prisma ORM + GraphQL + SQLite

ECOMMERCE BACKEND NESTJS APP Nestjs + Prisma ORM + GraphQL + SQLite USER Create Account Login Product Create Product Get Products Get Product Search P

Rui Paulo Calei 5 Apr 6, 2022
just a graphql example created by typescript + fastify + mikro-orm(postgresql) + mercurius(graphql adaptor) + type-graphql

fastify-mikro-orm-mercurius-graphql-example A MikroORM boilerplate for GraphQL made with Fastify, Mercurius, Typescript using TypeGraphQL ?? Packages

Vigen 10 Aug 28, 2022
A typesafe database ORM that exposes the full power of handwritten sql statements to the developer.

TORM A typesafe database ORM that exposes the full power of handwritten sql statements to the developer. import { torm, z } from 'https://deno.land/x/

Andrew Kaiser 15 Dec 22, 2022
AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.

Please use version 1.x as prior versions has a security flaw if you use user generated data to concat your SQL strings instead of providing them as a

Andrey Gershun 6.1k Jan 9, 2023
The JavaScript Database, for Node.js, nw.js, electron and the browser

The JavaScript Database Embedded persistent or in memory database for Node.js, nw.js, Electron and browsers, 100% JavaScript, no binary dependency. AP

Louis Chatriot 13.2k Jan 2, 2023
⚡️ lowdb is a small local JSON database powered by Lodash (supports Node, Electron and the browser)

Lowdb Small JSON database for Node, Electron and the browser. Powered by Lodash. ⚡ db.get('posts') .push({ id: 1, title: 'lowdb is awesome'}) .wri

null 18.9k Dec 30, 2022
A WebAssembly build of the Tesseract OCR engine for use in the browser and Node

tesseract-wasm A WebAssembly build of the Tesseract OCR engine for use in the browser and Node. tesseract-wasm can detect and recognize text in docume

Robert Knight 80 Dec 28, 2022