Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to open resource database files #77

Open
05nelsonm opened this issue Oct 14, 2023 · 3 comments
Open

Add ability to open resource database files #77

05nelsonm opened this issue Oct 14, 2023 · 3 comments

Comments

@05nelsonm
Copy link
Collaborator

05nelsonm commented Oct 14, 2023

Providing database file via resource and opening it should be possible. JDBC already offers this, but need to play around with its functionality.

@05nelsonm
Copy link
Collaborator Author

05nelsonm commented Oct 14, 2023

Might be beneficial, too, to make DatabasesDir throw exception if the provided path starts with file: to inhibit misuse of providing a file url.

@05nelsonm
Copy link
Collaborator Author

05nelsonm commented Oct 15, 2023

So, this is possible on JVM, but native side resource management is a tricky thing. Thinking something for the DSL being

// FactoryConfig.Builder

public fun resourceFilesystem(resourceDir: String, block: ResourceConfig.Builder.() -> Unit): Builder {
    // TODO
    //  - Configure config builder
    //  - Set resourceConfig with returned value
    //  - Set filesystemConfig with returned value

    // In the event filesystem is called after this, that should also clear the resourceFilesystem
    // 
    return this
}
class ResourceConfig private constructor (
) {

    public class Builder internal constructor(
        @JvmField
        public val resourceDir: String
    ) {
        // JVM
        @JvmField
        public var classLoader = Thread.currentThread().contextClassLoader

        // Also need to consider Android assets

        // Maybe some unique identifier producer???
        // like a hash of the resourceDir path + db name that will prefix the file
        // name or something.

        // public fun encryption(...)

        @JvmSynthetic
        internal fun build(): Pair<ResourceConfig, FilesystemConfig> {
            // FilesystemConfig will house the encryption and use the
            // temporary directory for DatabasesDir. There are no encryption
            // migrations needed for resources, so.

            // Some sort of resource extractor needs to be instantiated
            // here 
            TODO()
        }
    }
}

@05nelsonm
Copy link
Collaborator Author

05nelsonm commented Oct 15, 2023

Extraction of the resource to filesystem in the temp directory should be handled by sqlite-mc. It's subsequent deletion should also be handled. The way sqlite-jdbc is doing it is unfortunately not sufficient, especially on Android where the temp directory is actually the application cache dir which never really clears unless the user manually deletes the application cache, meaning resource extraction simply builds up and can be problematic over time.

Some things to note:

  • iOS/watchOS/tvOS the application temp directory will wipe the temp dir after ~60s in the background
  • There is no clear way to package resources for native in a .klib. Will require creating some sort of framework
    or configurable resource locator
  • Jvm/Android we have the ability to delete the file on exit, on native this is not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant