This guide will walk you through setting up and using LightDB, a high-performance computational database. We'll use a sample application to explore its key features.
NOTE: This project uses Rapid (https://github.com/outr/rapid) for effects. It's somewhat similar to cats-effect, but
with a focus on virtual threads and simplicity. In a normal project, you likely wouldn't be using .sync() to invoke
each task, but for the purposes of this documentation, this is used to make the code execute blocking.
Ensure you have the following:
Scala installed
SBT (Scala Build Tool) installed
Add LightDB to Your Project
Add the following dependency to your build.sbt file:
valadam=Person(name ="Adam", age =21)
// adam: Person = Person(// name = "Adam",// age = 21,// city = None,// nicknames = Set(),// friends = List(),// _id = StringId(value = "fKJ5L8wKjw4dLiu31LWsCfOC6LsgJ6EG")// )
db.people.transaction { implicit txn =>
txn.insert(adam)
}.sync()
// res1: Person = Person(// name = "Adam",// age = 21,// city = None,// nicknames = Set(),// friends = List(),// _id = StringId(value = "fKJ5L8wKjw4dLiu31LWsCfOC6LsgJ6EG")// )
Retrieve records using filters:
db.people.transaction { txn =>
txn.query.filter(_.age BETWEEN20->29).toList.map { peopleIn20s =>
println(s"People in their 20s: $peopleIn20s")
}
}.sync()
// People in their 20s: List(Person(Adam,21,None,Set(),List(),StringId(bxvPuSxBZ3MJ7rihSEssM697Bq32xzFw)), Person(Adam,21,None,Set(),List(),StringId(fKJ5L8wKjw4dLiu31LWsCfOC6LsgJ6EG)))
Transactions:
LightDB ensures atomic operations within transactions.
Indexes:
Support for various indexes, like tokenized and field-based, ensures fast lookups.
Aggregation:
Perform aggregations such as min, max, avg, and sum.
Streaming:
Stream records for large-scale queries.
Backups and Restores:
Backup and restore databases seamlessly.
importlightdb.backup._importjava.io.FileDatabaseBackup.archive(db.stores, newFile("backup.zip")).sync()
// res5: Int = 3
Restore from a backup:
DatabaseRestore.archive(db, newFile("backup.zip")).sync()
// res6: Int = 3
Dispose of the database when done:
This guide provided an overview of using LightDB. Experiment with its features to explore the full potential of this high-performance database. For advanced use cases, consult the API documentation.