iPhone 上 SQLite 的最佳 Cocoa/Objective-C 包装库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/640885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 21:14:47  来源:igfitidea点击:

Best Cocoa/Objective-C Wrapper Library for SQLite on iPhone

iphoneobjective-ccocoa-touchsqlite

提问by pfeilbr

I'm developing for the iPhone and am looking for a good Cocoa/Objective-C library for working with SQLite. I don't want to use the standard procedural SQLite C API. I see options at sqlite.orgunder the Objective-C section, but am not sure which is the best in terms of library API design, stability, and functionality. I'd like to use something that's actively being developed and hopefully will be around for a while. Anyone have suggestions based on experience using one?

我正在为 iPhone 开发,正在寻找一个很好的 Cocoa/Objective-C 库来使用 SQLite。我不想使用标准的过程 SQLite C API。我在sqlite.org的 Objective-C 部分看到了一些选项,但我不确定在库 API 设计、稳定性和功能方面哪个是最好的。我想使用一些正在积极开发的东西,希望能存在一段时间。任何人都有基于使用经验的建议?

Thanks

谢谢

采纳答案by ccgus

I personally use FMDB, and the last update to it was yesterday.

我个人使用FMDB,最后一次更新是昨天。

回答by Brent Royal-Gordon

I'm also a fan of FMDatabase, although I've had to customize my own version of it. My apps use a layer around it I wrote called ArchDBObject that transparently converts objects to and from a database representation; I'm thinking about releasing it in some form, but I haven't really decided how yet.

我也是 FMDatabase 的粉丝,尽管我不得不自定义我自己的版本。我的应用程序在它周围使用了一个名为 ArchDBObject 的层,它可以透明地将对象与数据库表示进行相互转换;我正在考虑以某种形式发布它,但我还没有真正决定如何发布。

In any case, FMDatabase can be had at https://github.com/ccgus/fmdb.

在任何情况下,FMDatabase 都可以在https://github.com/ccgus/fmdb 获得

回答by Accatyyc

The simplest I've found is this one https://github.com/misato/SQLiteManager4iOS

我发现的最简单的是这个https://github.com/misato/SQLiteManager4iOS

SQLiteManager by Ester Sanchez.

Ester Sanchez 的 SQLiteManager。

Using it is basically like this:

使用它基本上是这样的:

NSArray *results = [dbManager getRowsForQuery:@"SELECT * FROM table WHERE id = 1"];

resultsis an array containing dictionaries. Each dictionary is a single returned row where the keys are the names of each column in the table.

results是一个包含字典的数组。每个字典都是一个返回的行,其中键是表中每一列的名称。

After that you can do things like this:

之后,您可以执行以下操作:

NSDictionary *aPerson = [results objectAtIndex:0];
NSString *firstName = aPerson[@"firstName"];
NSString *email = aPerson[@"email"];

回答by Kendall Helmstetter Gelner

FMDB is nice because it's the lightest way to not have to deal with the C calls and type conversions, while still giving you full access to the SQL.

FMDB 很好,因为它是无需处理 C 调用和类型转换的最轻松的方式,同时仍然可以让您完全访问 SQL。

The thing I generally do not like about object-relational wrappers is that you get too distant from the SQL being generated and that's when performance can start to suffer.

我通常不喜欢对象关系包装器的一点是,您离生成的 SQL 太远了,这时性能可能会开始受到影响。

回答by Vineel Shah

I spent the last few hours looking at the options -- haven't been in production with any of these yet, so YMMV.

我花了最后几个小时查看选项 - 还没有使用这些选项进行生产,所以 YMMV。

The lightest weight wrapper I found was here:

我找到的最轻的包装纸在这里:

http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/

http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/

I don't know if it has an official name. It's just 1 class, and it abstracts the nastiness of the SQLite api, while leaving the value of working directly with SQL. The learning curve is 5 minutes, assuming you know SQL already. Since it's so small, I can imagine it would be easy to fix anything that might go wrong with it.

我不知道它是否有正式名称。它只是 1 个类,它抽象了 SQLite api 的肮脏,同时保留了直接使用 SQL 的价值。学习曲线为 5 分钟,假设您已经了解 SQL。由于它很小,我可以想象它很容易修复任何可能出错的地方。

回答by Ziminji

If you want, you could also have a look at the following repository that provides a set of classes that can be used to create SQL statements and provides a simple way to handle a SQLite database connection. It is located at https://github.com/ziminji/objective-c-sql-query-builder

如果需要,您还可以查看以下存储库,其中提供了一组可用于创建 SQL 语句的类,并提供了一种处理 SQLite 数据库连接的简单方法。它位于https://github.com/ziminji/objective-c-sql-query-builder

回答by mamcx

I have a simple ORM on top of FDBM here http://code.google.com/p/chibiorm/.

我在http://code.google.com/p/chibiorm/的 FDBM 之上有一个简单的 ORM 。

With it, you can use raw SQL when you wish, return any SQL as a dict list, or use the nice OO style.

有了它,您可以根据需要使用原始 SQL,将任何 SQL 作为 dict 列表返回,或者使用漂亮的 OO 样式。