Search code examples
androiddatabase-designcouchbase-lite

Couchbase Lite Datastructure Appoarch


I have many data models. How should I approach when I create my Couchbaselite database? Should create multiple database for every model. Then how should I join them?

Example Object Model:

Restaurant

  • Name
  • Adress

Waiter

  • Name
  • Salary

json String: [{ id=..., Name=Rest, adress={id=...,street=..}}]


Solution

  • You could use the same database for multiple models, and when you want to join, you could use alias(DataSource.database(db).as("main")) from same database(below example db) and join using it.

    Below is a swift example,

    let q = QueryBuilder
            .select(SelectResult.expression(Meta.id.from("main")))
            .from(DataSource.database(db).as("main"))
            .join(
                Join.join(DataSource.database(db).as("secondary"))
                    .on(Expression.property("prop1").from("main")
                        .equalTo(Expression.property("prop2").from("secondary"))))