Skip to content

Commit

Permalink
✨ Init the storage module (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang authored Nov 27, 2023
1 parent ef933db commit 3310663
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ plugins {
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.kotlinSerialization) apply false
}
id("app.cash.sqldelight") version "2.0.0" apply false
}
10 changes: 10 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.kotlinSerialization)
id("app.cash.sqldelight") version "2.0.0"
}

sqldelight {
databases {
create("Database") {
packageName.set("com.clipevery")
}
}
}

kotlin {
Expand All @@ -28,6 +37,7 @@ kotlin {
implementation("br.com.devsrsouza.compose.icons:tabler-icons-desktop:1.1.0")
implementation("io.insert-koin:koin-core:3.5.0")
implementation("com.github.kwhat:jnativehook:2.2.2")
implementation("app.cash.sqldelight:sqlite-driver:2.0.0")
}
commonMain.dependencies {
implementation(compose.runtime)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.clipevery.data

import app.cash.sqldelight.db.SqlDriver
import com.clipevery.Database

expect class DriverFactory {
fun createDriver(): SqlDriver
}

fun createDatabase(driverFactory: DriverFactory): Database {
val driver = driverFactory.createDriver()
val database = Database(driver)

// Do more work with the database (see below).
return database;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE hockeyPlayer (
player_number INTEGER PRIMARY KEY NOT NULL,
full_name TEXT NOT NULL
);

CREATE INDEX hockeyPlayer_full_name ON hockeyPlayer(full_name);

INSERT INTO hockeyPlayer (player_number, full_name)
VALUES (15, 'Ryan Getzlaf');
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.clipevery.data

import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
import com.clipevery.Database

actual class DriverFactory {
actual fun createDriver(): SqlDriver {
val driver: SqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
Database.Schema.create(driver)
return driver
}
}

0 comments on commit 3310663

Please sign in to comment.