top of page

View/Open Couchbase Lite database in iOS using VSCode


A person designing the database schema

Download CouchbaseLite from github

Create a new Xcode project and open it. I’ll be using Cocoapods as dependency manager but you’re free to use any of your choice

You can go to CouchbaseLite Github and download their community editionSDK via any of the dependency manager specified there. Don’t forget to download the swift version if you’re working with Swift

If you’re using Cocoapods and Swift for this example like I am, use the following pod in you Podfile

pod 'CouchbaseLite-Swift'

Save the Podfile and go to terminal and download the pods using

pod install

Don’t forget to open your .xcworkspace and NOT .xcodeproj going forward

Build your project once to make sure everything is in place

To make sure that CouchbaseLite was successfully downloaded, go to your newly created sample project’s ViewController file and add:

import CouchbaseLiteSwift

below import UIKit and build your project. If you don’t see any error, you’re good to go!

Initialise Couchbase Database and save data

Now, we’ll initialise Couchbase database and save some data to it

We’ll be using a dictionary (_data) to save data into couchbase. Also, we’ll be using database named SampleDB along with it’s default scope as well as default collection

Other than saving data into couchbase, we will need to fetch the path to Couchbase database inside the storage directory of the app. For that I have written a helper method which makes use of the documents directory URL

Once you add the following code and run your app, you’ll see a path printed in your console like the following:

/Users/shubhambakshi/Library/Developer/CoreSimulator/Devices/4AAB696F-31F2–4AC1-A6A4–2EFA59F48597/data/Containers/Data/Application/39EF4B9D-E06B-4E38-BB39–9AB165B2F726/Library/Application Support/CouchbaseLite/

We’ll be using this path to Open/View Couchbase database using Visual Studio Code. Keep this handy !

Also, by this time, our sample data will also be added into couchbase database as well

Download VSCode and install Couchbase Lite extension

Download Visual Studio Code and head to it’s extension tab on the right side. Search for Couchbase Lite and install that extension

Now click on Search bar on top, select Show and Run Commands and then cblite: Open Database. Click Choose database from file and a finder widndow will open

Here, you would have to go to the path of couchbase lite storage which is tedious but lucky for us, we have used a helper method that provides us with a path/to/couchbase/storage. Remember, I asked you to keep the path handy that was shown in the console? We’ll use that here

Hit command+shift+G, paste the storage URL in the search window that opens and click/double click on the first URL that is shown in the list just below. You’ll see a finder window like this:

The finder window that opens after entering the storage URL
The finder window that opens after entering the storage URL

Select SampleDB (or whatever database you were using) and hit Open

Voila! Now you’ll be able to see COUCHBASE: CBLITE EXPLORER window open with your database below that. Click on the expand icon and you’ll be able to view your saved data and everything:

The data that was stored inside the document
The data that was stored inside the document

If you were not using the said data for insertion in the database and might have your own data/structure and are not able to still view the data in couchbase, that means your database is corrupted in some way so the extension is not able to open it

One issue that I faced a while back where my database got corrupted and there was no error from Couchbase whatsoever in the console was because I had “-” in my collection name and although they have mentioned in the docs that collection names can have “-” in it, still that was causing issues in my case. Check if that is your case as well

That’s it, folks! Happy Coding!

Related Posts

Comments


bottom of page