• 数据库键-值方式存储封装


    //
    //  YTKKeyValueStore.h
    //  Ape
    //
    //  Created by TangQiao on 12-11-6.
    //  Copyright (c) 2012年 TangQiao. All rights reserved.
    //

    #import <Foundation/Foundation.h>

    @interface YTKKeyValueItem : NSObject

    @property (strong, nonatomic) NSString *itemId;
    @property (strong, nonatomic) id itemObject;
    @property (strong, nonatomic) NSDate *createdTime;

    @end


    @interface YTKKeyValueStore : NSObject

    /**
     *  打开数据库不存在在沙盒中创建
     *
     *  @param dbName 数据库的名字test.db
     *
     
    */
    - (id)initDBWithName:(NSString *)dbName;
    /**
     *  工程路径打开数据库
     *
     *  @param dbPath 工程路径
     *
     
    */
    - (id)initWithDBWithPath:(NSString *)dbPath;
    /**
     *  创建表
     *
     *  @param tableName 表的名字
     
    */
    - (void)createTableWithName:(NSString *)tableName;

    - (BOOL)isTableExists:(NSString *)tableName;
    /**
     *  清除表
     
    */
    - (void)clearTable:(NSString *)tableName;
    /**
     *  关闭数据库
     
    */
    - (void)close;

    ///************************ Put&Get methods *****************************************

    //存入(NSString, NSNumber, NSDictionary和NSArray)修改和添加
    - (void)putString:(NSString *)string withId:(NSString *)stringId intoTable:(NSString *)tableName;
    - (void)putObject:(id)object withId:(NSString *)objectId intoTable:(NSString *)tableName;
    - (void)putNumber:(NSNumber *)number withId:(NSString *)numberId intoTable:(NSString *)tableName;
    //取出 (NSString, NSNumber, NSDictionary和NSArray)
    - (id)getObjectById:(NSString *)objectId fromTable:(NSString *)tableName;
    - (NSString *)getStringById:(NSString *)stringId fromTable:(NSString *)tableName;
    - (NSNumber *)getNumberById:(NSString *)numberId fromTable:(NSString *)tableName;
    //删除
    - (void)deleteObjectById:(NSString *)objectId fromTable:(NSString *)tableName;
    - (void)deleteObjectsByIdArray:(NSArray *)objectIdArray fromTable:(NSString *)tableName;
    - (void)deleteObjectsByIdPrefix:(NSString *)objectIdPrefix fromTable:(NSString *)tableName;
    //更多接口
    - (YTKKeyValueItem *)getYTKKeyValueItemById:(NSString *)objectId fromTable:(NSString *)tableName;
    //获得所有数据
    - (NSArray *)getAllItemsFromTable:(NSString *)tableName;
    //数量
    - (NSUInteger)getCountFromTable:(NSString *)tableName;




    @end

     github链接:https://github.com/yuantiku/YTKKeyValueStore

     百度云盘:http://pan.baidu.com/s/1jG9w6EU

  • 相关阅读:
    [置顶] Codeforces Round #198 (Div. 1)(A,B,C,D)
    Python基础 1----Python语言基础和Python环境准备与安装
    UVa 10400
    Linux多线程——使用互斥量同步线程
    SICP 习题 (1.8) 解题总结
    浙江大学PAT上机题解析之1014. 福尔摩斯的约会 (20)
    3.11 程序改错
    汉语-汉字:芔
    汉语-汉字:屮
    汉语-汉字:艸
  • 原文地址:https://www.cnblogs.com/hxwj/p/4635770.html
Copyright © 2020-2023  润新知