Search code examples
javacouchbase-litenosql

Does couchbase lite really a no sql database


Currently I'm trying to find an embeddable nosql database for my java application. My current approach is using couchbase lite java. i ran following example and saw creation of db.sqlite3 files.

            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());
                }
            }

so here am I using a nosql database?


Solution

  • Absolutely. The comments mostly already answer this.

    Couchbase Lite requires no schema. It stores data as JSON documents (as demonstrated in your code sample). It currently uses map/reduce for indexing and queries. It's a fully functional embedded NoSQL database (and more).

    From a coding perspective, how it's implemented underneath is irrelevant. You don't need to know, nor should you rely on, anything but the public API.

    To make the point, there is an implementation of Couchbase Lite that uses ForestDB available. ForestDB is currently considered less mature than SQLite, so it's not the default.

    If you're interested in implementation details like how one version uses SQLite, I encourage you to look at the code. You can find it under various repos at https://github.com/couchbase