Adding new data source
This commit is contained in:
parent
bcef4c88cf
commit
1e1a227f86
|
@ -467,7 +467,7 @@ Define a data source for persisting models.
|
|||
password: 'password'
|
||||
});
|
||||
|
||||
#### dataSource.createModel(name, options, settings)
|
||||
#### dataSource.createModel(name, properties, settings)
|
||||
|
||||
Define a model and attach it to a `DataSource`.
|
||||
|
||||
|
|
14
index.js
14
index.js
|
@ -2,4 +2,16 @@
|
|||
* asteroid ~ public api
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/asteroid');
|
||||
var asteroid = module.exports = require('./lib/asteroid');
|
||||
|
||||
/**
|
||||
* Connector
|
||||
*/
|
||||
|
||||
asteroid.Connector = require('./lib/connector');
|
||||
|
||||
/**
|
||||
* JugglingDB Connector
|
||||
*/
|
||||
|
||||
asteroid.JdbConnector = require('./lib/jdb-connector');
|
|
@ -93,17 +93,4 @@ app.remoteObjects = function () {
|
|||
|
||||
app.remotes = function () {
|
||||
return this._remotes || (this._remotes = RemoteObjects.create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a remote data source.
|
||||
*
|
||||
* @param name {String}
|
||||
* @param options {Object}
|
||||
* @returns {DataSource}
|
||||
*/
|
||||
|
||||
app.dataSource = function (name, options) {
|
||||
var dataSources = this.dataSources || (this.dataSources = {});
|
||||
return (dataSources[name] = new DataSource(options.adapter, options));
|
||||
}
|
|
@ -6,7 +6,9 @@ var express = require('express')
|
|||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, proto = require('./application')
|
||||
, utils = require('express/node_modules/connect').utils;
|
||||
, utils = require('express/node_modules/connect').utils
|
||||
, DataSource = require('jugglingdb').DataSource
|
||||
, ModelBuilder = require('jugglingdb').ModelBuilder;
|
||||
|
||||
/**
|
||||
* Expose `createApplication()`.
|
||||
|
@ -66,4 +68,22 @@ fs.readdirSync(path.join(__dirname, 'middleware')).forEach(function (m) {
|
|||
* Error handler title
|
||||
*/
|
||||
|
||||
asteroid.errorHandler.title = 'Asteroid';
|
||||
asteroid.errorHandler.title = 'Asteroid';
|
||||
|
||||
/**
|
||||
* Create a data source with passing the provided options to the connector.
|
||||
*/
|
||||
|
||||
asteroid.createDataSource = function (options) {
|
||||
var connector = options.connector;
|
||||
var jdbAdapter = connector.jdbAdapter;
|
||||
|
||||
if(jdbAdapter) {
|
||||
// TODO remove jdb dependency
|
||||
delete options.connector;
|
||||
return new DataSource(jdbAdapter, options);
|
||||
} else {
|
||||
// TODO implement asteroid data source
|
||||
throw Error('unsupported adapter')
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* Expose `Connector`.
|
||||
*/
|
||||
|
||||
module.exports = Connector;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
, debug = require('debug')('connector')
|
||||
, util = require('util')
|
||||
, inherits = util.inherits
|
||||
, assert = require('assert');
|
||||
|
||||
/**
|
||||
* Create a new `Connector` with the given `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Connector}
|
||||
*/
|
||||
|
||||
function Connector(options) {
|
||||
EventEmitter.apply(this, arguments);
|
||||
this.options = options;
|
||||
|
||||
debug('created with options', options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `EventEmitter`.
|
||||
*/
|
||||
|
||||
inherits(Connector, EventEmitter);
|
||||
|
||||
/*!
|
||||
* Create an adapter instance from a JugglingDB adapter.
|
||||
*/
|
||||
|
||||
Connector._createJDBAdapter = function (jdbModule) {
|
||||
var fauxSchema = {};
|
||||
jdbModule.initialize(fauxSchema, function () {
|
||||
// connected
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
* Add default crud operations from a JugglingDB adapter.
|
||||
*/
|
||||
|
||||
Connector.prototype._addCrudOperationsFromJDBAdapter = function (adapter) {
|
||||
|
||||
}
|
|
@ -1,5 +1,10 @@
|
|||
describe('asteroid', function() {
|
||||
|
||||
describe('asteroid.createDataSource(options)', function(){
|
||||
it('Create a data sources with a connector.', function(done) {
|
||||
done(new Error('not implemented'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('asteroid.remoteMethod(Model, fn, [options]);', function() {
|
||||
it("Expose a remote method.", function(done) {
|
||||
/* example -
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe('DataSource', function() {
|
||||
|
||||
describe('dataSource.createModel(name, options, settings)', function() {
|
||||
describe('dataSource.createModel(name, properties, settings)', function() {
|
||||
it("Define a model and attach it to a `DataSource`.", function(done) {
|
||||
/* example -
|
||||
var Color = oracle.createModel('color', {name: String});
|
||||
|
|
Loading…
Reference in New Issue