# protolus-data

> A multi source ORM supporting normalized queries across many instances of datasources

Latest version **0.0.5-alpha** (published 2013-06-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install protolus-data
pnpm add protolus-data
yarn add protolus-data
bun add protolus-data
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5-alpha |
| Published | 2013-06-19 |
| First published | 2012-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Abbey Hawk Sparrow |
| Maintainers | khrome |
| Keywords | ORM, DAL, data, mysql, mongo, amqp |

## Links

- npm: https://www.npmjs.com/package/protolus-data
- Repository: https://github.com/Protolus/protolus-data
- Issues: https://github.com/Protolus/protolus-data/issues
- npm.io page: https://npm.io/package/protolus-data

## Dependencies (5)

- [prime](https://npm.io/package/prime.md) 0.0.5-alpha
- [Classy](https://npm.io/package/Classy.md) *
- [bit-mask](https://npm.io/package/bit-mask.md) *
- [prime-ext](https://npm.io/package/prime-ext.md) *
- [where-parser](https://npm.io/package/where-parser.md) *

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.0.5-alpha (latest) — 2013-06-19
- 0.0.4-alpha — 2013-02-05
- 0.0.3-alpha — 2013-02-03
- 0.0.2-alpha — 2012-12-30
- 0.0.1-alpha — 2012-12-12

## README

protolus-data.js
===========

A Node.js data layer supporting mysql/mongo/rabbit using a single SQL based query syntax

Usage
-----

First you'll need to register at least one datasource:

    var MySQLDatasource = require('protolus-data/sources/mysql');
    new MySQLDatasource({
        name : 'maindatabase',
        host : 'localhost',
        user : 'dbuser',
        password : 'P455W0RD',
        database : 'mysqldbname'
    });
    

The basic data pattern looks like:

    var Data = require('protolus-data');
    var MyObject = Data.Container({
        initialize : function MyObject(key){
            this.fields = [
                'id',
                'somefield',
                'anotherfield'
            ];
            this.parent({
                name : 'user',
                datasource : 'maindatabase'
            });
            if(key) this.load(key);
        }
    });
    Data.register('MyObject', MyObject);
    module.exports = MyObject;
    
You would use this class like this:

    var MyObject = Data.require('MyObject');
    var myInstance = new MyObject();
    myInstance.set('somefield', 'somevalue');
    myInstance.set('anotherfield', 49);
    myInstance.save();
    
And you would search for a set using:

    Data.search('MyObject', "somefield == 'searchvalue' || (somefield > 24 && somefield < 38)");
    
or if you only wanted the data payload (not a set of objects)

    Data.query('MyObject', "somefield == 'searchvalue' || (somefield > 24 && somefield < 38)");
    
One thing to note: This data layer is designed to discourage both streaming data sets and joins while normalizing query syntax across datasources. If you need these features or you find this level of indirection uncomfortable you should probably manipulate the DB directly and skip the whole data layer (or even better, interface with an API). 

Virtuals
--------
Sometimes you want to address a field as another field (we use this feature with mongo so you can address the primary key as 'id' rather than '_id'), but you want that reference to be symbolic as far as the DB is concerned. This is simply accomplished:

    object.virtualAlias(virtualName, fieldName);
    
Direct Access
-------------

Other Datasource specific features (for example MapReduce under mongo) must be accessed from the DB driver which may be accessed directly:

    var Data = require('protolus-data');
    Data.Source.get('myAwesomeDatasource').connection;

But when you do this you are circumventing the data layer (other than letting protolus negotiate the connection for you).

Testing
-------
Tests use mocha/should to execute the tests from root

    mocha

If you find any rough edges, please submit a bug!

Enjoy,

-Abbey Hawk Sparrow

---
_Source: https://npm.io/package/protolus-data · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
