PostgreSQL用のデータアクセスクラスを作成
とりあえず単一テーブルをObjective-CベースでCRUDれるクラスを作った。ヘッダで書くとこんな感じ:
@interface TableInfo : NSObject { } + (TableInfo *)tableInfoWithTableName:(NSString *)tableName primaryKeyNames:(NSSet *)primaryKeyNames; - (NSString *)tableName; - (NSSet *)primaryKeyNames; - (BOOL)isPrimaryKey:(NSString *)keyName; @end @interface SimpleDataAccess : NSObject { } + (SimpleDataAccess *)simpleDataAccessWithConnectionDictionary:(NSDictionary *)connectionDictionary; - (BOOL)insertWithValues:(NSDictionary *)values intoTable:(TableInfo *)tableInfo; - (BOOL)updateWithValues:(NSDictionary *)values inTable:(TableInfo *)tableInfo; - (BOOL)deleteWithValues:(NSDictionary *)values fromTable:(TableInfo *)tableInfo; - (NSArray *)fetchWithCondition:(NSDictionary *)condition fromTable:(TableInfo *)tableInfo;; @end
インスタンス変数とかは削ってありますよ。
機能としては、
- 実装済み
- 単一テーブルのinsert/update/delete(行単位)、select(条件は"="のみ)がNSDictionaryで出来る
- データ型は数値(integer, real, bigint)、文字列(varcharのみ)、時刻(timestampのみ)に対応。
- テーブル名・カラム名はDBから取得した値を直に使用(CamelCapitalizedとか無し)
- 未実装
- トランザクション
POJOPOOO(Plain Old Objective-C Object)対応- 複数テーブルでのselect
- 「=」以外の検索条件
- 楽観ロッキング
- serial使用時のinsert後の自動再取得
- その他多数
なところ。複数テーブルでのselectは実装するとしてもとりあえず検索条件の方だけでも良いか。