Fast simple json-based Database in Kotlin
the idea is to keep a fast and simple way to store and retrieve data without using alot of resources and to maintain a flexible storage and keep it simple !
- java
- kotlin
- android
- scala
- groovy
- more !
A bundle of sets that can be accessed by a name
A bundle of rows that can be accessed by a id
The id
can be either a string
or int
Consider it as a table without schema
A row is a bundle of different data types that can share keys
You can have an integer
string
boolean
JSON Array
JSON Object
with this same key name
var db = Bella("test")
this will create a database named test to the IOAgent an IOAgent is a class that will differ between environments for example standard java and android io
var db = Bella("test")
var set = db.BellaSet(1)
// or
var set = Bella("test").BellaSet("mySet")
//
a data row is where you put and get your data
// automatic id
var row = BellaRow()
// numeric id
var row = BellaRow(3)
// string id
var row = BellaRow("awesomerow")
// same key many values !
// inline builder
var row = BellaRow()
.put("hi","hi !")
.put("hi",1)
.put("hi",true)
.put("hi",JSONObject())
.put("hi",JSONArray())
// or outside builder ;)
row.put("bye","bye !")
var row = ...
var value = row.getString("hi")
var value = row.getInt("hi")
var value = row.getBoolean("hi")
var value = row.getJsonObject("hi")
var value = row.getJsonArray("hi")
// you can set or get manually here as well !
var row = ...
// json objects
var string = row.strings
var string = row.ints
var string = row.booleans
var string = row.objects
var string = row.arrays
var row = BellaRow()
.put("hi", 1)
.put("hi", "hi")
.put("hi", true)
.put("hi", JSONArray().put(3))
// returns the id of our row
var id = db.insert(row)
// yes ! that simple
// the item is now a data row
var row = db.select(id)
row.getInt("hi")
// yes ! that simple
// the item is now a data row
var row = db.select(id)
// changes the integer one in the bundle
row.put("hi",3)
// and simply save it
db.save(row)
// select it completely
var row = db.select(id)
// or
var row = BellaRow(3)
// delete it
db.delete(row)
var db = Bella("test").BellaSet("my")
var id = db.insert(BellaRow()
.put("hi", 1)
.put("hi", "hi")
.put("hi", true)
.put("hi", JSONArray().put(3)))
var row = db.select(id)
row.put("hi",2)
db.save(row)
which results
0.rdp
{
"strings":{
"hi":"hi"
},
"ints":{
"hi":2
},
"booleans":{
"hi":true
},
"arrays":{
"hi":[
3
]
}
}