Skip to content
MiguelMadero edited this page Oct 16, 2012 · 14 revisions

We currently support mongo, riak, postgres and a memory model adapter which is useful for testing purposes.

Pre-requisites

We assume that you already have a DB installed and the native components that you may need. At the end of this document we provide some links that can help you get started with this.

Specifying a Model Adapter

Most applications will only use one model adapter. However, geddy provides the flexibility to overrides per model. This way you might store some of your models in postgres and others in mongo.

Setting a Default Model Adapter

In your config/development.js (or production.js) you can specify a modelAdapter

var config = {
  model: {
    defaultAdapter: 'memory'
  }
};

Setting a per-model Model Adapter

Inside your model's constructor function specify the desired adapter, for example

this.adapter = 'postgres';

Model adapter configuration

The adapter's configuration is also set in config/development.js (or production.js) you have to specify your model adapter settings. Each modelAdapter has specific configuration so we will cover them individually.

Mongo

Install the mongodb wrapper for node.

npm install mongodb-wrapper

Edit your config file with your connection settings.

var config = {
  // Other settings
, model: {
    defaultAdapter: 'mongo'
  }
, db: {
  mongo: {
    dbname: 'model_test'
  }
};

If you are deploying on a multi-user server, it is probably best to use mongodb in secure mode, ie. with authentication. See mongodb security. In this case, you'll need more settings in config. For example:

var config = {
  // Other settings
, model: {
    defaultAdapter: 'mongo'
  }
, db: {
  mongo: {
    dbname: 'model_test'
  , port: 27017
  , host: 'localhost'
  , prefix: 'mongodb'
  , username: 'adminguy'
  , password: 'adminpass'
  }
};

Postgres

Install the postgres client for node.

npm install pg

Edit your config file with your connection settings.

var config = {
  // Other settings
  , model: {
    defaultAdapter: 'postgres'
  }
  , db: {
    postgres: {
      port: 5432
    , password: 'supersecurepassword'
    , database: 'dbname'
    , host: 'localhost'
    , user: 'user' 
    }
  }
};

Links