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"

          ...

  </application>   

...

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:
  ...
  
        new DBKong(getApplicationContext(), timeout, new OnInitListener() {
            @Override
            public void onInit(boolean init, Error error) {
                if (init && error == null) {
                    String uri = "mongodb+srv://admin:<password>@<cluster_name>.1oqwt.mongodb.net/<database_name>?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
Issues
  • 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
MySQL Server, the world's most popular open source database, and MySQL Cluster, a real-time, open source transactional database.

Copyright (c) 2000, 2021, Oracle and/or its affiliates. This is a release of MySQL, an SQL database server. License information can be found in the

MySQL 8k Jul 4, 2022
A mini database for learning database

A mini database for learning database

Chuckie Tan 3 Nov 3, 2021
The fastest database-library on Android OS.

Android SQLite3 NDK 封装 Demo下载 (操作:按钮新增 按钮查询 点按编辑 长按删除) 写在前面 sqlite3 开源、集成简单(现在的版本只有2个文件 sqlite3.h sqlite3.c) 这个库抽离自 Telegram 的开源代码、作者:DrKLO 我个人感觉 Tele

水银灯、 2 Dec 27, 2021
Experimental Rendering Backend for Manim.

Maki Mathematical Animation and Knickknack Inscriber (Maki), an experimental rendering backend for Manim. References christopher-besch/opengl_referenc

Christopher Besch 21 Jun 23, 2022
A simple flutter application to maintain basic personal notes. A showcase on how to use fastAPI as backend

Flutter App Notes with FastApi as backend A simple flutter application to maintain basic personal notes. The backend of this app was built with FastAP

António Pedro 5 May 31, 2022
OrioleDB – building a modern cloud-native storage engine

OrioleDB is a new storage engine for PostgreSQL, bringing a modern approach to database capacity, capabilities and performance to the world's most-loved database platform.

OrioleDB 1.1k Jul 3, 2022
A type safe SQL template library for C++

sqlpp11 A type safe embedded domain specific language for SQL queries and results in C++ Documentation is found in the wiki So what is this about? SQL

Roland Bock 2k Jul 2, 2022
ESE is an embedded / ISAM-based database engine, that provides rudimentary table and indexed access.

Extensible-Storage-Engine A Non-SQL Database Engine The Extensible Storage Engine (ESE) is one of those rare codebases having proven to have a more th

Microsoft 780 Jun 13, 2022
Nebula Graph is a distributed, fast open-source graph database featuring horizontal scalability and high availability

Nebula Graph is an open-source graph database capable of hosting super large scale graphs with dozens of billions of vertices (nodes) and trillions of edges, with milliseconds of latency.

vesoft inc. 807 Jun 30, 2022
DuckDB is an in-process SQL OLAP Database Management System

DuckDB is an in-process SQL OLAP Database Management System

DuckDB 5.4k Jun 27, 2022
TimescaleDB is an open-source database designed to make SQL scalable for time-series data.

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.

Timescale 13.3k Jun 27, 2022
Beryl-cli is a client for the BerylDB database server

Beryl-cli is a client for the BerylDB database server. It offers multiple commands and is designed to be fast and user-friendly.

BerylDB 11 Apr 21, 2022
PolarDB for PostgreSQL (PolarDB for short) is an open source database system based on PostgreSQL.

PolarDB for PostgreSQL (PolarDB for short) is an open source database system based on PostgreSQL. It extends PostgreSQL to become a share-nothing distributed database, which supports global data consistency and ACID across database nodes, distributed SQL processing, and data redundancy and high availability through Paxos based replication. PolarDB is designed to add values and new features to PostgreSQL in dimensions of high performance, scalability, high availability, and elasticity. At the same time, PolarDB remains SQL compatibility to single-node PostgreSQL with best effort.

Alibaba 2.3k Jun 30, 2022
A MariaDB-based command line tool to connect to OceanBase Database.

什么是 OceanBase Client OceanBase Client(简称 OBClient) 是一个基于 MariaDB 开发的客户端工具。您可以使用 OBClient 访问 OceanBase 数据库的集群。OBClient 采用 GPL 协议。 OBClient 依赖 libobclie

OceanBase 47 Mar 16, 2022
A proxy server for OceanBase Database.

OceanBase Database Proxy TODO: some badges here OceanBase Database Proxy (ODP for short) is a dedicated proxy server for OceanBase Database. OceanBase

OceanBase 76 Apr 6, 2022
OceanBase is an enterprise distributed relational database with high availability, high performance, horizontal scalability, and compatibility with SQL standards.

What is OceanBase database OceanBase Database is a native distributed relational database. It is developed entirely by Alibaba and Ant Group. OceanBas

OceanBase 4.4k Jun 27, 2022
SOCI - The C++ Database Access Library

Originally, SOCI was developed by Maciej Sobczak at CERN as abstraction layer for Oracle, a Simple Oracle Call Interface. Later, several database backends have been developed for SOCI, thus the long name has lost its practicality. Currently, if you like, SOCI may stand for Simple Open (Database) Call Interface or something similar.

SOCI 1.1k Jun 25, 2022
StarRocks is a next-gen sub-second MPP database for full analysis senarios, including multi-dimensional analytics, real-time analytics and ad-hoc query, formerly known as DorisDB.

StarRocks is a next-gen sub-second MPP database for full analysis senarios, including multi-dimensional analytics, real-time analytics and ad-hoc query, formerly known as DorisDB.

StarRocks 2.7k Jun 26, 2022
BaikalDB, A Distributed HTAP Database.

BaikalDB supports sequential and randomised realtime read/write of structural data in petabytes-scale. BaikalDB is compatible with MySQL protocol and it supports MySQL style SQL dialect, by which users can migrate their data storage from MySQL to BaikalDB seamlessly.

Baidu 955 Jun 30, 2022