Add discover methods for model names and properties

This commit is contained in:
Raymond Feng 2013-04-19 14:11:52 -07:00
parent ad1b2ad7e9
commit 5620be1d57
2 changed files with 38 additions and 0 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ analyse.r
docs/html
docs/man
npm-debug.log
.project

View File

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