Hello, how it would be possible to maintain multip...
# squarelibraries
j
Hello, how it would be possible to maintain multiple (as many as possible) vaults (databases) like various password managers have - Enpass, 1Password, etc. using SqlDelight? Let's say user could add a vault and new database file would be created for it. When user opens the app, all vaults (databases) could be accessed within the app and user could add/remove to/from the specified vault (database). As of now I am able to only open one database connection on a single path via SqlDriver. Are there any good practices for this or how do they manage to do it? Thanks.
m
Why would each vault need to be a new database? Can't you have a table: Vaults with the fields name, id and encryption_key Then another table Secrets: With the fields: id, name, vault_id
1
j
I like multiple databases 'cause it makes the sign-out implementation very easy to get right
👍 1
h
What about creating multiple drivers with different urls/paths?
j
@Magnus Lundberg it would reduce the size of the database, the performance of queries & backups would improve. Your idea is valid, but what if each vault has thousands of records, each vault has to be synchronized separately, this kind of becomes hard in one single database, or am I missing something?
m
I'm currently doing what Philip suggests - just creating specific database for every user:
Copy code
class MyRepository(private val databaseDriverFactory: DatabaseDriverFactory): Repository {

    private lateinit var databaseDriver: SqlDriver

    // databaseName is just user id
    // cipherKey because I'm using SQLCipher
    override fun initDatabase(databaseName: String, cipherKey: String) {
        if (::databaseDriver.isInitialized) databaseDriver.close()
        databaseDriver = databaseDriverFactory.createDriver(databaseName, cipherKey)
        // create database
    }
    // queries
}
j
@MJegorovas this is probably not what was meant by this topic, since you create only one database (driver) instance when opening the app, right? How your repository implementation can handle when user has many databases and wants to access them all to view/modify the data? Do you create this
MyRepository
instance as many times as there are different databases assigned the user?
m
Yeah sorry, misread that you need multiple access at the same time.