目前我正在尝试为我的 java 应用程序找到一个可嵌入的 nosql 数据库。我目前的方法是使用 couchbase lite java。我运行了以下示例并看到了 db.sqlite3 文件的创建。
public class Main {
public static void main(String[] args) {
// Enable logging
Logger log = Logger.getLogger("app1");
log.setLevel(Level.ALL);
JavaContext context = new JavaContext();
// Create a manager
Manager manager = null;
try {
manager = new Manager(context, Manager.DEFAULT_OPTIONS);
} catch (IOException e) {
e.printStackTrace();
}
// Create or open the database named app
Database database = null;
try {
database = manager.getDatabase("app1");
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
// The properties that will be saved on the document
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("title", "Couchbase Mobile");
properties.put("sdk", "Java");
// Create a new document
Document document = database.createDocument();
// Save the document to the database
try {
document.putProperties(properties);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
// Log the document ID (generated by the database)
// and properties
log.info(String.format("Document ID :: %s", document.getId()));
log.info(String.format("Learning %s with %s", (String) document.getProperty("title"), (String) document.getProperty("sdk")));
System.out.println(document.toString());
}
}
那么我这里使用的是 nosql 数据库吗?
最佳答案
绝对是的。评论大多已经回答了这个问题。
Couchbase Lite 不需要架构。它将数据存储为 JSON 文档(如代码示例中所示)。目前它使用map/reduce 进行索引和查询。它是一个功能齐全的嵌入式 NoSQL 数据库(以及更多)。
从编码的角度来看,它的底层如何实现是无关紧要的。除了公共(public) API 之外,您不需要了解也不应该依赖任何其他内容。
为了说明这一点,有一个使用 ForestDB 的 Couchbase Lite 实现。目前,ForestDB 被认为不如 SQLite 成熟,因此它不是默认值。
如果您对实现细节感兴趣,例如一个版本如何使用 SQLite,我鼓励您查看代码。您可以在 https://github.com/couchbase 的各种存储库下找到它。
关于java - couchbase lite真的是一个无sql数据库吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40000381/