<commit_before>var _ = require('alloy/underscore')._, 
	db;

var ALLOY_DB = '_alloy_';

function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};

function guid() {
   return (S4()+S4()+'-'+S4()+'-'+S4()+'-'+S4()+'-'+S4()+S4()+S4());
};	

function InitAdapter(config) {
	if (!db) {
		if (Ti.Platform.osname === 'mobileweb' || typeof Ti.Database === 'undefined') {
			throw 'No support for Titanium.Database in MobileWeb environment.';
		}
		else {
			db = Ti.Database.open('_alloy_');
		}
		module.exports.db = db;
		
		// create the migration table in case it doesn't exist
		db.execute('CREATE TABLE IF NOT EXISTS migrations (latest TEXT, model TEXT)');
	}
	return {};<commit_msg>Add pre-loaded db support for sql adapter<commit_after>var _ = require('alloy/underscore')._, 
	db;

var ALLOY_DB_DEFAULT = '_alloy_';

function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};

function guid() {
   return (S4()+S4()+'-'+S4()+'-'+S4()+'-'+S4()+'-'+S4()+S4()+S4());
};	

function InitAdapter(config) {
	if (!db) {
		if (Ti.Platform.osname === 'mobileweb' || typeof Ti.Database === 'undefined') {
			throw 'No support for Titanium.Database in MobileWeb environment.';
		}
		else {
			var dbfile = config.adapter.db;
			if (dbfile) {
				var rx = /^(\/{0,1})(.+)\.(.+)$/;
				var match = dbfile.match(rx);
				if (match !== null) {
					var file = (match[1] || '/') + match[2] + '.' + match[3];
					var name = match[2];
					db = Ti.Database.install(file, name);
				} else {
					// invalid db file name
				}
			} else {
				db = Ti.Database.open(ALLOY_DB_DEFAULT);
			}
		}
		module.exports.db = db;
		
		// create the migration table in case it doesn't exist
		db.execute('CREATE TABLE IF NOT EXISTS migrations (latest TEXT, model TEXT)');
	}
	return {};
{'fraction_non_alphanumeric': 0.2071625344352617, 'fraction_numerical': 0.02534435261707989, 'mean_word_length': 3.4839506172839507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6244727', 'n_tokens_mistral': 756, 'n_tokens_neox': 662, 'n_words': 151}