DBHelp
示例
要运行示例项目,首先克隆仓库,然后在 Example 目录下运行 pod install
。
安装
DBHelp 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中
pod 'DBHelp'
支持
支持 create, count, select, insert, update, delete, between ... and ... 等语句
创建
创建表
SQLTable *table = [SQLTable table:@"table1"];
table.create.column(@"age", eSQLBindTypeInteger);
table.create.newColumn(@"id", eSQLBindTypeInteger).primaryKey();
table.create.newColumn(@"name", eSQLBindTypeText).unique().notNull();
table.create.newColumn(@"company", eSQLBindTypeText).defaultValue(@"home");
table.create.newColumn(@"createtime", eSQLBindTypeReal);
table.create.sqlExpression();
--> CREATE TABLE table1 ( id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL, age INTEGER, company TEXT DEFAULT 'home', createtime REAL );
选择
table.select.where(@"age").equal(@28);
table.select.sqlExpression();
--> SELECT * FROM table1 where age = 28;
计数
table.select.column(@"name").count.columnAsAlias(@"height", @"").columnAsAlias(@"company", @"company别名").where(@"age").between(20, 27);
table.select.sqlExpression();
--> SELECT COUNT(name, height, company AS company别名) FROM table1 where age between 20 and 27;
插入
table.insert.columns(@"id", @"name", @"age", @"company", @"createtime", nil).values([NSNull null], @"Ray", @28, [NSNull null], @4145123.4, nil);
table.insert.sqlExpression();
--> INSERT INTO table1 ( id, name, age, company, createtime ) VALUES ( null, 'Ray', 28, null, 4145123.4 );
更新
table.update.set(@"company", @"update").set(@"age", @24);
table.update.sqlExpression();
--> UPDATE table1 SET company = 'update', age = 24;
table.update.set(@"company", @"update").set(@"age", @5).where(@"name").equal(@"Ray");
table.update.sqlExpression();
--> UPDATE table1 SET company = 'update', age = 25 where name = 'Ray';
删除 && 符号
table.deleteColumn.where(@"age").symbol(@">", @4);
table.deleteColumn.sqlExpression();
--> DELETE FROM table1 where age > 4;
条件
table.select.where(@"age").symbol(@">", @4).andCondition(@"name").equal(@"Ray").andCondition(@"salary").symbol(@">", @25000).andCondition(@"height").between(@150, @160);
table.select.sqlExpression();
--> SELECT * FROM table1 where age > 4 AND name = 'Ray' AND salary > 25000 AND 3 between 150 and 160;
[table.select.where(@"age").symbol(@">", @4).andCondition(@"height") inRange:@133, @144, @155, @166, nil];
table.select.sqlExpression();
--> SELECT * FROM table1 where age > 4 AND height IN (133, 144, 155, 166);
修改
table.alter.addColumn(@"age", eSQLBindTypeInteger).unique().notNull();
作者
许可证
DBHelp可在MIT许可下使用。有关更多信息,请参阅LICENSE文件。