{"id":20763699,"url":"https://github.com/infosys/cordova_plugin_couchbase","last_synced_at":"2025-10-04T23:59:00.555Z","repository":{"id":97110358,"uuid":"203117032","full_name":"Infosys/Cordova_Plugin_Couchbase","owner":"Infosys","description":"This is plugin for Cordova to use Couchbase Lite to create iOS and Android app code for basic CRUD operations.","archived":false,"fork":false,"pushed_at":"2019-10-09T06:01:08.000Z","size":52,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T18:22:43.370Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Infosys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-19T07:03:52.000Z","updated_at":"2024-12-05T10:46:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"a8c9a0da-e881-497e-a8c2-ea16022b82c9","html_url":"https://github.com/Infosys/Cordova_Plugin_Couchbase","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Infosys/Cordova_Plugin_Couchbase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infosys%2FCordova_Plugin_Couchbase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infosys%2FCordova_Plugin_Couchbase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infosys%2FCordova_Plugin_Couchbase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infosys%2FCordova_Plugin_Couchbase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Infosys","download_url":"https://codeload.github.com/Infosys/Cordova_Plugin_Couchbase/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infosys%2FCordova_Plugin_Couchbase/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278391180,"owners_count":25978945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T10:45:35.587Z","updated_at":"2025-10-04T23:59:00.538Z","avatar_url":"https://github.com/Infosys.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"“Copyright 2018 Infosys Ltd.\r\nUse of this source code is governed by MIT license that can be found in the LICENSE file or at\r\nhttps://opensource.org/licenses/MIT.”\r\n\r\nCORDOVA PLUGIN FOR COUCHBASE LITE\r\n\r\nIntroduction:\r\nThis is document is all about some basic understanding of Couchbase, why we need a plugin for Cordova to use Couchbase, how to create a plugin for iOS and Android and sample plugin code for basic CRUD operations.\r\nWhy Couchbase?\r\nToday’s mission-critical applications demand support for millions of interactions with end-users. Traditional databases were built for thousands. Designed for consistency and control, they lack agility, flexibility, and scalability. To execute multiple use cases, organizations are forced to deploy multiple types of databases, resulting in a \"database sprawl\" - and inefficiency, sluggish time to market, and poor customer experience. \r\n\r\nCouchbase Server is an open source, distributed, NoSQL document-oriented engagement database. It exposes a fast key-value store with managed cache for sub-millisecond data operations, purpose-built indexers for fast queries and a powerful query engine for executing SQL-like queries. \r\n\r\nCouchbase Lite for mobile and Internet of Things environments Couchbase also runs natively on-device. This enables the device’s offline capability to ensure the business continuation.\r\n\r\nCouchbase Sync Gateway manages data synchronization b/w Couchbase Lite DB on mobile and Couchbase server.\r\n\r\nWhy Cordova?\r\nApache Cordova is an open-source mobile development framework. It allows you to use standard web technologies - HTML5, CSS3, and JavaScript for cross-platform development. Applications execute within wrappers targeted to each platform, and rely on standards-compliant API bindings to access each device's capabilities such as sensors, data, network status, etc.\r\nUse Apache Cordova if you are a mobile developer and want to extend an application across more than one platform, without having to re-implement it with each platform's language and tool set.\r\nA Cordova plugin is a package of injected code that allows the Cordova web view within which the app renders to communicate with the native platform on which it runs. Plugins provide access to device and platform functionality that is ordinarily unavailable to web-based apps so all the main Cordova API features are implemented as plugins.\r\nCouchbase with Cordova Architecture:\r\nThere are several security components and Integrations in the actual application PoC design, this following diagram just shows a high-level view of what we did for a reputed financial organization to integrate Cordova with Couchbase Lite database on mobile. The user Interface is a web app, the business logic and data model is written in native Swift. The data model uses Couchbase Lite as the embedded data persistence layer. The Cordova Plugin API acts as the bridging layer between the JavaScript and the native Swift worlds. The plugin exposes a JavaScript API to the web app. This architecture allows you to write the User Interface code once for both iOS and Android apps while leveraging Couchbase Lite’s native iOS framework for data management.\r\n\r\n \r\n\r\n\r\n\r\n \r\nPlugin Development for iOS Step-by-step:\r\nIn this section you will create a new plugin called Cordova-plugin-Couchbase to implement data persistence using Couchbase Lite’s Swift API.\r\nThe plugin code will be added to the Cordova-plugin-Couchbase folder which resides alongside the Cordova application folder.\r\nStep 1: Create a new file at Cordova-plugin-Couchbase/plugin.xml with the following.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nThe id=\"Cordova-plugin-Couchbase\" attribute is the plugin name which will be used later to import it in the Cordova project.\r\nThe \u003cjs-module\u003e\u003c/js-module\u003e XML tag declares the location of the file that will declare the JavaScript interface.\r\nThe \u003cplatform name=\"ios\"\u003e\u003c/platform\u003e XML tag declares the location of the Swift files to hold the native code.\r\n\r\n\r\n\r\n\r\n\r\nStep 2: Create a new file at Cordova-plugin-Couchbase/package.json with the following\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nThis file describes the plugin.\r\nStep 3: Create a new file at Cordova-plugin-Couchbase/www/Couchbase.js. This file defines the JS API with which a Cordova web app may interact with this plugin. Generally, this means that the plugin binds to the window element and by doing so, grants access to its parent project through simple JavaScript references. Add the following to your Couchbase.js file:\r\n\r\n\r\n\r\n\r\n\r\nStep 4: Create a new file at Cordova-plugin-Couchbase/src/ios/Couchbase.swift with the following. This file provides the native Swift implementation corresponding to the APIs defined in Couchbase.js.\r\n\r\n\r\n\r\nThe Cordova Plugin is instantiated when it is first called in the JavaScipt WebView app. The pluginInitialized() method includes the startup code. \r\nTo verify that your plugin is ready to work as expected, you have to install it in your Couchbase project. To do so, run the following commands from the root of the starter-project folder.\r\nCordova plugin add ../Cordova-plugin-Couchbase/\r\nCordova platform add ios\r\nCouchbase Lite Setup:\r\nNext, you will import Couchbase Lite as a dependency in the Xcode project.\r\nDownload Couchbase Lite framework from here https://www.couchbase.com/downloads and Unzip the file.\r\nOpen the Xcode project located at Couchbase/platforms/ios/Couchbase.xcodeproj.\r\nDrag CouchbaseLiteSwift.framework from the downloaded folder to the Xcode project navigator. Be sure to select the Copy items if needed checkbox.\r\n \r\nNavigate to Project \u003e General \u003e Embedded Binary and drag CouchbaseLiteSwift.framework over the list.\r\n \r\nDatabase Setup:\r\nWe will use the singleton pattern to setup the database instance. Create a new file at Cordova-plugin-Couchbase/src/ios/DatabaseManager.swift and insert the following.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nWhen adding a new Swift file, it must be referenced in the plugin’s configuration file. Insert the following as a child to the \u003cplatform name=\"ios\"\u003e\u003c/platform\u003e element in Cordova-plugin-Couchbase/plugin.xml.\r\n\u003csource-file src=\"src/ios/DatabaseManager.swift\"/\u003e\r\nTo test your changes, you must re-install the Cordova plugin from Cordova-plugin-Couchbase to Couchbase. Run the following commands from the root of the Cordova application folder.\r\nCordova emulate ios --target \"iPhone-XR, 12.0\" -- --buildFlag=\"-seModernBuildSystem=0\"\r\nThe application should run successfully the Couchbase Lite database is initialized but you haven’t run any queries to insert / select data from the database.\r\nIn the next section, you will use this Database variable to insert \u0026 select data from Couchbase Lite database.\r\nAdd the implementation of the getdata method to Cordova-plugin-Couchbase/src/ios/Couchbase.swift.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nThis method queries for all properties of documents including the Document id where the type property is testing.\r\nNext, you will update the plugin’s JavaScript interface. In Cordova-plugin-Couchbase/www/Couchbase.js, replace /* code will be added here later */ with the following code snippet.\r\n\r\n\r\n\r\nYou can now call the getdata method in the Cordova project. Add the following to the constructor method in Couchbase/www/index.html.\r\n\r\n\r\n\r\n\r\nTo test your changes, you must re-install the Cordova plugin. Modify Couchbase.swift, index.html and Couchbase.js (JavaScript Interface) to add new functionalities.\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfosys%2Fcordova_plugin_couchbase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfosys%2Fcordova_plugin_couchbase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfosys%2Fcordova_plugin_couchbase/lists"}