li6185377 / LKDBHelper-SQLite-ORM

全自动的插入,查询,更新,删除, an automatic database operation thread-safe and not afraid of recursive deadlock
MIT License
1.21k stars 288 forks source link

有没有过滤不需要写入数据库的属性的功能 #123

Closed HelloZhu closed 6 years ago

HelloZhu commented 6 years ago

有没有过滤不需要写入数据库的属性的功能

natewang commented 6 years ago

initialize 时候删除就好。见demo里的LKTestModels

//在类 初始化的时候
+(void)initialize
{
    //remove unwant property
    //比如 getTableMapping 返回nil 的时候   会取全部属性  这时候 就可以 用这个方法  移除掉 不要的属性
    [self removePropertyWithColumnName:@"error"];

    //simple set a column as "LKSQL_Mapping_UserCalculate"
    //根据 属性名  来启用自己计算
    //[self setUserCalculateForCN:@"error"];

    //根据 属性类型  来启用自己计算
    //[self setUserCalculateForPTN:@"NSDictionary"];

    //enable own calculations
    //[self setUserCalculateForCN:@"address"];

    //enable the column binding property name
    [self setTableColumnName:@"MyAge" bindingPropertyName:@"age"];
    [self setTableColumnName:@"MyDate" bindingPropertyName:@"date"];
}
ekingo commented 6 years ago

属性是readonly的会过滤掉。

///过滤只读属性
        if ([propertyType rangeOfString:@",R,"].length > 0 || [propertyType hasSuffix:@",R"]) {
            NSString *firstWord = [[propertyName substringToIndex:1] uppercaseString];
            NSString *otherWord = [propertyName substringFromIndex:1];
            NSString *setMethodString = [NSString stringWithFormat:@"set%@%@:", firstWord, otherWord];
            SEL setSEL = NSSelectorFromString(setMethodString);
            ///有set方法就不过滤了
            if ([self instancesRespondToSelector:setSEL] == NO) {
                continue;
            }
        }