<commit_before>"use strict"
var puree = require('../index'),
	glob = require("glob"),
	debug = require('debug')('koala-puree:models'),
	waterline = require('waterline'),
	fdbsql = require("sails-fdbsql");
var config = {
	adapters: {
		'sails-fdbsql': fdbsql
	},
	connections: {
		fdbsql: {
			adapter: 'sails-fdbsql',
			url: 'fdb://root:root@localhost:15432/eskygo',
		}
	}
}

function genModel(file, name, remove) {
	remove = remove === undefined ? false : remove;
	var path = require('path').join(process.cwd(),file), schema;
	if ( remove ) {
		delete require.cache[path];
	}
	schema = require(path);
	schema.connection = 'fdbsql'
	schema.tableName = name;
	return require('waterline').Collection.extend(schema);
}

var pureeorm = exports = module.exports = function(){

	var orm;
	return {
		setup: function *(app, next) {
			return new Promise(function(resolve, reject) {
				orm = app._orm = new waterline();
				var update = function(){
					var fs = require('fs');
					glob("models/*.js", function (er, files) {
						if ( er ) { return reject(er); }
						for ( var f of files ) {
							var name = f.substr(7,f.length-10)
							orm.loadCollection(genModel(f, name, app._app.env !== "production"))
							debug(`loaded ${name} into app.models`);
						}<commit_msg>making db configurable<commit_after>"use strict"
var puree = require('../index'),
	glob = require("glob"),
	debug = require('debug')('koala-puree:models'),
	waterline = require('waterline'),
	fdbsql = require("sails-fdbsql");
var DEFAULTCONFIG = {
	adapters: {
		'sails-fdbsql': fdbsql
	},
	connections: {
		fdbsql: {
			adapter: 'sails-fdbsql'
		}
	}
}

function genModel(file, name, remove) {
	remove = remove === undefined ? false : remove;
	var path = require('path').join(process.cwd(),file), schema;
	if ( remove ) {
		delete require.cache[path];
	}
	schema = require(path);
	schema.connection = 'fdbsql'
	schema.tableName = name;
	return require('waterline').Collection.extend(schema);
}

var pureeorm = exports = module.exports = function(){

	var orm;
	return {
		setup: function *(app, next) {
			return new Promise(function(resolve, reject) {
				var dburl;
				if ( app._config.db ) {
					if ( !app._config.db.url ) {
						let username = app._config.db.username || "root";
						let password = app._config.db.password || "<PASSWORD>";
						let host = app._config.db.host || "localhost";
						let port = app._config.db.port || "15432";
						let dbname = app._config.dbname || app._config.name;
						if ( !dbname ) {
							return reject("dbname or package name has to be provided");
						}
						if ( app._app.env !== "production" ) {
							dbname = `${dbname}-${app._app.env}`;
						}
						dburl = `fdb://${username}:${password}@${host}:${port}/${dbname}`;
					} else {
						dburl = app._config.db.url
					}
				} else {
					return reject("You have to have dburl defined");
				}
				var config = require('extend')({},DEFAULTCONFIG);
				config.connections.fdbsql.url = dburl;
				orm = app._orm = new waterline();
				var update = function(){
					var fs = require('fs');
					glob("models/*.js", function (er, files) {
						if ( er ) { return reject(er); }
						for ( var f of files ) {
							var name = f.substr(7,f.length-10)
							orm.loadCollection(genModel(f, name, app._app.env !== "production"))
							debug(`loaded ${name} into app.models`);
						}
{'fraction_non_alphanumeric': 0.17231134878193702, 'fraction_numerical': 0.004753416518122401, 'mean_word_length': 3.2405541561712847, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1944560', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1122, 'n_words': 258}