{"id":12874,"date":"2022-03-14T10:23:48","date_gmt":"2022-03-14T17:23:48","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=12874"},"modified":"2025-06-13T19:26:33","modified_gmt":"2025-06-14T02:26:33","slug":"reuse-sql-queries-between-server-mobile-app-databases","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/pt\/reuse-sql-queries-between-server-mobile-app-databases\/","title":{"rendered":"Reutilizar consultas SQL entre os bancos de dados do servidor e do aplicativo m\u00f3vel"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Como todos sabemos, a manuten\u00e7\u00e3o do c\u00f3digo \u00e9 cara - quanto mais complexo for o c\u00f3digo, maior ser\u00e1 o custo de sua manuten\u00e7\u00e3o. Portanto, desde o in\u00edcio dos tempos, os desenvolvedores de software t\u00eam se esfor\u00e7ado muito para atingir o objetivo de <\/span><b>reutiliza\u00e7\u00e3o de c\u00f3digo<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">O Couchbase Mobile 3.0 introduziu o suporte para consultas SQL++. Como desenvolvedor, a primeira coisa que me veio \u00e0 mente foi compartilhar as consultas usadas em projetos voltados para os aplicativos Couchbase Server e Couchbase Mobile.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Essa \u00e9 uma boa ideia? Vamos explorar essa quest\u00e3o usando dados de amostra e um aplicativo m\u00f3vel de prova de conceito.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Dados de amostra<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Todo o c\u00f3digo deste artigo est\u00e1 dispon\u00edvel em <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\"><span style=\"font-weight: 400;\">GitHub<\/span><\/a><span style=\"font-weight: 400;\">. Veja o <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/README.md\"><i><span style=\"font-weight: 400;\">LEIAME<\/span><\/i><\/a> <span style=\"font-weight: 400;\">para obter informa\u00e7\u00f5es sobre como configurar os projetos em seu computador.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Os dados de amostra s\u00e3o provenientes do <\/span><a href=\"https:\/\/www.openstreetmap.org\/#map=5\/38.007\/-95.844\"><span style=\"font-weight: 400;\">OpenStreetMap<\/span><\/a><span style=\"font-weight: 400;\"> e est\u00e1 licenciado sob a licen\u00e7a <\/span><a href=\"https:\/\/wiki.osmfoundation.org\/wiki\/Terms_of_Use\"><span style=\"font-weight: 400;\">Open Data Commons Licen\u00e7a de banco de dados aberto (ODbL)<\/span><\/a><span style=\"font-weight: 400;\"> pela OpenStreetMap Foundation.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">O conjunto de dados cont\u00e9m todas as lojas que vendem sorvete nos Estados Unidos. Um exemplo de documento JSON est\u00e1 listado abaixo:<\/span><\/p>\n<pre class=\"\">{\r\n \"type\": \"Feature\",\r\n \"id\": \"node\/472242349\",\r\n \"properties\": {\r\n \"addrCity\": \"Austin\",\r\n \"addrHousenumber\": \"4477\",\r\n \"addrPostcode\": \"78745\",\r\n \"addrState\": \"TX\",\r\n \"addrStreet\": \"South Lamar Boulevard\",\r\n \"addrUnit\": \"#790\",\r\n \"amenity\": \"ice_cream\",\r\n \"cuisine\": \"ice_cream\",\r\n \"name\": \"Amy's Ice Creams\",\r\n \"phone\": \"+1-512-891-0573\",\r\n \"id\": \"node\/472242349\"\r\n},\r\n  \"geometry\": {\r\n   \"type\": \"Point\",\r\n   \"coordinates\": [\r\n    -97.7998856,\r\n    30.230688\r\n  ]\r\n }\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">Como voc\u00ea pode ver, esse \u00e9 um conjunto de dados vers\u00e1til para testes porque tem propriedades incorporadas nos documentos.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Exemplo de aplicativo m\u00f3vel<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">O <a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\">Exemplo de aplicativo m\u00f3vel<\/a> foi escrito em <\/span><a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/\"><span style=\"font-weight: 400;\">SwiftUI<\/span><\/a><span style=\"font-weight: 400;\"> com <\/span><a href=\"https:\/\/developer.apple.com\/documentation\/combine\"><span style=\"font-weight: 400;\">Combinar<\/span><\/a><span style=\"font-weight: 400;\"> e \u00e9 um aplicativo para iOS\/macOS que exibe todas as v\u00e1rias lojas que vendem sorvete nos Estados Unidos. O aplicativo inclui um <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/prebuilt-database.html\"><span style=\"font-weight: 400;\">banco de dados pr\u00e9-criado<\/span><\/a><span style=\"font-weight: 400;\"> com os mesmos documentos JSON j\u00e1 importados para ele por conveni\u00eancia. Esse aplicativo m\u00f3vel usa a vers\u00e3o mais recente do <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/quickstart.html\"><span style=\"font-weight: 400;\">SDK do Couchbase Lite<\/span><\/a><span style=\"font-weight: 400;\">. Voc\u00ea pode abrir o projeto no XCode a partir do arquivo de projeto na pasta src para acompanhar o processo.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Uma compara\u00e7\u00e3o de consulta simples<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Para iniciar nossos testes, podemos escrever uma consulta simples para o Couchbase Server, para mostrar todos os endere\u00e7os de sorveterias e orden\u00e1-los pelo nome da loja:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">SELECT id, properties.addrCity, properties.addrHousenumber, properties.addrPostcode, \r\nproperties.addrStreet, properties.addrState, properties.name \r\nFROM icecream \r\nWHERE properties.addrCity &lt;&gt; \"\" \r\nAND type = \"Feature\" \r\nORDER BY properties.name<\/pre>\n<p><span style=\"font-weight: 400;\">Essa consulta tem um filtro que retorna apenas documentos em que o objeto da propriedade <\/span><i><span style=\"font-weight: 400;\">addrCity <\/span><\/i><span style=\"font-weight: 400;\">tem um valor e onde o documento <\/span><i><span style=\"font-weight: 400;\">tipo<\/span><\/i><span style=\"font-weight: 400;\"> \u00e9 igual a <\/span><i><span style=\"font-weight: 400;\">Recurso<\/span><\/i><span style=\"font-weight: 400;\">. Se voc\u00ea se pergunta por que temos o <\/span><i><span style=\"font-weight: 400;\">addrCity<\/span><\/i><span style=\"font-weight: 400;\"> \u00e9 devido a dados sujos ou documentos sem nomes ou informa\u00e7\u00f5es ausentes nesse conjunto de dados. Usando um <\/span><i><span style=\"font-weight: 400;\">tipo<\/span><\/i><span style=\"font-weight: 400;\"> O atributo \u00e9 comum em aplicativos m\u00f3veis para filtrar diferentes tipos de documentos.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Podemos usar o <\/span><b>Editor de consultas<\/b><span style=\"font-weight: 400;\"> do servidor Couchbase<\/span> <a href=\"https:\/\/docs.couchbase.com\/server\/current\/manage\/manage-ui\/manage-ui.html\"><b>Console da Web<\/b><\/a><span style=\"font-weight: 400;\"> para executar essa consulta. Quando a executei em meu Macbook Pro M1 Max pessoal, o resultado chegou em 38,4 ms. Essa consulta usa o <\/span><i><span style=\"font-weight: 400;\">adv_properties_addrCity_type<\/span><\/i><span style=\"font-weight: 400;\"> que voc\u00ea pode ver clicando no \u00edcone <\/span><b>Consultor de \u00edndices<\/b><span style=\"font-weight: 400;\"> bot\u00e3o.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Portando a consulta para o Couchbase Lite<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Agora vamos ver essa mesma consulta em execu\u00e7\u00e3o no nosso aplicativo m\u00f3vel. Para visualizar o aplicativo m\u00f3vel, voc\u00ea pode usar o XCode para abrir o arquivo <\/span><i><span style=\"font-weight: 400;\">IceCreamLocator.xcodeproj<\/span><\/i><span style=\"font-weight: 400;\"> localizado no arquivo <\/span><i><span style=\"font-weight: 400;\">src <\/span><\/i><span style=\"font-weight: 400;\">pasta. Uma vez aberta no Xcode, localize a pasta <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift#L32\"><i><span style=\"font-weight: 400;\">IceCreamLocationRepository<\/span><\/i><\/a><span style=\"font-weight: 400;\"> swift no arquivo <\/span><i><span style=\"font-weight: 400;\">Compartilhado\\Data<\/span><\/i><span style=\"font-weight: 400;\"> pasta.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">O <\/span><i><span style=\"font-weight: 400;\">inicial <\/span><\/i><span style=\"font-weight: 400;\">ativa o registro detalhado do banco de dados para inspecionar as informa\u00e7\u00f5es da consulta. Usando o registro detalhado, voc\u00ea pode analisar o que est\u00e1 acontecendo no Couchbase Lite, incluindo o desempenho da consulta.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Vamos analisar a consulta simples do Couchbase Server e ver como ela funciona no Swift com a nova API de consulta SQL++. A fun\u00e7\u00e3o para a consulta simples \u00e9 denominada <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift#L101\"><i><span style=\"font-weight: 400;\">getListByTypeCityOrderName<\/span><\/i><\/a><span style=\"font-weight: 400;\">e o c\u00f3digo \u00e9 exibido abaixo:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">  func getListByTypeCityOrderName() -&gt; Void {\r\n      do {\r\n        if let query = try _db?.createQuery(\"SELECT id, \r\nproperties.addrCity, properties.addrHousenumber, properties.addrPostcode, properties.addrStreet, \r\nproperties.addrState, properties.name FROM _ WHERE properties.addrCity &lt;&gt; \\\"\\\" AND \r\ntype = \\\"Feature\\\" ORDER BY properties.name\") {\r\n            var results: [IceCreamLocation] = []\r\n            let explain = try query.explain()\r\n            print (\"**EXPLAIN** \\(explain)\")\r\n            for result in try query.execute() {\r\n                if let data = result.toJSON().data(using: .utf8){\r\n                   let location = try \r\nJSONDecoder().decode(IceCreamLocation.self, from: data)\r\n                   results.append(location)\r\n             }\r\n           }\r\n           self.iceCreamLocationList.send(results)\r\n           self.iceCreamLocationList.send(completion: .finished)\r\n         }\r\n     } catch {\r\n         print(\"**Error**: \\(error)\")\r\n         self.iceCreamLocationList.send(completion: .failure(DbError.unknown))\r\n     }\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">H\u00e1 algumas maneiras de fazer uma consulta SQL++ no Swift. Neste exemplo, usamos o banco de dados <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/query-n1ql-mobile.html\"><i><span style=\"font-weight: 400;\">createQuery<\/span><\/i><\/a> <span style=\"font-weight: 400;\">para criar a consulta. No Couchbase Lite, estou usando o caractere de sublinhado (_) como o nome do banco de dados antes da fun\u00e7\u00e3o <\/span><i><span style=\"font-weight: 400;\">DE <\/span><\/i><span style=\"font-weight: 400;\">declara\u00e7\u00e3o. Alterar o nome do banco de dados \u00e9 uma das altera\u00e7\u00f5es esperadas para reutilizar instru\u00e7\u00f5es SQL++. Al\u00e9m disso, para escapar das aspas no comando <\/span><i><span style=\"font-weight: 400;\">ONDE <\/span><\/i><span style=\"font-weight: 400;\">tive que adicionar o caractere de escape de string do Swift (<\/span><i><span style=\"font-weight: 400;\">\\<\/span><\/i><span style=\"font-weight: 400;\">) antes de cada aspa.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Para testar essa consulta durante a execu\u00e7\u00e3o, voc\u00ea pode abrir o arquivo <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/ViewModels\/IceCreamListViewModel.swift#L24\"><i><span style=\"font-weight: 400;\">IceCreamListViewModel<\/span><\/i><\/a> <span style=\"font-weight: 400;\">encontrado no arquivo <\/span><i><span style=\"font-weight: 400;\">ViewModels <\/span><\/i><span style=\"font-weight: 400;\">pasta. Localize a pasta <\/span><i><span style=\"font-weight: 400;\">inicial <\/span><\/i><span style=\"font-weight: 400;\">e descomente a primeira linha de exemplo localizada na parte inferior da fun\u00e7\u00e3o que chama a fun\u00e7\u00e3o <\/span><i><span style=\"font-weight: 400;\">getListByTypeCityOrderName<\/span><\/i><span style=\"font-weight: 400;\"> da fun\u00e7\u00e3o <\/span><i><span style=\"font-weight: 400;\">_reposit\u00f3rio <\/span><\/i><span style=\"font-weight: 400;\">vari\u00e1vel:<\/span><\/p>\n<pre class=\"\"> \/\/first example\r\n_repository.getListByTypeCityOrderName()<\/pre>\n<p><span style=\"font-weight: 400;\">Agora voc\u00ea pode usar o Xcode para executar o aplicativo em um simulador do iOS ou em um aplicativo do macOS. Em seguida, abra o aplicativo <\/span><b>Console de depura\u00e7\u00e3o <\/b><span style=\"font-weight: 400;\">no Xcode, clicando no \u00edcone <\/span><b>Mostrar depura\u00e7\u00e3o <\/b><span style=\"font-weight: 400;\">no canto inferior direito do editor do Xcode, conforme destacado abaixo.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12888\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/03\/properties.png\" alt=\"\" width=\"858\" height=\"396\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/properties.png 858w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/properties-300x138.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/properties-768x354.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/properties-20x9.png 20w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">O registro detalhado exibir\u00e1 uma quantidade enorme de informa\u00e7\u00f5es de registro. Para ajudar a encontrar as informa\u00e7\u00f5es corretas nos logs, use a caixa de filtro abaixo do console. Por exemplo, digite o texto \"<\/span><i><span style=\"font-weight: 400;\">Informa\u00e7\u00f5es de consulta<\/span><\/i><span style=\"font-weight: 400;\">\" e, em seguida, pressione a tecla Enter em seu teclado para ver informa\u00e7\u00f5es sobre a consulta. O console de depura\u00e7\u00e3o filtrar\u00e1 os dados que o Couchbase Lite retorna.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A inspe\u00e7\u00e3o dos registros mostrar\u00e1 a <\/span><i><span style=\"font-weight: 400;\">Informa\u00e7\u00f5es de consulta<\/span><\/i><span style=\"font-weight: 400;\"> e o n\u00famero de documentos encontrados pela consulta, quantos bytes e quanto tempo a consulta levou. Lembre-se de que os n\u00fameros que voc\u00ea est\u00e1 vendo s\u00e3o de um simulador, n\u00e3o de um dispositivo real. Para ajustar o desempenho de aplicativos m\u00f3veis, voc\u00ea deve usar ferramentas da Apple com um dispositivo real.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A velocidade de execu\u00e7\u00e3o dessa consulta \u00e9 impressionante. Ainda mais impressionante \u00e9 o fato de que ainda n\u00e3o foram criados \u00edndices, portanto, essa consulta \u00e9 executada sem um \u00edndice e faz uma varredura de tabela, o que significa que ela precisa examinar o banco de dados em cada documento para ver se ele corresponde aos requisitos da consulta. O Couchbase Lite n\u00e3o exige \u00edndices e far\u00e1 varreduras de tabela se necess\u00e1rio, enquanto o Couchbase Server exige \u00edndices porque as varreduras de tabela podem prejudicar o desempenho de todo o cluster.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Em v\u00e1rios casos, a adi\u00e7\u00e3o de \u00edndices pode melhorar significativamente o desempenho de suas consultas, portanto, vamos parar de executar o aplicativo, adicionar o \u00edndice adequado e verificar novamente o desempenho.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Abra o <\/span><i><span style=\"font-weight: 400;\">IceCreamLocationRepository<\/span><\/i><span style=\"font-weight: 400;\"> e localize o <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift#L84\"><i><span style=\"font-weight: 400;\">createIceCreamIndexes<\/span><\/i><\/a> <span style=\"font-weight: 400;\">fun\u00e7\u00e3o. Descomente o primeiro bloco de c\u00f3digo para criar o primeiro \u00edndice de consulta:<\/span><\/p>\n<pre class=\"lang:default decode:true\">   let simpleIndex = ValueIndexConfiguration([\"properties.name\", \"properties.addrCity\", \"type\"])\r\n   try _db?.createIndex(simpleIndex, name: \"idx_location_type_city_name\")<\/pre>\n<p><span style=\"font-weight: 400;\">Como testamos para ver se a consulta usou o \u00edndice que criamos? Na consulta <\/span><i><span style=\"font-weight: 400;\">getListByTypeCityOrderName<\/span><\/i><span style=\"font-weight: 400;\"> voc\u00ea ver\u00e1 duas linhas que imprimem os resultados da fun\u00e7\u00e3o explain no console:<\/span><\/p>\n<pre class=\"\">let explain = try query.explain()\r\nprint (\"**EXPLAIN** \\(explain)\")<\/pre>\n<p><span style=\"font-weight: 400;\">A consulta <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/troubleshooting-queries.html#using\"><span style=\"font-weight: 400;\">explicar<\/span><\/a><span style=\"font-weight: 400;\"> executar\u00e1 o equivalente \u00e0 fun\u00e7\u00e3o SQLite <\/span><i><span style=\"font-weight: 400;\">EXPLICAR O PLANO DE CONSULTA<\/span><\/i><span style=\"font-weight: 400;\"> e armazene os resultados em uma cadeia de caracteres que voc\u00ea envia ao console usando a fun\u00e7\u00e3o print. Voc\u00ea pode filtrar por <\/span><i><span style=\"font-weight: 400;\">TABELA DE VARREDURA <\/span><\/i><span style=\"font-weight: 400;\">no console de depura\u00e7\u00e3o para encontrar os resultados. Ao analisar os resultados, certifique-se de remover o filtro anterior da janela do console. Agora, execute novamente o aplicativo e examine os registros para verificar a altera\u00e7\u00e3o de desempenho.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12889\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/03\/scantable.png\" alt=\"\" width=\"854\" height=\"485\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantable.png 854w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantable-300x170.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantable-768x436.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantable-20x11.png 20w\" sizes=\"auto, (max-width: 854px) 100vw, 854px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Voc\u00ea dever\u00e1 ver o <\/span><i><span style=\"font-weight: 400;\">USANDO O \u00cdNDICE <\/span><\/i><span style=\"font-weight: 400;\">com o nome do \u00edndice criado, o que informa que a consulta usa o \u00edndice adequado. Observe que, embora os \u00edndices possam ajudar as consultas, eles tamb\u00e9m podem tornar mais lentas as inser\u00e7\u00f5es e atualiza\u00e7\u00f5es de documentos. Voc\u00ea pode encontrar mais informa\u00e7\u00f5es sobre indexa\u00e7\u00e3o na se\u00e7\u00e3o Couchbase Lite <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/indexing.html\"><span style=\"font-weight: 400;\">documenta\u00e7\u00e3o<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Outra compara\u00e7\u00e3o de consulta<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Em nossa segunda compara\u00e7\u00e3o, filtramos os resultados para mostrar apenas as sorveterias no estado da Ge\u00f3rgia, ordenadas por cidade e estado:<\/span><\/p>\n<pre class=\"\">SELECT id, properties.addrCity, properties.addHousenumber, properties.addrPostcode, \r\nproperties.addrStreet, properties.addrState, properties.name \r\nFROM icecream \r\nWHERE\r\nproperties.addrCity IS NOT NULL \r\nAND properties.addrState = 'GA'\r\nAND type = \"Feature\" \r\nORDER BY properties.name<\/pre>\n<p><span style=\"font-weight: 400;\">Essa consulta retorna 15 documentos e usa uma consulta diferente, pois usamos o <\/span><i><span style=\"font-weight: 400;\">properties.addrState <\/span><\/i><span style=\"font-weight: 400;\">e <\/span><i><span style=\"font-weight: 400;\">properties.addrCity<\/span><\/i><span style=\"font-weight: 400;\"> em nossos atributos <\/span><i><span style=\"font-weight: 400;\">ONDE <\/span><\/i><span style=\"font-weight: 400;\">cl\u00e1usula.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Observe que mudamos a forma como verificamos o <\/span><i><span style=\"font-weight: 400;\">properties.addrCity<\/span><\/i><span style=\"font-weight: 400;\"> e usar o atributo <\/span><i><span style=\"font-weight: 400;\">IS NOT NULL<\/span><\/i><span style=\"font-weight: 400;\"> agora. Isso mostra a flexibilidade da linguagem SQL++ e como os desenvolvedores podem usar diferentes sintaxes para produzir os mesmos resultados.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12890\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/03\/selectID.png\" alt=\"\" width=\"1600\" height=\"699\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID.png 1600w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-300x131.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-1024x447.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-768x336.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-1536x671.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-20x9.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-1320x577.png 1320w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Agora, vamos voltar ao nosso aplicativo m\u00f3vel para observar as diferen\u00e7as. A fun\u00e7\u00e3o para nossa segunda consulta \u00e9 denominada <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift#L122\"><i><span style=\"font-weight: 400;\">getListByStateGeorgia<\/span><\/i><\/a><span style=\"font-weight: 400;\">e o c\u00f3digo \u00e9 exibido abaixo:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">    func getListByStateGeorgia() -&gt; Void {\r\n        do {\r\n           if let query = try _db?.createQuery(\"SELECT id, properties.addrCity, \r\nproperties.addrHousenumber, properties.addrPostcode, properties.addrStreet, \r\nproperties.addrState, properties.name FROM _ WHERE properties.addrCity NOT NULL AND \r\nproperties.addrState = \\\"GA\\\" AND type=\\\"Feature\\\" ORDER BY properties.name\") {\r\n               var results: [IceCreamLocation] = []\r\n               let explain = try query.explain()\r\n               print (\"**EXPLAIN** \\(explain)\")\r\n               for result in try query.execute() {\r\n                   if let data = result.toJSON().data(using: .utf8){\r\n                      let location = try \r\nJSONDecoder().decode(IceCreamLocation.self, from: data)\r\n                      results.append(location)\r\n                 }\r\n              }\r\n              self.iceCreamLocationList.send(results)\r\n              self.iceCreamLocationList.send(completion: .finished)\r\n          }\r\n        } catch {\r\n            print(\"**Error**: \\(error)\")\r\n            self.iceCreamLocationList.send(completion: .failure(DbError.unknown))\r\n     }\r\n   }<\/pre>\n<p><span style=\"font-weight: 400;\">Para testar essa nova consulta, voc\u00ea pode abrir o arquivo <\/span><i><span style=\"font-weight: 400;\">IceCreamListViewModel<\/span><\/i><span style=\"font-weight: 400;\">. Localize o <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/ViewModels\/IceCreamListViewModel.swift#L21\"><i><span style=\"font-weight: 400;\">inicial<\/span><\/i><\/a> <span style=\"font-weight: 400;\">e comente a primeira linha de exemplo localizada na parte inferior da fun\u00e7\u00e3o que chama a fun\u00e7\u00e3o <\/span><i><span style=\"font-weight: 400;\">getListByTypeCityOrderName <\/span><\/i><span style=\"font-weight: 400;\">da fun\u00e7\u00e3o <\/span><i><span style=\"font-weight: 400;\">_reposit\u00f3rio<\/span><\/i><span style=\"font-weight: 400;\"> e descomente a linha que chama nossa nova fun\u00e7\u00e3o:<\/span><\/p>\n<pre class=\"\">\/\/first example\r\n\/\/_repository.getListByTypeCityOrderName()\r\n\r\n\/\/second example\r\n_repository.getListByStateGeorgia()<\/pre>\n<p><span style=\"font-weight: 400;\">Voc\u00ea pode depurar o aplicativo usando o Xcode e verificar a \u00e1rea de depura\u00e7\u00e3o. Ela mostra os mesmos 15 documentos que foram retornados pela consulta executada no Couchbase Server, mas voltamos a fazer uma varredura de tabela, o que n\u00e3o \u00e9 o comportamento que queremos - alteramos a consulta, mas ainda n\u00e3o criamos nenhum \u00edndice novo.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12891\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/03\/scantableusetemp.png\" alt=\"\" width=\"856\" height=\"420\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantableusetemp.png 856w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantableusetemp-300x147.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantableusetemp-768x377.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantableusetemp-20x10.png 20w\" sizes=\"auto, (max-width: 856px) 100vw, 856px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Para corrigir isso, podemos voltar ao <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift\"><i><span style=\"font-weight: 400;\">IceCreamLocationRepository<\/span><\/i><\/a> <span style=\"font-weight: 400;\">e localize o <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift#L86\"><i><span style=\"font-weight: 400;\">createIceCreamIndexes<\/span><\/i><\/a> <span style=\"font-weight: 400;\">fun\u00e7\u00e3o. Descomente o segundo bloco de c\u00f3digo para criar o segundo \u00edndice de consulta:<\/span><\/p>\n<pre class=\"\">        let secondIndex = \r\nValueIndexConfiguration([\"properties.name\",\"properties.addrCity\", \"type\", \"properties.addrState\"])\r\n        try _db?.createIndex(secondIndex, name: \"idx_location_type_city_state_name\")<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12892\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/03\/scantablelocationtype.png\" alt=\"\" width=\"860\" height=\"426\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantablelocationtype.png 860w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantablelocationtype-300x149.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantablelocationtype-768x380.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantablelocationtype-20x10.png 20w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Descobrimos que poder\u00edamos reutilizar o c\u00f3digo nessas duas consultas mais simples, mas tivemos que adicionar os \u00edndices para evitar varreduras de tabela.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Capturas com reutiliza\u00e7\u00e3o de consultas<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">O Couchbase Server e o Couchbase Mobile n\u00e3o usam o mesmo mecanismo de armazenamento ou de consulta. Portanto, voc\u00ea pode se deparar com consultas do Couchbase Server que precisam de pequenas modifica\u00e7\u00f5es para serem otimizadas para o Couchbase Mobile.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Para obter mais informa\u00e7\u00f5es sobre o Couchbase Server, consulte a documenta\u00e7\u00e3o sobre o <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/cost-based-optimizer.html\"><span style=\"font-weight: 400;\">Otimizador baseado em custos<\/span><\/a><span style=\"font-weight: 400;\"> que o mecanismo de consulta usa. O portal do desenvolvedor do Couchbase tamb\u00e9m tem um bom artigo sobre como melhorar <\/span><a href=\"https:\/\/developer.couchbase.com\/tutorial-tuning-tips-and-advice\"><span style=\"font-weight: 400;\">desempenho da consulta<\/span><\/a><span style=\"font-weight: 400;\"> no Couchbase Server que podem explicar por que algumas consultas s\u00e3o escritas de uma maneira espec\u00edfica.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Recomendo a leitura da documenta\u00e7\u00e3o do Couchbase Mobile sobre solu\u00e7\u00e3o de problemas <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/troubleshooting-queries.html\"><span style=\"font-weight: 400;\">consultas<\/span><\/a><span style=\"font-weight: 400;\"> pois ele me ajudou a escrever consultas otimizadas e explica melhor a sa\u00edda do plano de consulta do SQLite.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Resumo<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Conforme mostrado em nossos exemplos de c\u00f3digo com a vers\u00e3o 3.0 do Couchbase Mobile, \u00e9 poss\u00edvel reutilizar o c\u00f3digo SQL++ entre o Server e o Mobile. No entanto, talvez seja necess\u00e1rio modificar as consultas e os \u00edndices para obter o melhor desempenho. Por isso, recomendo fortemente a leitura da excelente documenta\u00e7\u00e3o sobre <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/query-n1ql-mobile-server-diffs.html\"><span style=\"font-weight: 400;\">SQL++ for Mobile - Diferen\u00e7as em rela\u00e7\u00e3o ao SQL++ for Server<\/span><\/a><span style=\"font-weight: 400;\"> e <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/query-n1ql-mobile.html\"><span style=\"font-weight: 400;\">Strings de consulta SQL++<\/span><\/a><span style=\"font-weight: 400;\">. Ele cont\u00e9m informa\u00e7\u00f5es valiosas sobre as altera\u00e7\u00f5es que voc\u00ea pode precisar fazer em suas consultas para us\u00e1-las em seus aplicativos m\u00f3veis.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Aqui est\u00e3o alguns dos principais recursos mencionados ao longo da postagem:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\"><span style=\"font-weight: 400;\">Exemplos de c\u00f3digo do GitHub<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/www.openstreetmap.org\/#map=5\/38.007\/-95.844\"><span style=\"font-weight: 400;\">Projeto OpenStreetMap<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/prebuilt-database.html\"><span style=\"font-weight: 400;\">Couchbase Mobile - Documentos do banco de dados pr\u00e9-constru\u00eddo<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/quickstart.html\"><span style=\"font-weight: 400;\">Couchbase Lite no Swift - Documentos de in\u00edcio r\u00e1pido<\/span><\/a><span style=\"font-weight: 400;\">\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/indexing.html\"><span style=\"font-weight: 400;\">Couchbase Lite - Documentos de indexa\u00e7\u00e3o<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/cost-based-optimizer.html\"><span style=\"font-weight: 400;\">Couchbase Server - Documentos do otimizador baseado em custos<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/developer.couchbase.com\/tutorial-tuning-tips-and-advice\"><span style=\"font-weight: 400;\">Couchbase Server - Dicas e conselhos de ajuste<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/troubleshooting-queries.html\"><span style=\"font-weight: 400;\">Couchbase Mobile - Solu\u00e7\u00e3o de problemas de consultas<\/span><\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>As we all know, code is expensive to maintain\u2014the more complex the code, the higher the cost of maintaining it. Therefore, since the beginning of time, software developers have worked very hard to achieve the goal of code reusability. Couchbase [&hellip;]<\/p>","protected":false},"author":77540,"featured_media":12893,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1814,1810,1816,1812],"tags":[9527],"ppma_author":[9539],"class_list":["post-12874","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-design","category-couchbase-mobile","category-couchbase-server","category-n1ql-query","tag-mobile-3-0"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.5 (Yoast SEO v26.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Reuse SQL Queries between Server &amp; Mobile App Databases - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"Couchbase Mobile 3.0 introduced support for SQL++ queries, learn how to reuse SQL queries between Server and Mobile App Databases.\" \/>\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\/blog\/pt\/reuse-sql-queries-between-server-mobile-app-databases\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reuse SQL Queries between Server &amp; Mobile App Databases\" \/>\n<meta property=\"og:description\" content=\"Couchbase Mobile 3.0 introduced support for SQL++ queries, learn how to reuse SQL queries between Server and Mobile App Databases.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/pt\/reuse-sql-queries-between-server-mobile-app-databases\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-14T17:23:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T02:26:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1440\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Aaron LaBeau - Principal Software Engineer\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@biozal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Aaron LaBeau - Principal Software Engineer\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/\"},\"author\":{\"name\":\"Aaron LaBeau - Principal Software Engineer\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/8a68fa58a5fc5d8bf29577e7dc003a54\"},\"headline\":\"Reuse SQL Queries between Server &#038; Mobile App Databases\",\"datePublished\":\"2022-03-14T17:23:48+00:00\",\"dateModified\":\"2025-06-14T02:26:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/\"},\"wordCount\":1636,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg\",\"keywords\":[\"mobile 3.0\"],\"articleSection\":[\"Application Design\",\"Couchbase Mobile\",\"Couchbase Server\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/\",\"name\":\"Reuse SQL Queries between Server & Mobile App Databases - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg\",\"datePublished\":\"2022-03-14T17:23:48+00:00\",\"dateModified\":\"2025-06-14T02:26:33+00:00\",\"description\":\"Couchbase Mobile 3.0 introduced support for SQL++ queries, learn how to reuse SQL queries between Server and Mobile App Databases.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg\",\"width\":2560,\"height\":1440},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reuse SQL Queries between Server &#038; Mobile App Databases\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/8a68fa58a5fc5d8bf29577e7dc003a54\",\"name\":\"Aaron LaBeau - Principal Software Engineer\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/343f246f1f6971ad0851b3d3b558afbb\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg\",\"caption\":\"Aaron LaBeau - Principal Software Engineer\"},\"description\":\"Aaron LaBeau is a Principal Software Engineer on the Developer Experience and Ecosystem team. He has over 29 years with substantial development experience in Objective-C, Swift, Kotlin, Java, C#, Javascript, and Typescript. You can find his GitHub profile at https:\/\/www.github.com\/biozal\/.\",\"sameAs\":[\"https:\/\/www.couchbase.com\",\"https:\/\/www.linkedin.com\/in\/aaron-labeau-b444747\/\",\"https:\/\/x.com\/biozal\",\"https:\/\/www.youtube.com\/channel\/UCXgF-JqwBRGSawXajr6plGg\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/pt\/author\/biozal\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Reuse SQL Queries between Server & Mobile App Databases - The Couchbase Blog","description":"O Couchbase Mobile 3.0 introduziu o suporte para consultas SQL++. Saiba como reutilizar consultas SQL entre o servidor e os bancos de dados de aplicativos m\u00f3veis.","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\/blog\/pt\/reuse-sql-queries-between-server-mobile-app-databases\/","og_locale":"pt_BR","og_type":"article","og_title":"Reuse SQL Queries between Server & Mobile App Databases","og_description":"Couchbase Mobile 3.0 introduced support for SQL++ queries, learn how to reuse SQL queries between Server and Mobile App Databases.","og_url":"https:\/\/www.couchbase.com\/blog\/pt\/reuse-sql-queries-between-server-mobile-app-databases\/","og_site_name":"The Couchbase Blog","article_published_time":"2022-03-14T17:23:48+00:00","article_modified_time":"2025-06-14T02:26:33+00:00","og_image":[{"width":2560,"height":1440,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg","type":"image\/jpeg"}],"author":"Aaron LaBeau - Principal Software Engineer","twitter_card":"summary_large_image","twitter_creator":"@biozal","twitter_misc":{"Written by":"Aaron LaBeau - Principal Software Engineer","Est. reading time":"10 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/"},"author":{"name":"Aaron LaBeau - Principal Software Engineer","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/8a68fa58a5fc5d8bf29577e7dc003a54"},"headline":"Reuse SQL Queries between Server &#038; Mobile App Databases","datePublished":"2022-03-14T17:23:48+00:00","dateModified":"2025-06-14T02:26:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/"},"wordCount":1636,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg","keywords":["mobile 3.0"],"articleSection":["Application Design","Couchbase Mobile","Couchbase Server","SQL++ \/ N1QL Query"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/","url":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/","name":"Reuse SQL Queries between Server & Mobile App Databases - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg","datePublished":"2022-03-14T17:23:48+00:00","dateModified":"2025-06-14T02:26:33+00:00","description":"O Couchbase Mobile 3.0 introduziu o suporte para consultas SQL++. Saiba como reutilizar consultas SQL entre o servidor e os bancos de dados de aplicativos m\u00f3veis.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg","width":2560,"height":1440},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Reuse SQL Queries between Server &#038; Mobile App Databases"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"Blog do Couchbase","description":"Couchbase, o banco de dados NoSQL","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-BR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"Blog do Couchbase","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/8a68fa58a5fc5d8bf29577e7dc003a54","name":"Aaron LaBeau - Engenheiro de software principal","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/343f246f1f6971ad0851b3d3b558afbb","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg","caption":"Aaron LaBeau - Principal Software Engineer"},"description":"Aaron LaBeau is a Principal Software Engineer on the Developer Experience and Ecosystem team. He has over 29 years with substantial development experience in Objective-C, Swift, Kotlin, Java, C#, Javascript, and Typescript. You can find his GitHub profile at https:\/\/www.github.com\/biozal\/.","sameAs":["https:\/\/www.couchbase.com","https:\/\/www.linkedin.com\/in\/aaron-labeau-b444747\/","https:\/\/x.com\/biozal","https:\/\/www.youtube.com\/channel\/UCXgF-JqwBRGSawXajr6plGg"],"url":"https:\/\/www.couchbase.com\/blog\/pt\/author\/biozal\/"}]}},"authors":[{"term_id":9539,"user_id":77540,"is_guest":0,"slug":"biozal","display_name":"Aaron LaBeau - Principal Software Engineer","avatar_url":{"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg","url2x":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg"},"author_category":"","last_name":"LaBeau - Principal Software Engineer","first_name":"Aaron","job_title":"","user_url":"https:\/\/www.couchbase.com","description":"Aaron LaBeau \u00e9 engenheiro de software principal da equipe de experi\u00eancia do desenvolvedor e ecossistema.  Ele tem mais de 29 anos de experi\u00eancia em desenvolvimento substancial em Objective-C, Swift, Kotlin, Java, C#, Javascript e Typescript.  Voc\u00ea pode encontrar seu perfil no GitHub em https:\/\/www.github.com\/biozal\/."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/12874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/users\/77540"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/comments?post=12874"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/12874\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media\/12893"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media?parent=12874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/categories?post=12874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/tags?post=12874"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/ppma_author?post=12874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}