From 5620be1d57c5e2cfb4b1767ffc5080d286b1aa38 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 19 Apr 2013 14:11:52 -0700 Subject: [PATCH] Add discover methods for model names and properties --- .gitignore | 1 + lib/schema.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/.gitignore b/.gitignore index 25580433..bd50fea5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ analyse.r docs/html docs/man npm-debug.log +.project diff --git a/lib/schema.js b/lib/schema.js index b5accdd7..a8ed2e8b 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -360,6 +360,43 @@ Schema.prototype.autoupdate = function (cb) { } }; +/** + * Discover existing database tables. + * This method returns an array of model objects, including {type, name, onwer} + * + * @param options An object that contains the following settings: + * all: true - Discovering all models, false - Discovering the models owned by the current user + * views: true - Including views, false - only tables + * limit: The page size + * offset: The starting index + */ +Schema.prototype.discoverModels = function (options, cb) { + this.freeze(); + if (this.adapter.discoverModels) { + this.adapter.discoverModels(options, cb); + } else if (cb) { + cb(); + } +}; + +/** + * Discover properties for a given model. + * @param options An object that contains the following settings: + * model: The model name + * limit: The page size + * offset: The starting index + * The method return an array of properties, including {owner, tableName, columnName, dataType, dataLength, nullable} + */ +Schema.prototype.discoverModelProperties = function (options, cb) { + this.freeze(); + if (this.adapter.discoverModelProperties) { + this.adapter.discoverModelProperties(options, cb); + } else if (cb) { + cb(); + } +}; + + /** * Check whether migrations needed * This method make sense only for sql adapters.