Test any type of cloud database on Android apps. No need of a dedicated backend.

Related tags

Database DBKong
Overview

DB Kong - Database connections simplified

Android CI Gradle Package

DB Kong is an Android library that allows you to connect, interact and test any type of cloud database on Android apps without the need to setup a dedicated backend. The library simplifies the process of connecting to a database and performing operations on it to just a few lines of code.

As of the current release DB Kong supports the following databases (future releases are aimed at including many more):

  • MongoDB

I really can't wait for y'all to try it out, so let's dive into the setup and features!

Getting started

  1. Firstly add the dependencies to your app/build.gradle (module level gradle file):
...

dependencies {

    ...

    implementation 'com.1407arjun.libs:dbkong:1.1.0'

    //Volley dependencies (required by the library as of the current version)
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.android.volley:volley:1.2.0'
    
    ...
}
  1. Create a github.properties file in the root of your project and add in the code as follows (skip this step if you want to use system environment variables as in step 2):
gpr.usr = < your github username >
gpr.key = < your personal access token >

The personal access token should have read packages scope.

  1. In the app/build.gradle (module level gradle file) include the following code to access the credentials from the github.properties file:
...

android {

  ...
  
  repositories {
        maven {
            url = "https://maven.pkg.github.com/1407arjun/DBKong"
            credentials {
                def githubProperties = new Properties()
                githubProperties.load(new FileInputStream(rootProject.file("github.properties")))

                username = githubProperties['gpr.usr'] ?: System.getenv("GPR_USER")
                password = githubProperties['gpr.key'] ?: System.getenv("GPR_API_KEY")
            }
        }
    }
    
    ...
}

Steps 2 and 3 are required by github to access any package published on Github Packages.

  1. Finally the repositories to your project level build.gradle file (depends on the Gradle version, do not add these to the buildscript):
...

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

...
  1. Sync the project with the build files.

  2. Add the permission to access the internet and allow clear-text traffic in the AndroidManifest.xml:

... ... ">
...

  <uses-permission android:name="android.permission.INTERNET"/>

  ...

  <application
          android:usesCleartextTraffic="true"

          ...

     

...

Using the library

  1. Firstly initialize the library in the onCreate() of your MainActivity.java or any other Java file:
        new DBKong(getApplicationContext(), timeout, new OnInitListener() {
            @Override
            public void onInit(boolean init, Error error) {
                if (init && error == null) {
                
                    ...
    
                } else {
                    if (error != null)
                    
                        ...
                }
            }
        });

Here, timeout is the time in milliseconds within which the connection should be established. You can set any timeout value depending on your use-case. On initialization, this method invokes a callback giving a boolean for the initialization status and an Error object for any error encountered (if any).

  1. If there is no error and the initialization status init == true then the intermediate server connection has been established and now all the connections to the database can be executed. Here, an example is shown for the MongoDB database:
@ .1oqwt.mongodb.net/ ?retryWrites=true&w=majority"; MongoDBConnect.getInstance(uri, db, collection) .insertOne(query) .addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(JSONObject response) { ... } @Override public void onFailure(Error error) { ... } }); } ... } }); ... ">
  ...
  
        new DBKong(getApplicationContext(), timeout, new OnInitListener() {
            @Override
            public void onInit(boolean init, Error error) {
                if (init && error == null) {
                    String uri = "mongodb+srv://admin:
      
       @
       
        .1oqwt.mongodb.net/
        
         ?retryWrites=true&w=majority
         "
        
       
      ;
                    MongoDBConnect.getInstance(uri, db, collection)
                            .insertOne(query)
                            .addOnSuccessListener(new OnSuccessListener() {
                                @Override
                                public void onSuccess(JSONObject response) {
                                    
                                    ...
                                }

                                @Override
                                public void onFailure(Error error) {
                                    
                                    ...
                                }
                            });
                }
                
                ...
            }
            
        });
        
  ...         

Here, uri is the connection string of MongoDB, db and collection is the name of the database (string) and collection (string) you want to connect to. This instance has several methods which you can use to perform CRUD or interact with the collection (for eg. insertOne(), find(), deleteMany(), etc.). Also you can add an OnSuccessListener callback to know if the operation is a success or whether it encountered an error, since all these tasks are carried out asynchronously.

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the project. git clone https://github.com/1407arjun/DBKong.git
  2. Create your feature branch. git checkout -b feature/AmazingFeature
  3. Commit your changes. git commit -m 'Add some AmazingFeature'
  4. Push to the branch. git push origin feature/AmazingFeature
  5. Open a Pull Request.

Acknowledgements

  1. https://github.com/JaneaSystems/nodejs-mobile
  2. https://github.com/google/volley
You might also like...
A small library to help with Realm.IO integration in Android apps

Android Realm Asset Helper A small library of methods to help with Realm.IO integration in Android apps Copies a realm database from a the assets fold

Android library for viewing and sharing in app databases.
Android library for viewing and sharing in app databases.

DbInspector DbInspector provides a simple way to view the contents of the in-app database for debugging purposes. There is no need to pull the databas

A wrapper around Android's SQLiteDatabase with restoring capability

Restorable SQLiteDatabase RestorableSQLiteDatabase is a wrapper to replicate android's SQLiteDatabase class with restoring capability. This wrapper ma

A simple NoSQL client for Android. Meant as a document store using key/value pairs and some rudimentary querying. Useful for avoiding the hassle of SQL code.

SimpleNoSQL A simple NoSQL client for Android. If you ever wanted to just save some data but didn't really want to worry about where it was going to b

an android library for debugging what we care about directly in app.
an android library for debugging what we care about directly in app.

EN | 中文 Pandora is a tool box that allows you to inspect and modify what includes networks, databases, UIs, etc. directly in your application. It is s

Core Data for Android

NexusData Core Data for Android NexusData is an object graph and persistence framework for Android. It allows for organizing and managing relational d

🧬 Android DataBinding kit for notifying data changes from Model layers to UI layers on MVVM architecture.
🧬 Android DataBinding kit for notifying data changes from Model layers to UI layers on MVVM architecture.

🧬 Android DataBinding kit for notifying data changes from Model layers to UI layers on MVVM architecture.

Pref-DB - Android SharedPreferences alternative library

Pref-DB Android SharedPreferences alternative library.

BlackDex is an Android unpack tool, it supports Android 5.0~12 and need not rely to any environment. BlackDex can run on any Android mobile phones or emulators, you can unpack APK File in several seconds.
BlackDex is an Android unpack tool, it supports Android 5.0~12 and need not rely to any environment. BlackDex can run on any Android mobile phones or emulators, you can unpack APK File in several seconds.

BlackDex is an Android unpack tool, it supports Android 5.0~12 and need not rely to any environment. BlackDex can run on any Android mobile phones or emulators, you can unpack APK File in several seconds.

☁️ cloud.sh is a lightweight self-hosted cloud for your home lab.
☁️ cloud.sh is a lightweight self-hosted cloud for your home lab.

DISCLAIMER: cloud.sh is under development. We do not recommend you to use it in a production environment for now. The storage could be corrupted when

Tired of manually setup test data of Kotlin data classes or POJOs? Instantiator creates Instances of any class for you so that you can focus on writing tests instead of spending time and effort to setup test data

Instantiator Tired of manually setup test data of Kotlin data classes or POJOs? Instantiator creates Instances of any class for you so that you can fo

Utility library dedicated for functional & non-functional codebases to simplify modelling of success and failure responses for the JVM languages 🔀

Expressible Utility library, part of the panda-lang SDK, dedicated for functional codebases that require enhanced response handling. Express yourself

LNSocial is a social media app dedicated to short-form videos created for and consumed by users.
LNSocial is a social media app dedicated to short-form videos created for and consumed by users.

LNSocial is a social media app dedicated to short-form videos created for and consumed by users. The length of videos is between 15-30 second

Spring Boot API for Modern Warfare 2 Dedicated Servers

Spring Boot API for Modern Warfare 2 Dedicated Servers

Sometimes, we need to show a label above an ImageView or any other views. Well, LabelView will be able to help you. It's easy to implement as well!
Sometimes, we need to show a label above an ImageView or any other views. Well, LabelView will be able to help you. It's easy to implement as well!

LabelView Sometimes, we need to show a label above an ImageView or any other views. Well, LabelXXView will be able to help you. It's easy to implement

Backend-aio - A ktor based ready to use backend

BackendAIO A ktor based ready to use backend BackendAIO is a project made to hel

Backend aio - A project made to help all newbie programmers that are approaching backend development

BackendAIO A ktor based ready to use backend BackendAIO is a project made to hel

Reapp is everything you need to build amazing apps with React: a collection of packages that work together, our UI kit, and a CLI that scaffolds your app and includes a server and build system.
Reapp is everything you need to build amazing apps with React: a collection of packages that work together, our UI kit, and a CLI that scaffolds your app and includes a server and build system.

What is it? Reapp is everything you need to build amazing apps with React: a collection of packages that work together, our UI kit, and a CLI that sca

Comments
  • Bug: Connection to MongoDB failed

    Bug: Connection to MongoDB failed

    There seems to be a bug due to which connection to MongoDB cannot be established. All the GET/POST requests are hitting the server but I don't seem to get a response or sometimes I get a response with a 500 error. Any help will be appreciated.

    bug 
    opened by 1407arjun 6
  • Fix : Updated code as per super class concept

    Fix : Updated code as per super class concept

    #2 URI is to be set in the superclass. So instead of this.URI, super.URI should be used. Accordingly, for other inherited variables with the same issue, updated this to super.

    opened by Tanmay000009 1
  • Issue: Node server on app restart

    Issue: Node server on app restart

    If nodeStarted == true then there is no callback to the onInitListener due to which further commands are not executed. This happens at times when the activity restarts (not the entire app). When the onInitListener is invoked in the case of nodeStarted == true (line 44) it throws an error Attempt to invoke interface method on a null object reference and when the listener itself is added to the constructor of DBKong (line 40) for initialization the following error is thrown java.lang.StackOverflowError: stack size 8MB. All the above is referenced from DBKong.java.

    Any help would be appriciated

    bug help wanted 
    opened by 1407arjun 0
  • Bug: No response from server

    Bug: No response from server

    res.json(result) in app.js does not return any response. In the case where try/catch isn't used, the response is returned, but when exception handling is used then there is no response returned.

    bug 
    opened by 1407arjun 0
Releases(1.1.0)
Owner
Arjun
18 | App Dev | Tech Enthusiast
Arjun
A key-value database for Android

SnappyDB SnappyDB is a key-value database for Android it's an alternative for SQLite if you want to use a NoSQL approach. It allows you to store and g

Nabil Hachicha 1.8k Dec 28, 2022
Insanely easy way to work with Android Database.

Sugar ORM Insanely easy way to work with Android databases. Official documentation can be found here - Check some examples below. The example applicat

null 2.6k Dec 16, 2022
Android Database Performance Benchmarks

ℹ Check out our new performance test app that includes ObjectBox. Android Database Performance Benchmark This project evaluates Android databases and

Markus Junginger 80 Nov 25, 2022
Kodein-DB is a Kotlin/Multiplatform embedded NoSQL database that works on JVM, Android, Kotlin/Native and iOS.

Kodein-DB is a Kotlin/Multiplatform embedded NoSQL database that works on JVM, Android, Kotlin/Native and iOS. It is suited for client or mobile applications.

null 277 Dec 3, 2022
Android with Real-time Database

Android with Real-time Database It was too much effort to build my own real-time database, but the result really satisfying, so it was worth it. Note

null 4 Jun 14, 2022
Realm is a mobile database: a replacement for SQLite & ORMs

Realm is a mobile database that runs directly inside phones, tablets or wearables. This repository holds the source code for the Java version of Realm

Realm 11.4k Jan 9, 2023
ObjectBox is a superfast lightweight database for objects

ObjectBox Java (Kotlin, Android) ObjectBox is a superfast object-oriented database with strong relation support. ObjectBox is embedded into your Andro

ObjectBox 4.1k Dec 30, 2022
A helper library to help using Room with existing pre-populated database [].

Room now supports using a pre-packaged database out of the box, since version 2.2.0 https://developer.android.com/jetpack/androidx/releases/room#2.2.0

Ibrahim Eid 136 Nov 29, 2022
A library for reading Shared Preferences and Database values within the application.

AppDataReader A library for reading and writing Shared Preferences and Database values of the application within the device. Advantages of using this

Anshul Jain 124 Nov 25, 2022
A quick and easy database manager plugin library for your DBFlow databases.

DBFlowManager A quick and easy database manager and viewer plugin library for your DBFlow databases to view, insert, delete, update the tables directl

Wajahat Karim 26 Oct 21, 2022