Giter Site home page Giter Site logo

postgres-adapter's Introduction

JugglingDB-Postgres Build Status

PostgreSQL adapter for JugglingDB.

Usage

To use it you need [email protected].

  1. Setup dependencies in package.json:

    {
      ...
      "dependencies": {
        "jugglingdb": "0.2.x",
        "jugglingdb-postgres": "latest"
      },
      ...
    }
  2. Use:

        var Schema = require('jugglingdb').Schema;
        var schema = new Schema('postgres', {
            database: 'myapp_test',
            username: 'postgres'
            // host: 'localhost',
            // port: 5432,
            // password: s.password,
            // database: s.database,
            // ssl: true,
            // debug: false
        });

Additional Features

  1. Support for float datatypes, ala the mysql adapter. Just add dataType: 'float' to your column properties:
var Model = schema.define('Model', {
  realNumber: {type: Number, dataType: 'float'}
});
  1. Support for single and multi-column indexes, ala the mysql adapter. Single column indexes are specified by adding index: true to the column properties. Unique single-column indexes are created by adding unique: true to the column properties (it is unnecessary to also specify index: true since it is implied). Multi-column indexes are added by specifying indexes in the settings hash of the schema.define method. Single-column indexes may also be specified this way if you want to have a little more control over their options. Each key in the indexes hash is the name of the index, and the value is a hash which specifies the index properties:
var Model = schema.define('Model', {
  column1: {type: Number, index: true},
  column2: {type: Number}
}, {
  indexes: {
    indexName1: {
      columns: 'column1, column2',
      type: 'btree'
    }
  }
});

The full list of supported index properties are:

{
  columns: 'comma, delimited, list, of, columns',
  keys: ['array', 'of', 'columns'],   // takes precedence over "columns"!
  type: 'TYPE',                       // 'btree', 'hash', etc
  kind: 'KIND'                        // 'unique' is the only valid option
}

See the postgres documentation for more information about type and kind.

  1. Support for arbitrary where clauses:
Model.all({where: {arbitrary: 'RANDOM STRING DOING ANYTHING'}}, function(err, models) {
  ...
});

You can still have columns named arbitrary in your models; those will take precedence if found.

Note: This is a perfect moment to discuss the unwise nature of passing filter objects from the client to the server. Don't do it. Expose endpoints which then call all() with known arguments.

  1. Support for an 'or' operator in where clauses. For example, you can look for models which either have a matching userId, or the same ip with a created date greater than one day ago:
var where = {
  or: [{
    userId: 5
  },{
    ip: req.ip,
    created: {
      gt: oneDayAgo
    }
  }]
}
Model.all({where: where}, function(err, models) {
  ...
});

Similar to the arbitrary operator above, any column named or in your model will take precedence if found.

Running tests

npm test

MIT License

Copyright (C) 2012 by Anatoliy Chakkaev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

postgres-adapter's People

Contributors

1602 avatar bmatcuk avatar scottnonnenberg avatar namtzigla avatar harish2704 avatar ivanrodriguezfernandez avatar bhuisgen avatar dbryand avatar eduard-ishmukhametov avatar quilime avatar wangfei0001 avatar martinell avatar radzikowski avatar roryf avatar scttnlsn avatar sdrdis avatar jinze avatar bradfordh avatar

Watchers

 avatar 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.