<commit_before>var _ = require('underscore');
var analyzer = require('sql-analyzer');
var strformat = require('strformat');
var handlebars = require('handlebars');
var path = require('path');
var fs = require('fs');
var jpath = require('jpath');
var os = require("os");
/*
	options = {
		//建表的sql列表
		createSql: [],
		//可以指定sqlite的路径
		sqlitePath: "",
		//是否允许出现下划线，如果不允许，则将user_name转换为userName
		allowUnderscore: false,
	}
 */

var entityMaker = function(saveTo, options){
	this.dothFile = "template-h.handlebars";
	this.dotmFile = "template-m.handlebars";
	//保存到文件夹，默认保存到当前目录
	this.saveToFolder = saveTo || path.join(os.tmpdir(), "peaksqlite-entity");
	if(!fs.existsSync(this.saveToFolder)){
		//文件夹不存在，创建一个
		fs.mkdirSync(this.saveToFolder, 0755);
	}

	this.options = _.extend({
		allowUnderscore: false,
		//类名的格式化
		classFormatter: '{0}Entity'
	}, options);

	//sqlite与cocoa数据类型的影射
	this.mapping = {
		'boolean': {
			cocoaType: 'BOOL',
			//将参数压入到NSArray时的转换
			parameter: '[NSNumber numberWithBool: self.{0}]',
			//从dict中转换转换到cocoa的属性
			parse: '[[self.data objectForKey:@"{0}"] boolValue]',
			defaultValue: 'NO'
		},
		//pointer：是否为指针
		'text': {
			cocoaType: 'NSString',
			pointer: true,
			parameter: '[PeakSqlite nilFilter: self.{0}]',
			parse: '[PeakSqlite valueToString: [data objectForKey:@"{0}"]]',
			defaultValue: 'nil'
		},
		'integer': {
			cocoaType: 'NSInteger',
			parameter: '[NSNumber numberWithInt: self.{0}]',
			parse: '[[data objectForKey:@"{0}"] intValue]',
			defaultValue: '0'
		},
		'float': {
			cocoaType: 'double',
			parameter: '[NSNumber numberWithDouble: self.{0}]',
			parse: '[[data objectForKey:@"{0}"] doubleValue]',
			defaultValue: '0.0'
		},
		'date': {
			cocoaType: 'NSDate',
			pointer: true,
			parameter: '[PeakSqlite dateToValue: self.{0}]',
			parse: '[PeakSqlite valueToDate: [data objectForKey:@"{0}"]]',
			defaultValue: 'nil'
		},
		//如果属性是字符，则影射mapping的某个类型
		'datetime': 'date'
	};
}

//执行某个任务
entityMaker.prototype.run = function(schema, sql){
	//如果参数是sql语句，则先分析出schema
	if(typeof(schema) == 'string'){
		sql = schema;
		schema = analyzer.analyseWithSql(schema);
	}
	this.makeOne(schema, sql);
}

//大写第一个字母
entityMaker.prototype.upperFirstLetter = function(text){
	return text.replace(/^\w/, function(a, b){return a.toUpperCase()});
}<commit_msg>加入int的影射<commit_after>var _ = require('underscore');
var analyzer = require('sql-analyzer');
var strformat = require('strformat');
var handlebars = require('handlebars');
var path = require('path');
var fs = require('fs');
var jpath = require('jpath');
var os = require("os");
/*
	options = {
		//建表的sql列表
		createSql: [],
		//可以指定sqlite的路径
		sqlitePath: "",
		//是否允许出现下划线，如果不允许，则将user_name转换为userName
		allowUnderscore: false,
	}
 */

var entityMaker = function(saveTo, options){
	this.dothFile = "template-h.handlebars";
	this.dotmFile = "template-m.handlebars";
	//保存到文件夹，默认保存到当前目录
	this.saveToFolder = saveTo || path.join(os.tmpdir(), "peaksqlite-entity");
	if(!fs.existsSync(this.saveToFolder)){
		//文件夹不存在，创建一个
		fs.mkdirSync(this.saveToFolder, 0755);
	}

	this.options = _.extend({
		allowUnderscore: false,
		//类名的格式化
		classFormatter: '{0}Entity'
	}, options);

	//sqlite与cocoa数据类型的影射
	this.mapping = {
		'boolean': {
			cocoaType: 'BOOL',
			//将参数压入到NSArray时的转换
			parameter: '[NSNumber numberWithBool: self.{0}]',
			//从dict中转换转换到cocoa的属性
			parse: '[[self.data objectForKey:@"{0}"] boolValue]',
			defaultValue: 'NO'
		},
		//pointer：是否为指针
		'text': {
			cocoaType: 'NSString',
			pointer: true,
			parameter: '[PeakSqlite nilFilter: self.{0}]',
			parse: '[PeakSqlite valueToString: [data objectForKey:@"{0}"]]',
			defaultValue: 'nil'
		},
		'integer': {
			cocoaType: 'NSInteger',
			parameter: '[NSNumber numberWithInt: self.{0}]',
			parse: '[[data objectForKey:@"{0}"] intValue]',
			defaultValue: '0'
		},
		'float': {
			cocoaType: 'double',
			parameter: '[NSNumber numberWithDouble: self.{0}]',
			parse: '[[data objectForKey:@"{0}"] doubleValue]',
			defaultValue: '0.0'
		},
		'date': {
			cocoaType: 'NSDate',
			pointer: true,
			parameter: '[PeakSqlite dateToValue: self.{0}]',
			parse: '[PeakSqlite valueToDate: [data objectForKey:@"{0}"]]',
			defaultValue: 'nil'
		},
		//影射int为integer
		'int': 'integer',
		//如果属性是字符，则影射mapping的某个类型
		'datetime': 'date'
	};
}

//执行某个任务
entityMaker.prototype.run = function(schema, sql){
	//如果参数是sql语句，则先分析出schema
	if(typeof(schema) == 'string'){
		sql = schema;
		schema = analyzer.analyseWithSql(schema);
	}
	this.makeOne(schema, sql);
}

//大写第一个字母
entityMaker.prototype.upperFirstLetter = function(text){
	return text.replace(/^\w/, function(a, b){return a.toUpperCase()});
}
{'fraction_non_alphanumeric': 0.1852568235546959, 'fraction_numerical': 0.007736943907156673, 'mean_word_length': 4.54047619047619, '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': '6146251', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1950, 'n_words': 315}