2016-10-12 32 views
1

目前我正在嘗試爲我的java應用程序找到一個可嵌入的nosql數據庫。我目前的做法是使用couchbase lite java。我運行下面的例子,看到db.sqlite3文件的創建。沒有couchbase lite真的沒有sql數據庫

  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數據庫?

+0

的各種回購協議下找到它是的,Couchbase是一個多模型NoSQL面向文檔的數據庫,您可以在[官方網站](http://www.couchbase.com/)上找到。 – DimaSan

+0

確實couchbase lite文件的持久性機制是.sqlite3。這些讓我感到困惑的是這些數據庫文件的關係模型。你能否在這裏啓發我。 – user3014595

+0

您看到NoSQL代表「不僅SQL」。 – DimaSan

回答

2

絕對如此。評論大多已經回答了這個問題。

Couchbase Lite不需要架構。它將數據存儲爲JSON文檔(如代碼示例中所示)。它目前使用map/reduce進行索引和查詢。這是一個功能齊全的嵌入式NoSQL數據庫(以及更多)。

從編碼的角度來看,它在底層如何實現是無關緊要的。您不需要知道,也不應該依賴除公共API之外的任何內容。

爲了說明問題,有一個使用ForestDB的Couchbase Lite實現。 ForestDB目前被認爲不如SQLite成熟,所以它不是默認的。

如果您對實現細節感興趣,比如一個版本如何使用SQLite,我鼓勵您查看代碼。您可以在https://github.com/couchbase