{"id":10257,"date":"2023-06-23T01:43:43","date_gmt":"2023-06-23T08:43:43","guid":{"rendered":"https:\/\/www.couchbase.com\/developers\/tutorials\/android-kotlin-query-builder\/"},"modified":"2023-06-23T01:43:43","modified_gmt":"2023-06-23T08:43:43","slug":"android-kotlin-query-builder","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/it\/developers\/tutorials\/android-kotlin-query-builder\/","title":{"rendered":"Couchbase Lite Query Builder Engine with Kotlin and Jetpack Compose"},"content":{"rendered":"\n<h3 id=\"h-introduction\" class=\"wp-block-heading\">Introduction<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Couchbase Lite brings powerful querying and Full-Text-Search(FTS) capabilties to the edge. The query builder interface is based on <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/www.couchbase.com\/sqlplusplus\">SQL++<\/a>, Couchbase\u2019s declarative query language that extends <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/www.sqlite.org\/index.html\">SQL<\/a> for JSON. If you are familiar with SQL, you will feel right at home with the semantics of the new API.  The query builder API is designed using the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/en.wikipedia.org\/wiki\/Fluent_interface\">Fluent API Design Pattern<\/a>, and it uses method cascading to read to like a Domain Specific Language (DSL). This makes the interface very intuitive and easy to understand.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this step of the learning path you will learn the fundamentals of:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using the QueryBuilder API<\/li>\n\n\n<li>Using Live Queries with queryChangeFlow and Kotlin Co-Routine Flows<\/li>\n\n\n<li>Using JSON Serialization to &#8220;deserialize&#8221; documents from the database in to Kotlin data class<\/li>\n\n\n<li>Using indexes to speed up a query<\/li>\n\n\n<li>Using the count function with the QueryBuilder API<\/li>\n\n\n<li>Using the LIKE operator to search for documents with a specific value in a field<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-app-overview\" class=\"wp-block-heading\">App Overview<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">While the demo app has a lot of functionality, this step will walk you through:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Log in into the application<\/li>\n\n\n<li>Scrolling the list of projects<\/li>\n\n\n<li>Review the code for displaying projects<\/li>\n\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>NOTE<\/strong>:  This step assumes you completed the previous step <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"android-kotlin-batch-operations?learningPath=learn\/android-kotlin\"><code>Batch operations<\/code><\/a> that loaded the sample data into the application.   This part of the learning path will not work if you don&#8217;t complete the previous steps.<\/p>\n<\/blockquote>\n\n\n\n<h3 id=\"h-installation\" class=\"wp-block-heading\">Installation<\/h3>\n\n\n\n<h4 id=\"h-fetching-app-source-code\" class=\"wp-block-heading\">Fetching App Source Code<\/h4>\n\n\n\n<h5 id=\"h-clone-source-code\" class=\"wp-block-heading\">Clone Source Code<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you haven&#8217;t already cloned the repo from the previous steps, clone the <code>Learn Couchbase Lite with Kotlin and Jetpack Compose<\/code> repository from GitHub.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git clone https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path.git\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-try-it-out\" class=\"wp-block-heading\">Try it out<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open src\/build.gradle using Android Studio.<\/li>\n\n\n<li>Build and run the project.<\/li>\n\n\n<li>Log in to the app with  <strong><em>&#8220;<a href=\"mailto:demo@example.com\">demo@example.com<\/a>&#8220;<\/em><\/strong> and <strong><em>&#8220;P@ssw0rd12&#8221;<\/em><\/strong> for user Id and password fields respectively.<\/li>\n\n\n<li>Verify that you see sample projects on the screen.  If you do not see sample projects, please complete the previous step <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"android-kotlin-batch-operations?learningPath=learn\/android-kotlin\"><strong>Batch operations<\/strong><\/a> to load sample data before continuing.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"project_listing.gif\" alt=\"Project Listing,400\"><\/p>\n\n\n\n<h3 id=\"h-data-model\" class=\"wp-block-heading\">Data Model<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A reminder that Couchbase Lite is a JSON Document Store. A <code>Document<\/code> is a logical collection of named fields and values. The values are any valid JSON types. In addition to the standard JSON types, Couchbase Lite supports <code>Date<\/code> and <code>Blob<\/code> data types. While it is not required or enforced, it is a recommended practice to include a <em>&#8220;documentType&#8221;<\/em> property that can serve as a namespace for related documents.<\/p>\n\n\n\n<h4 id=\"h-the-project-document\" class=\"wp-block-heading\">The Project Document<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The sample app was loaded with a collection of <code>Document<\/code> with a <em>&#8220;documentType&#8221;<\/em> property of <em>&#8220;project&#8221;<\/em> in the previous step.  Each document represents a project that a team would would work on and have to complete before the due date based on a selected location, which is another document type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An example of a document would be:<\/p>\n\n\n\n<pre class=\"wp-block-code language-json\"><code>{\n\t&quot;team&quot;: &quot;team1&quot;,\n\t&quot;modifiedOn&quot;: &quot;1656804469897&quot;,\n\t&quot;documentType&quot;: &quot;project&quot;,\n\t&quot;createdBy&quot;: &quot;demo@example.com&quot;,\n\t&quot;dueDate&quot;: &quot;1734415200000&quot;,\n\t&quot;name&quot;: &quot;Santa Clara Warehouse Audit&quot;,\n\t&quot;description&quot;: &quot;Audit of warehouse stock located in Santa Clara, CA.&quot;,\n\t&quot;modifiedBy&quot;: &quot;demo@example.com&quot;,\n\t&quot;warehouse&quot;: {\n\t\t&quot;documentType&quot;: &quot;warehouse&quot;,\n\t\t&quot;name&quot;: &quot;Santa Clara Warehouse&quot;,\n   \t&quot;shippingTo&quot;: [\n\t\t\t&quot;AZ&quot;,\n\t\t\t&quot;CA&quot;,\n\t\t\t&quot;HI&quot;,\n\t\t\t&quot;NV&quot;\n\t\t],\n\t\t&quot;warehouseId&quot;: &quot;e1839e0b-57a0-472c-b29d-8d57e256ef32&quot;,\n\t\t&quot;city&quot;: &quot;Santa Clara&quot;,\n\t\t&quot;address1&quot;: &quot;3250 Dr Olcott Street&quot;,\n\t\t&quot;postalCode&quot;: &quot;95054&quot;,\n\t\t&quot;latitude&quot;: 32.3803024,\n\t\t&quot;state&quot;: &quot;CA&quot;,\n\t\t&quot;salesTax&quot;: 0.0913,\n\t\t&quot;longitude&quot;: -121.9674197,\n\t\t&quot;yearToDateBalance&quot;: 0.0\n\t},\n\t&quot;projectId&quot;: &quot;663953ba-9e4c-4090-9e07-642c1778d467&quot;,\n\t&quot;createdOn&quot;: &quot;1656804469897&quot;\n}\n<\/code><\/pre>\n\n\n\n<h5 id=\"h-the-project-data-class\" class=\"wp-block-heading\">The Project Data Class<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">When a <em>&#8220;project&#8221;<\/em> is retreived from the database it is stored within an data class of type <strong>Project<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>@Keep\n@Serializable\ndata class Project (\n    var projectId: String = &quot;&quot;,\n    var name: String = &quot;&quot;,\n    var description: String = &quot;&quot;,\n    var isComplete: Boolean = false,\n    var documentType: String = &quot;&quot;,\n    @Serializable(with = DateSerializer::class)\n    var dueDate: Date? = null,\n    var warehouse: Warehouse? = null,\n\n    \/\/security tracking\n    var team: String = &quot;&quot;,\n    var createdBy: String = &quot;&quot;,\n    var modifiedBy: String = &quot;&quot;,\n    @Serializable(with = DateSerializer::class)\n    var createdOn: Date? = null,\n    @Serializable(with = DateSerializer::class)\n    var modifiedOn: Date? = null\n)\n<\/code><\/pre>\n\n\n\n<h5 id=\"h-the-warehouse-class\" class=\"wp-block-heading\">The Warehouse Class<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">When a <em>&#8220;warehouse&#8221;<\/em> from a project is retreived from the database it is stored within a data class of type <strong>Warehouse<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>@Keep\n@Serializable\ndata class Warehouse(\n    val warehouseId: String,\n    val name: String,\n    val address1: String,\n    val address2: String? = &quot;&quot;,\n    val city: String,\n    val state: String,\n    val postalCode: String,\n    val salesTax: Double,\n    val yearToDateBalance: Double,\n    val latitude: Double,\n    val longitude: Double,\n    val shippingTo: List&lt;String&gt;,\n    val documentType: String\n    )\n)\n<\/code><\/pre>\n\n\n\n<h3 id=\"h-exploring-the-query-builder-api-with-the-count-function\" class=\"wp-block-heading\">Exploring the Query Builder API with the Count Function<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The Query API in Couchbase Lite is extensive.  On the Developer &#8211; Database Information screen we display the number of warehouse documents found in the warehouse database.  The <code>QueryBuilder<\/code> API along with the count function was used to calculate this number.  To see the Developer Information screen:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Launch the Invenory Application on your emulator<\/li>\n\n\n<li>Login in using the username <em><a href=\"mailto:demo@example.com\">demo@example.com<\/a><\/em> and password <em>P@ssw0rd12<\/em><\/li>\n\n\n<li>Click the Drawer menu icon (sometimes referred to the Hamburger icon) and tap on Developer<\/li>\n\n\n<li>Tap on the Database Information button<\/li>\n\n<\/ul>\n\n\n\n<h4 id=\"h-counting-number-of-documents-by-type\" class=\"wp-block-heading\">Counting number of documents by type<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The &#8220;DevDatabaseInfoView&#8221; screen displays the count of how many documents are in the warehouse database with the type set to &#8216;warehouse&#8217;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"developer-database-info.jpg\" alt=\"Developer - Database Information\" title=\"#width=300px\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The DevDatabaseInfoView function obtains this information from the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/src\/app\/src\/main\/java\/com\/couchbase\/learningpath\/ui\/developer\/DevDatabaseInfoViewModel.kt#L74\"> <strong>DevDatabaseInfoViewModel<\/strong><\/a> class, which tracks this in a mutableStateOf variable.   The view model calls the WarehouseRepositoryDb which runs the query to calculate the count.<\/p>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>private suspend fun updateWarehouseCount() {\n viewModelScope.launch(Dispatchers.IO) {\n  val locationCount = warehouseRepository.warehouseCount()\n   if (locationCount &gt; 0) {\n    withContext(Dispatchers.Main) {\n     numberOfWarehouses.value = locationCount\n    }\n   }\n  }\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/src\/app\/src\/main\/java\/com\/couchbase\/learningpath\/data\/warehouse\/WarehouseRepositoryDb.kt#L97\"> <strong>WarehouseRepositoryDb.kt<\/strong><\/a> file and locate the <code>warehouseCount<\/code> function.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>override suspend fun warehouseCount(): Int {\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We build the Query using the <code>QueryBuilder<\/code> API that will look for Documents that match the specified criteria.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>var resultCount = 0\nval countAliasName = &quot;count&quot;\ntry {\n val db = databaseResources.warehouseDatabase\n db?.let {\n  val query = QueryBuilder  \/\/ &lt;1&gt;\n   .select(SelectResult.expression(Function.count(Expression.string(&quot;*&quot;))).`as`(countAliasName)) \/\/ &lt;2&gt;\n   .from(DataSource.database(it)) \/\/ &lt;3&gt;\n   .where(Expression.property(typeAttributeName).equalTo(Expression.string(documentType))) \/\/ &lt;4&gt;\n  val results = query.execute().allResults()  \/\/ &lt;5&gt;\n  resultCount = results[0].getInt(countAliasName)  \/\/ &lt;6&gt;\n  }\n } catch (e: Exception){\n  Log.e(e.message, e.stackTraceToString())\n }\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Call the Query Builder API to create a Query<\/li>\n\n\n<li>The select function will run the calculation from the count function.  Note we have to use the ` as an escape character because as is a reserved Kotlin keyword.<\/li>\n\n\n<li>The <code>DataSource.database(it)<\/code> specified the Data Source which is the warehouse database<\/li>\n\n\n<li>We include the <code>where<\/code> clauses that uses the <code>equalTo<\/code> operator to look for the <em>&#8220;warehouse&#8221;<\/em> string in the <em>&#8220;type&#8221;<\/em> property.<\/li>\n\n\n<li>We run the Query by calling the <code>execute().allResults()<\/code> method on the Query that was constructed in the previous step<\/li>\n\n\n<li>We get the results by looking at the first result in the collection and getting an integer value for the key countAlaisName which we defined in the <code>select<\/code> clause<\/li>\n\n<\/ol>\n\n\n\n<h3 id=\"h-further-exploring-the-query-builder-api-return-list-of-projects-documents\" class=\"wp-block-heading\">Further Exploring the Query Builder API &#8211; return List of Projects Documents<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The Query Builder API in Couchbase Lite is extensive. In our second example, we will be using the <code>QueryBuilder<\/code> API to make a simple <em>pattern matching<\/em> query using the equalTo operator.  This example will use Live Query with Kotlin coroutine flows.<\/p>\n\n\n\n<h4 id=\"h-fetching-project-documents\" class=\"wp-block-heading\">Fetching Project Documents<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">From the &#8220;Login&#8221; screen, when a user logs in with the proper credentials they are presented with a list of projects there team is assigned to work on.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>Open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/src\/app\/src\/main\/java\/com\/couchbase\/learningpath\/ui\/project\/ProjectListView.kt#L54\"> <strong>ProjectListView.kt<\/strong><\/a> file and locate the <code>ProjectListView<\/code> function.<\/p>\n<\/li>\n\n\n<li>\n<p>The live query is <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/developer.android.com\/kotlin\/flow\">collected<\/a> as state from the Flow&lt;List<project>&gt; repositoryFlow property that the ProjectListViewModel exposes.  Flows do not emit values until they are collected.  This is often referred to as a <code>cold stream<\/code>.<\/project><\/p>\n<\/li>\n\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>TIP<\/strong>:  Anytime documents change or are added to the database that satisify this query, the flow would stream to the ProjectListViewModel and the ProjectListView would collect it if it&#8217;s the current composable on the screen.  The <code>live query<\/code> API via the queryChangeFlow function can dynmamically update your UI without the need for end user interaction, which will come in handy in future sections of the learning path when we review replication.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>val projectList by viewModel.repositoryFlow.collectAsState(initial = listOf())\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To see how the flow is created, open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/src\/app\/src\/main\/java\/com\/couchbase\/learningpath\/ui\/project\/ProjectListViewModel.kt#L29\"> <strong>ProjectListViewModel.kt<\/strong><\/a> file and locate the <code>repositoryFlow<\/code> property.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>var repositoryFlow: Flow&lt;List&lt;Project&gt;&gt; = repository.getDocuments(currentUser.team)\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>The view model exposes the flow which is a list of projects from the repository getDocument function.  The getDocument function takes in the current user&#8217;s team in order to filter out results to only the projects associated with that team.<\/p>\n<\/li>\n\n\n<li>\n<p>To see how to build a flow, open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/src\/app\/src\/main\/java\/com\/couchbase\/learningpath\/data\/project\/ProjectRepositoryDb.kt#L48\"> <strong>ProjectRepositoryDb.kt<\/strong><\/a> file and locate the getDocuments function.<\/p>\n<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>override fun getDocuments(team: String): Flow&lt;List&lt;Project&gt;&gt;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We first build a Query using the <code>QueryBuilder<\/code> API that will look for Documents that match the specified criteria.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code> val query = QueryBuilder \/\/ &lt;1&gt;\n  .select(SelectResult.all()) \/\/ &lt;2&gt;\n  .from(DataSource.database(database).`as`(&quot;item&quot;)) \/\/ &lt;3&gt;\n  .where( \/\/4\n    Expression.property(&quot;documentType&quot;)\n      .equalTo(Expression.string(projectType)) \/\/ &lt;4&gt;\n    .and(Expression.property(&quot;team&quot;)\n      .equalTo(Expression.string(team)))) \/\/ &lt;4&gt;\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Build a query using the <code>QueryBuilder<\/code> API<\/li>\n\n\n<li>The <code>SelectResult.all()<\/code> specifies that we are interested in all properties in Documents that match the specified criteria<\/li>\n\n\n<li>The <code>DataSource.database(database).\\<\/code>as<code>(\"item\")<\/code> specified the Data Source.  Note we have to use escape character in order to use the as function<\/li>\n\n\n<li>The <code>Expression<\/code> builds a <code>QueryExpression<\/code> used to find documents where the <code>type<\/code> property and the <code>team<\/code> properties are equal to the value passed in<\/li>\n\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Once the query has been created we can define the flow that will be returned.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>val flow = query        \/\/ &lt;1&gt;\n  .queryChangeFlow()  \/\/ &lt;1&gt; \n  .map { qc -&gt; mapQueryChangeToProject(qc) } \/\/ &lt;2&gt;\n  .flowOn(Dispatchers.IO)  \/\/ &lt;3&gt;\nquery.execute()  \/\/ &lt;4&gt;\nreturn flow  \/\/ &lt;5&gt;\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The query varible from the previous step is used to call the queryChangeFlow function to return a flow<\/li>\n\n\n<li>The <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/developer.android.com\/kotlin\/flow#modify\">intermediate operator map<\/a> is used to change the results coming back using the mapQueryChangeToProject function passing in the QueryChange.  This is used to deserialize the results from JSON to the Project data class.<\/li>\n\n\n<li>The flowOn function is used to make sure that the flow runs on the Dispatcher.IO context to keep the code from running on the main UI thread.<\/li>\n\n\n<li>The query executes.  Remember this step <strong>MUST<\/strong> be done before returning the flow.<\/li>\n\n\n<li>Return the flow<\/li>\n\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>REMINDER<\/strong>:  Kotlin Co Routine Flows emit new values into the stream of data and are not returned until they are <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/developer.android.com\/kotlin\/flow\">collected<\/a>.<\/p>\n<\/blockquote>\n\n\n\n<h5 id=\"h-indexing-the-query\" class=\"wp-block-heading\">Indexing the Query<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>Creating indexes for non-FTS based queries is optional. However, to speed up queries, you can create indexes on the properties that you would query against. Indexing is handled eagerly.<\/p>\n<\/li>\n\n\n<li>\n<p>In the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/src\/app\/src\/main\/java\/com\/couchbase\/learningpath\/data\/DatabaseManager.kt#L123\"><strong>DatabaseManager.kt<\/strong><\/a>  file, locate the <code>createTeamTypeIndex<\/code> function.<\/p>\n<\/li>\n\n\n<li>\n<p>We create an index on the <code>type<\/code> and <code>team<\/code> properties of the documents in the <em>inventory<\/em> database.<\/p>\n<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>private fun createTeamTypeIndex(){\n try {\n  inventoryDatabase?.let {  \/\/ &lt;1&gt;\n   if (!it.indexes.contains(teamIndexName)) {\n    \/\/ create index for ProjectListView to only return documents with\n    \/\/ the type attribute set to project and the team attribute set to the\n    \/\/ logged in users team\n    it.createIndex( \/\/ &lt;2&gt;\n     teamIndexName, \/\/ &lt;3&gt;\n     IndexBuilder.valueIndex(   \/\/ &lt;4&gt;\n      ValueIndexItem.property(documentTypeAttributeName), \/\/ &lt;5&gt;\n      ValueIndexItem.property(teamAttributeName)) \/\/ &lt;5&gt;\n     )\n    }\n   }\n } catch (e: Exception){\n  android.util.Log.e(e.message, e.stackTraceToString())\n }\n}\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The let keyword is used to unbox the database since it can be null.<\/li>\n\n\n<li>Call the database createIndex function which takes in a name of the index and then the properites to index<\/li>\n\n\n<li>The name of the index in string format.  TeamIndexName is defined toward the top of the class with the value <code>idxTeam<\/code><\/li>\n\n\n<li>The IndexBuilder&#8217;s valueIndex function can be used to create the index<\/li>\n\n\n<li>The ValueIndexItem.property factory method can be used to create a ValueIndexItem by passing in the property of which to index.<\/li>\n\n<\/ol>\n\n\n\n<h3 id=\"h-query-builder-api-searching-for-warehouses-with-the-like-operator\" class=\"wp-block-heading\">Query Builder API &#8211; Searching for Warehouses with the LIKE Operator<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The Query Builder API supports serveral operators including the LIKE which can be used for string matching.  We use the LIKE operator on the data editor screen for Projects to find a warehouse to add to a project.  Let&#8217;s review the code.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>NOTE<\/strong>: The like operator performs case sensitive matches.  To perform case insensitive matching, use lowercase or uppercase functions to ensure all comparators have the same case, thereby removing the case issue.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">On the Project Editor screen we provide a link to the Warehouse Section screen.  To see the Project Editor screen:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Launch the Invenory Application on your emulator<\/li>\n\n\n<li>Login in using the username <em><a href=\"mailto:demo@example.com\">demo@example.com<\/a><\/em> and password <em>P@ssw0rd12<\/em><\/li>\n\n\n<li>Click the + icon to add a Project<\/li>\n\n\n<li>Type in a name for the project on the Name field.<\/li>\n\n\n<li>Tap the button <code>No Warehouse Selected<\/code><\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"project_editor_screen_nowarehouse_selected.png\" alt=\"Project Editor screen\" title=\"#width=300px\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the City box enter Sa<\/li>\n\n\n<li>In the State box enter Ca<\/li>\n\n\n<li>Hit the Search button<\/li>\n\n\n<li>A listing of warehouses should return that match these results<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"select_project_warehouse.png\" alt=\"Select Project screen\" title=\"#width=300px\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s review the code for the Warehouse Section screen.<\/p>\n\n\n\n<h4 id=\"h-warehouse-selection\" class=\"wp-block-heading\">Warehouse Selection<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>Open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/src\/app\/src\/main\/java\/com\/couchbase\/learningpath\/ui\/project\/WarehouseSelectionView.kt#L48\"> <strong>WarehouseSelectionView.kt<\/strong><\/a> file and locate the <code>WarehouseSelectionView<\/code> function.<\/p>\n<\/li>\n\n\n<li>\n<p>The WarehouseSelectionView exposes the viewModel&#8217;s onSearch which the WarehouseSector function uses with the Search button.<\/p>\n<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>WarehouseSelector(\n  searchCity = viewModel.searchCity.value,\n  searchState = viewModel.searchState.value,\n  onSearchCityChanged = viewModel.onSearchCityChanged,\n  onSearchStateChanged = viewModel.onSearchCountryChanged,\n  onSearch = viewModel.onSearch,\n  warehouseStatusMessage = viewModel.locationStatusMessage.value,\n  warehouses = viewModel.warehousesState,\n  onWarehouseSelected = onWarehouseSelected\n)\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This is defined as OnSearch in the WarehouseSelector function<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>fun WarehouseSelector(\n    searchCity: String,\n    searchState: String,\n    onSearchCityChanged: (String) -&gt; Unit,\n    onSearchStateChanged: (String) -&gt; Unit,\n    onSearch: () -&gt; Unit,\n    warehouseStatusMessage: String,\n    warehouses: List&lt;Warehouse&gt;,\n    onWarehouseSelected: (Warehouse) -&gt; Unit\n)\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The search button then calls the OnSearch method on the OnClick listener.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>Button(modifier = Modifier\n .padding(top = 4.dp),\n  colors = ButtonDefaults.buttonColors(backgroundColor = Red500),\n  onClick = {\n   onSearch()\n  })\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/src\/app\/src\/main\/java\/com\/couchbase\/learningpath\/ui\/project\/WarehouseSelectionViewModel.kt#L43\"> <strong>WarehouseSelectionViewModel.kt<\/strong><\/a> file and locate the <code>onSearch<\/code> val definition.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>val onSearch: () -&gt; Unit = {\n viewModelScope.launch { \/\/ &lt;1&gt;\n  if (searchCity.value.length &gt;= 2) { \/\/ &lt;2&gt;\n   isLoading.value = true\n   val warehouses = warehouseRepository \/\/ &lt;3&gt;\n    .getByCityState(searchCity.value, searchState.value) \/\/ &lt;3&gt;\n   if (warehouses.isNotEmpty()) { \/\/ &lt;4&gt;\n    withContext(Dispatchers.Main) {\n    warehousesState.clear()\n    warehousesState.addAll(warehouses)\n    isLoading.value = false\n   } \n  } else { \/\/ &lt;5&gt;\n   withContext(Dispatchers.Main) {\n    warehousesState.clear()\n    locationStatusMessage.value = &quot;No Locations Found&quot;\n    isLoading.value = false\n    }\n   }\n  }\n }\n}\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Since we will be talking to the database using suspend functions, we want to make sure we use viewModel Scope<\/li>\n\n\n<li>Business logic to check if the searchCity value is greater than or equal to 2 characters.  If so, then we can search for warehouses.<\/li>\n\n\n<li>Call the warehouseRepository getByCityState function which takes in the searchCity and searchState values.<\/li>\n\n\n<li>If the warehouses list is not empty, then we can set the warehousesState to the warehouses list.<\/li>\n\n\n<li>If not, then we set the locationStatusMessage to &#8220;No Locations Found&#8221;.<\/li>\n\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/src\/app\/src\/main\/java\/com\/couchbase\/learningpath\/data\/warehouse\/WarehouseRepositoryDb.kt#L26\"> <strong>WarehouseRepositoryDb.kt<\/strong><\/a> file and locate the <code>getByCityState<\/code> function.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>override suspend fun getByCityState(searchCity: String, searchState: String?): List&lt;Warehouse&gt; {\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We wil use withContext(Dispatchers.IO) to make sure we are working on the IO thread since we will be talking to the database.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-kotlin\"><code>try {\n val db = databaseResources.warehouseDatabase\n db?.let { database -&gt;\n  \/\/search by city\n  var whereQueryExpression = Function\n   .lower(Expression.property(cityAttributeName))\n   .like(Expression.string(&quot;%&quot; + searchCity.lowercase() + &quot;%&quot;)) \/\/ &lt;1&gt;\n\n  \/\/search by optional state\n  searchState?.let { state -&gt;\n   if (state.isNotEmpty()) { \/\/ &lt;2&gt;\n    val stateQueryExpression = Function\n     .lower(Expression.property(stateAttributeName))\n     .like(Expression.string(&quot;%&quot; + state.lowercase() + &quot;%&quot;))  \/\/ &lt;2&gt;\n\n     whereQueryExpression =\n      whereQueryExpression.and(stateQueryExpression)  \/\/ &lt;2&gt;\n   }\n  }\n\n  \/\/add type filter\n  val typeQueryExpression = Function\n   .lower(Expression.property(typeAttributeName))\n   .equalTo(Expression.string(documentType))  \/\/ &lt;3&gt;\n\n  whereQueryExpression = whereQueryExpression.and(typeQueryExpression) \/\/ &lt;3&gt;\n\n  \/\/create query to execute using QueryBuilder API\n  val query = QueryBuilder\n   .select(SelectResult.all())\n   .from(DataSource.database(database).`as`(itemAliasName))\n   .where(whereQueryExpression) \/\/ &lt;4&gt;\n\n  \/\/loop through results and add to list\n  query.execute().allResults().forEach { item -&gt; \/\/ &lt;5&gt;\n   val json = item.toJSON()\n   val warehouse = Json.decodeFromString&lt;WarehouseDao&gt;(json).item\n   warehouses.add(warehouse)\n  }\n }\n} catch (e: Exception){\n Log.e(e.message, e.stackTraceToString())\n}\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a query expression off the city attribute and use the like function to pass in the searchCity value.<\/li>\n\n\n<li>If the searchState value is not null, then we will create a query expression off the state attribute and use the like function to pass in the searchState value.<\/li>\n\n\n<li>Create a query expression off the type attribute and use the equalTo function to pass in the documentType value.  This makes sure we only match warehouse documents.<\/li>\n\n\n<li>We will build a query using the QueryBuilder API to select all the results from the database and pass in our whereQueryExpression with our like statement(s).<\/li>\n\n\n<li>We loop through all the results and add them to the warehouses list that is then returned to the ViewModel.<\/li>\n\n<\/ol>\n\n\n\n<h3 id=\"h-learn-more\" class=\"wp-block-heading\">Learn More<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Congratulations on completing this step of our learning path!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This step of the learning path walked you through the Query Builder API in Couchbase Lite and used it to return documents from the database and we looked at calling the Query API built-in count function. Check out the following links for further documenation and continue on to the next step to learn more about how to use Query Builder with SQL++ syntax.<\/p>\n\n\n\n<h4 id=\"h-references\" class=\"wp-block-heading\">References<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/android\/querybuilder.html\">Documentation: Querybuilder<\/a><\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/android\/querybuilder.html#lbl-like-ops\">Documentation: Querybuilder &#8211; Like Operator<\/a><\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/mobile\/3.0.0\/couchbase-lite-android\/com\/couchbase\/lite\/Function.html\">API Documentation: Querybuilder &#8211; Functions<\/a><\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/android\/query-resultsets.html\">Documentation: Result Sets<\/a><\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/android\/query-live.html\">Documentation: Live Query &#8211; Working with Queries<\/a><\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/android\/query-troubleshooting.html\">Documentation: Query Troubleshooting\n<\/a><\/li>\n\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Couchbase Lite brings powerful querying and Full-Text-Search(FTS) capabilties to the edge. The query builder interface is based on SQL++, Couchbase\u2019s declarative query language that extends SQL for JSON. If you are familiar with SQL, you will feel right at home with the semantics of the new API. The query builder API is designed using [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"_acf":"","footnotes":""},"tutorial-languages":[586],"tutorial-tags":[587],"tutorial-technologies":[585],"tutorial-types":[555],"class_list":["post-10257","tutorials","type-tutorials","status-publish","hentry","tutorial-languages-kotlin","tutorial-tags-android","tutorial-technologies-mobile","tutorial-types-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Couchbase Lite Query Builder Engine with Kotlin and Jetpack Compose - Couchbase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/it\/developers\/tutorials\/android-kotlin-query-builder\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Couchbase Lite Query Builder Engine with Kotlin and Jetpack Compose\" \/>\n<meta property=\"og:description\" content=\"Introduction Couchbase Lite brings powerful querying and Full-Text-Search(FTS) capabilties to the edge. The query builder interface is based on SQL++, Couchbase\u2019s declarative query language that extends SQL for JSON. If you are familiar with SQL, you will feel right at home with the semantics of the new API. The query builder API is designed using [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/it\/developers\/tutorials\/android-kotlin-query-builder\/\" \/>\n<meta property=\"og:site_name\" content=\"Couchbase\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Couchbase\/\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2548\" \/>\n\t<meta property=\"og:image:height\" content=\"1171\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@couchbase\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"14 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/developers\\\/tutorials\\\/android-kotlin-query-builder\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/developers\\\/tutorials\\\/android-kotlin-query-builder\\\/\",\"name\":\"Couchbase Lite Query Builder Engine with Kotlin and Jetpack Compose - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/#website\"},\"datePublished\":\"2023-06-23T08:43:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/developers\\\/tutorials\\\/android-kotlin-query-builder\\\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/it\\\/developers\\\/tutorials\\\/android-kotlin-query-builder\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/developers\\\/tutorials\\\/android-kotlin-query-builder\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Couchbase Lite Query Builder Engine with Kotlin and Jetpack Compose\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"width\":1129,\"height\":1129,\"caption\":\"Couchbase\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/it\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Couchbase\\\/\",\"https:\\\/\\\/x.com\\\/couchbase\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/CouchbaseServer\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/couchbase\\\/\",\"https:\\\/\\\/github.com\\\/couchbase\\\/\",\"https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Couchbase,_Inc.\"],\"description\":\"Couchbase is a database software company headquartered in San Jose, California, providing an operational data platform for AI used by hundreds of global enterprises.\",\"legalName\":\"Couchbase, Inc.\",\"foundingDate\":\"2011-01-01\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Couchbase Lite Query Builder Engine with Kotlin and Jetpack Compose - Couchbase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/it\/developers\/tutorials\/android-kotlin-query-builder\/","og_locale":"it_IT","og_type":"article","og_title":"Couchbase Lite Query Builder Engine with Kotlin and Jetpack Compose","og_description":"Introduction Couchbase Lite brings powerful querying and Full-Text-Search(FTS) capabilties to the edge. The query builder interface is based on SQL++, Couchbase\u2019s declarative query language that extends SQL for JSON. If you are familiar with SQL, you will feel right at home with the semantics of the new API. The query builder API is designed using [&hellip;]","og_url":"https:\/\/www.couchbase.com\/it\/developers\/tutorials\/android-kotlin-query-builder\/","og_site_name":"Couchbase","article_publisher":"https:\/\/www.facebook.com\/Couchbase\/","og_image":[{"width":2548,"height":1171,"url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@couchbase","twitter_misc":{"Est. reading time":"14 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/it\/developers\/tutorials\/android-kotlin-query-builder\/","url":"https:\/\/www.couchbase.com\/it\/developers\/tutorials\/android-kotlin-query-builder\/","name":"Couchbase Lite Query Builder Engine with Kotlin and Jetpack Compose - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/it\/#website"},"datePublished":"2023-06-23T08:43:43+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/it\/developers\/tutorials\/android-kotlin-query-builder\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/it\/developers\/tutorials\/android-kotlin-query-builder\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/it\/developers\/tutorials\/android-kotlin-query-builder\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/"},{"@type":"ListItem","position":2,"name":"Couchbase Lite Query Builder Engine with Kotlin and Jetpack Compose"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/it\/#website","url":"https:\/\/www.couchbase.com\/it\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/it\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/it\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"it-IT"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/it\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/it\/","logo":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/www.couchbase.com\/it\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","contentUrl":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","width":1129,"height":1129,"caption":"Couchbase"},"image":{"@id":"https:\/\/www.couchbase.com\/it\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Couchbase\/","https:\/\/x.com\/couchbase","https:\/\/www.youtube.com\/c\/CouchbaseServer","https:\/\/www.linkedin.com\/company\/couchbase\/","https:\/\/github.com\/couchbase\/","https:\/\/en.wikipedia.org\/wiki\/Couchbase,_Inc."],"description":"Couchbase \u00e8 una societ\u00e0 di software per database con sede a San Jose, in California, che fornisce una piattaforma operativa per i dati utilizzata da centinaia di aziende globali.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/it\/wp-json\/wp\/v2\/tutorials\/10257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/it\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/it\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/it\/wp-json\/wp\/v2\/tutorials\/10257\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/it\/wp-json\/wp\/v2\/media?parent=10257"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/it\/wp-json\/wp\/v2\/tutorial-languages?post=10257"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/it\/wp-json\/wp\/v2\/tutorial-tags?post=10257"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/it\/wp-json\/wp\/v2\/tutorial-technologies?post=10257"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/it\/wp-json\/wp\/v2\/tutorial-types?post=10257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}