Latest 4.0.2
Homepage https://github.com/maopenglin/oc_ORM_Sqlite
License Apache License, Version 2.0 Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Platforms ios , requires ARC
Authors

Objective C 实体对象转换成sql 语句,支持数据类型 int float double number class array

安装

最新的版本 4.0.2

 pod 'ocORM', '~> 4.0.2'

使用

#import "NSObject+ORM.h"

配置数据库路径

 [ORMDB configDBPath:@"/Users/test/dbpath/test.db"];

创建数据库

[ClassInfo createTable];

数据保存


    ClassInfo *classInfo=[[ClassInfo alloc] init];
    [email protected]"三班";
    classInfo.roomId=120;
    [email protected](1);
    [email protected]"北京市海淀区";
    [email protected]{@"a":@"b",@"c":@"d"};

    Student *one=[[Student alloc] init];
    [email protected]"小红";
    one.age=15;

    Student *two=[[Student alloc] init];
    [email protected]"小民";
    two.age=18;

    Teacher *teacher=[[Teacher alloc] init];
    [email protected]"班主任";

    [email protected][one,two].copy;
    classInfo.teacher=teacher;

    //根据classNumber 保存数据    
    [classInfo save:@[@"classNumber"]];

查询数据

    ClassInfo *t=[ClassInfo getObject:@[@"classNumber"] withValue:@[@(1)]];

查询数据列表

    NSMutableArray *arrt=[ClassInfo list:@[@"classNumber"] withValue:@[@(1)] ];

自定义查询并封装为对象

   NSMutableArray *resultArray = [Test queryForObjectArray:@"Select * from Test"];

自定义查询一行记录并封装为字典

 NSMutableDictionary *resultDic = [Test queryForDictionary:@"Select * from Test"];

保存数组

  [arr saveListDataWithKeys:@[@"id"]];

自定义sql操作

[Test execSql:^(SqlOperationQueueObject *db) {
                [db execDelete:@"delte from Test"];//删除sql语句
                [db execUpdate:@"update Test set xxx=x where xxx=x "];//upate sql语句
               BOOL result = [db rowExist:@"select * from Test where xxx=x"];
            }];

清空表数据

    [ClassInfo clearTable];

根据条件删除数据

[Test clearTable:@[@"key1",@[@"key2"]] withValue:@[@"value1",@"value2"]];

模型类方法

ignore column

+(NSArray<NSString *> *_Nonnull)sqlIgnoreColumn;

Set Primary key

+(NSString * _Nonnull)primarilyKey;

Set foreign key

+(NSString * _Nonnull)foreignKey;

foreign update or insert

+(NSDictionary<NSString *, NSString *> *_Nonnull)foreignKeyNotCreateTable;

开启日志调试 运行生成sql语句效果如下

ocORM

Latest podspec

{
    "name": "ocORM",
    "version": "4.0.2",
    "summary": "Objective c u81eau52a8u4fddu5b58u5230u6570u636eu5e93",
    "description": "ocORMu80fdu591fu65b9u4fbfu7684u5c06u5b9eu4f8bu5bf9u8c61u4fddu5b58u5230u6570u636eu5e93uff0cu5e76u652fu6301u961fu5217u540cu6b65uff0cu9632u6b62u6570u636eu5e93u6b7bu9501",
    "homepage": "https://github.com/maopenglin/oc_ORM_Sqlite",
    "license": {
        "type": "Apache License, Version 2.0",
        "text": "    Licensed under the Apache License, Version 2.0 (the "License");n    you may not use this file except in compliance with the License.n    You may obtain a copy of the License atnn    http://www.apache.org/licenses/LICENSE-2.0nn    Unless required by applicable law or agreed to in writing, softwaren    distributed under the License is distributed on an "AS IS" BASIS,n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.n    See the License for the specific language governing permissions andn    limitations under the License.n"
    },
    "authors": {
        "u6bdbu9e4fu9716": "[email protected]"
    },
    "platforms": {
        "ios": null
    },
    "source": {
        "git": "https://github.com/maopenglin/oc_ORM_Sqlite.git",
        "tag": "v4.0.2"
    },
    "source_files": "ORMDB/ORM/*.{h,m}",
    "libraries": "sqlite3",
    "requires_arc": true
}

Pin It on Pinterest

Share This