All Projects → dariopellegrini → Storagedone Android

dariopellegrini / Storagedone Android

Licence: mit
Kotlin library to make easy using local document-oriented database in Android apps.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Storagedone Android

Nodejs Firestore
Node.js client for Google Cloud Firestore: a NoSQL document database built for automatic scaling, high performance, and ease of application development.
Stars: ✭ 475 (+2538.89%)
Mutual labels:  database, nosql
Redis Marshal
Lightweight Redis data exploration tool
Stars: ✭ 16 (-11.11%)
Mutual labels:  database, nosql
Csharp Driver
DataStax C# Driver for Apache Cassandra
Stars: ✭ 477 (+2550%)
Mutual labels:  database, nosql
Tinydb
TinyDB is a lightweight document oriented database optimized for your happiness :)
Stars: ✭ 4,713 (+26083.33%)
Mutual labels:  database, nosql
Litedb
LiteDB - A .NET NoSQL Document Store in a single data file - https://www.litedb.org
Stars: ✭ 6,133 (+33972.22%)
Mutual labels:  database, nosql
Sleekdb
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.
Stars: ✭ 450 (+2400%)
Mutual labels:  database, nosql
Nitrite Java
Java embedded nosql document store
Stars: ✭ 538 (+2888.89%)
Mutual labels:  database, nosql
Mongo
The MongoDB Database
Stars: ✭ 20,883 (+115916.67%)
Mutual labels:  database, nosql
Restheart
RESTHeart - The REST API for MongoDB
Stars: ✭ 659 (+3561.11%)
Mutual labels:  database, nosql
Zeppelin
Web-based notebook that enables data-driven, interactive data analytics and collaborative documents with SQL, Scala and more.
Stars: ✭ 5,513 (+30527.78%)
Mutual labels:  database, nosql
Awesome Elasticsearch
A curated list of the most important and useful resources about elasticsearch: articles, videos, blogs, tips and tricks, use cases. All about Elasticsearch!
Stars: ✭ 4,168 (+23055.56%)
Mutual labels:  database, nosql
Libmdbx
One of the fastest embeddable key-value ACID database without WAL. libmdbx surpasses the legendary LMDB in terms of reliability, features and performance.
Stars: ✭ 729 (+3950%)
Mutual labels:  database, nosql
Objectbox Java
ObjectBox is a superfast lightweight database for objects
Stars: ✭ 3,950 (+21844.44%)
Mutual labels:  database, nosql
Orientdb
OrientDB is the most versatile DBMS supporting Graph, Document, Reactive, Full-Text and Geospatial models in one Multi-Model product. OrientDB can run distributed (Multi-Master), supports SQL, ACID Transactions, Full-Text indexing and Reactive Queries. OrientDB Community Edition is Open Source using a liberal Apache 2 license.
Stars: ✭ 4,394 (+24311.11%)
Mutual labels:  database, nosql
Dbreeze
C# .NET MONO NOSQL ( key value store embedded ) ACID multi-paradigm database management system.
Stars: ✭ 383 (+2027.78%)
Mutual labels:  database, nosql
Arangojs
The official ArangoDB JavaScript driver.
Stars: ✭ 503 (+2694.44%)
Mutual labels:  database, nosql
Bitnami Docker Redis
Bitnami Redis Docker Image
Stars: ✭ 317 (+1661.11%)
Mutual labels:  database, nosql
Kache
A simple in memory cache written using go
Stars: ✭ 349 (+1838.89%)
Mutual labels:  database, nosql
Corfudb
A cluster consistency platform
Stars: ✭ 539 (+2894.44%)
Mutual labels:  database, nosql
Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+3883.33%)
Mutual labels:  database, nosql

StorageDone-Android

Kotlin library to make easy using local document-oriented database in Android apps.

Installation

Edit your build.gradle file

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Then add as dependency to your app/build.gradle

dependencies {
    ...
    implementation 'com.github.dariopellegrini:StorageDone-Android:v0.7'
}

Usage

StorageDone lets you save models in a local database very easily.

First create a model

data class Teacher(val id: String,
                   val name: String?,
                   val surname: String?,
                   val age: Int?,
                   val cv: String?)

Then create a StorageDoneDatabase object and save an instance of a model in it

val database = StorageDoneDatabase(context, "teachers")
val teacher = Teacher("id1", "Sarah", "Jones", 29, "https://my.cv.com/sarah_jones")

try {
    database.insert(teacher)
} catch(e: Exception) {
    Log.e("StorageDone", e.localizedMessage)
}

Reading database content will retrieve an array of the decleared model

try {
  val teachers = database.get<List<Teacher>>()
} catch(e: Exception) {
  Log.e("StorageDone", e.localizedMessage)
}

Other methods allow filtering and deletion.

Primary key

A model can implement PrimaryKey interface, in order to have an attribute set as database primary key

data class Teacher(val id: String,
                   val name: String?,
                   val surname: String?,
                   val age: Int?,
                   val cv: String?): PrimaryKey {
    override fun primaryKey(): String {
        return "id"
    }
}

Primary keys come in combination with insert or update methods

val teachers = listOf(Teacher(id: "id1", name: "Sarah", surname: "Jones", age: 29, cv: "https://my.cv.com/sarah_jones"),
                Teacher(id: "id2", name: "Silvia", surname: "Jackson", age: 29, cv: "https://my.cv.com/silvia_jackson"),
                Teacher(id: "id3", name: "John", surname: "Jacobs", age: 30, cv: "https://my.cv.com/john_jackobs"))      
try {
        this.insertOrUpdate(teachers)
    } catch (e: Exception) {
        Log.e("StorageDone", e.localizedMessage)
    }

Coroutines

Every operation has its suspending version. Each can be used through suspending extension

database.suspending.insertOrUpdate(teachers)

database.suspending.insert(teachers)

val teachers: List<Teacher> = database.suspending.get()

database.suspending.delete(map("id" to "id2"))

Operators

Database objects can use different functions, which wrap try-catch logic and give a more compact way to access database

// Insert or update
database += teachers

// Read
val teachers: List<Teacher> = database.all()

// Filter
val filteredTeachers: List<Teacher> = database filter mapOf("id" to "id2")

// Delete if model implements PrimaryKey protocol
database -= teachers

Queries

Get and delete commands can use queries. Queries can be built in different ways, using custom operators

// Equal
"id" equal "id1"

// Comparison (Numeric only)
"age" greaterThan 20
"age" greaterThanOrEqual 20
"age" lessThan 20
"age" lessThanOrEqual 20
"age" between (10 to 20)

// Is null
"age".isNull

// Is not null
"age".isNotNull

// Value inside array
"id" inside listOf("id1", "id2", "id3")

// Array contains value
"array" contains "A1"

// Like
"name" like "A%"

// Regex
"city" regex "\\bEng.*e\\b"

// Dates comparisons
"dateCreated" greaterThan Date()
"dateCreated" greaterOrEqualThan Date()
"dateCreated" lessThan Date()
"dateCreated" lessOrEqualThan Date()
"dateCreated" betweenDates (Date() to Date())

// And
and(expression1, expression2, expression3)

// Or
or(expression1, expression2, expression3)

database.get(expression)

Ordering

Ordering on queries is performed using extension properties on the attributes' names. It's possible to use more of them to achive an order priority on attributes.

val orderedTeachers = database.get<Teacher>("dateCreated".ascending, "name".ascending)

Live queries

Using live queries it's possible to observe database changes.

// All elements
val liveQuery = database.live<Teacher> {
    teachers ->
        Log.i("LiveQuery", "$teachers")
}

// Elements with query
val liveQuery = database.live<Teacher>("id" equal "id1") {
    teachers ->
        Log.i("LiveQuery", "$teachers")
}

To cancel a live query simply call cancel on LiveQuery object.

liveQuery.cancel()

Advanced queries

Using advanced queries lets to specify filtering expression, ordering logic and priority, limit and skip values. All of these parameters are optional. The only limitation is that skip is ignored if limit parameter is not present.

val teachers = database.get<Teacher> {
    expression = or("id" equal "id1", "id" equal "id2")
    orderings = arrayOf("name".ascending, "date".descending)
    limit = 5
    skip = 1
}
            
val teachers: List<Teacher> = database filter {
    expression = or("id" equal "id1", "id" equal "id2")
    orderings = arrayOf("name".ascending, "date".descending)
    limit = 5
    skip = 1
}

val liveQuery = database.live<Teacher>({
    expression = or("id" equal "id1", "id" equal "id2")
    orderings = arrayOf("name".ascending, "date".descending)
    limit = 5
    skip = 1
}) {
    teachers ->
    Log.i("LiveQuery", "Count ${teachers.size}")
}

Fulltext search

Fulltext search needs to be configured with the parameters' name that should be indexed.
After that, a query can be performed with search text and with an optional advanced query.

// Define the index
database.fulltextIndex<Teacher>("id", "name", "surname", "age", "cv")

// All results
database.search<Teacher>("Silvia")

// Results with advanced query
database.search<Teacher>("Silvia") {
    orderings = arrayOf("age".ascending)
}

Author

Dario Pellegrini, [email protected]

Credits

CouchbaseLite Android

Logo

Antonio Petruccelli

License

StorageDone-Android is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].