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

本文介绍了YTKKeyValueStore,一个用于iOS应用的数据存储类库。它支持字符串、数字及复杂对象的存储与检索,并提供了创建数据库、表的操作及数据增删查改等功能。
//
//   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

转载于:https://www.cnblogs.com/hxwj/p/4635770.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值