This is an Arrow connector to Postgres.
$ appc install connector/postgres --save
A configuration file is generated for you. By default we use a host of localhost
, a user of root
and an
empty password to connect. However, you must set a database in your configuration.
The Postgres connector will automatically generate models from the tables in your database. You will not normally need to define them yourself.
To reference a model, use Arrow.getModel
var Arrow = require('arrow');
var User = Arrow.getModel('postgres/users');
If you need to explicitly specify the schema, you can do so in the model name.
var User = Arrow.getModel('postgres/my_schema.users');
You can only reference schemas whitelisted in the schemas
config option. Do not specify a schema name if your schema is already in the search_path
.
onAllocateConnection
(connection, request, response, done)
: Hook function called when a pool connection is allocated. If the connection is being allocated within the context of a HTTP request, request
and response
will have their appropriate values from the framework. Otherwise, they will be null. done
must be called after the hook is complete.
onDeallocateConnection
(connection, request, response, done)
: Hook function called right before a connection is returned to the pool. The behavior of request
and response
are the same as in onAllocateConnection
. done
must be called after the hook is complete.
readReplicaHosts
(optional): Array of alternate read-replica hosts to connect to for read-only queries.
var Account = Arrow.Model.extend('Account',{
fields: {
Name: { type: String, required: true, validator: /[a-zA-Z]{3,}/ }
},
connector: 'postgres'
});
If you want to map a specific model to a specific table, use metadata. For example, to map the account
model to the table named accounts
, set it such as:
var Account = Arrow.Model.extend('account',{
fields: {
Name: { type: String, required: false, validator: /[a-zA-Z]{3,}/ }
},
connector: 'postgres',
metadata: {
'postgres': {
table: 'accounts'
}
}
});
This section is for individuals developing the Postgres Connector and not intended for end-users.
npm install
node app.js
To use the tests, you'll want to create a database with the following tables:
CREATE TABLE post
(
id SERIAL PRIMARY KEY,
title VARCHAR(255),
content VARCHAR(255)
);
CREATE TABLE super_post
(
id SERIAL PRIMARY KEY,
title VARCHAR(255),
content VARCHAR(255)
);
CREATE TABLE employee
(
id SERIAL PRIMARY KEY,
first_name VARCHAR(255),
last_name VARCHAR(255),
email_address VARCHAR(255)
);
npm test
This project is open source and licensed under the Apache Public License (version 2). Please consider forking this project to improve, enhance or fix issues. If you feel like the community will benefit from your fork, please open a pull request.
Appcelerator is a registered trademark of Appcelerator, Inc. Arrow and associated marks are trademarks of Appcelerator. All other marks are intellectual property of their respective owners. Please see the LEGAL information about using our trademarks, privacy policy, terms of usage and other legal information at http://www.appcelerator.com/legal.