Skip to content

Commit

Permalink
Always create the database implementation (#3540)
Browse files Browse the repository at this point in the history
Co-authored-by: hfhbd <hfhbd@users.noreply.github.com>
  • Loading branch information
hfhbd and hfhbd committed Sep 29, 2022
1 parent 5ed758e commit 5fc354d
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 1 deletion.
Expand Up @@ -174,6 +174,7 @@ class SqlDelightEnvironment(
output = writer,
includeAll = true,
)
SqlDelightCompiler.writeImplementations(module, migrationFile, moduleName, writer)
}
logger("----- END ${migrationFile.name} in $timeTaken ms ------")
}
Expand Down
Expand Up @@ -72,7 +72,7 @@ object SqlDelightCompiler {

fun writeImplementations(
module: Module,
sourceFile: SqlDelightQueriesFile,
sourceFile: SqlDelightFile,
implementationFolder: String,
output: FileAppender,
) {
Expand Down
@@ -0,0 +1,26 @@
buildscript {
apply from: "${projectDir.absolutePath}/../buildscript.gradle"
}

apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'app.cash.sqldelight'

repositories {
maven {
url "file://${projectDir.absolutePath}/../../../../build/localMaven"
}
mavenCentral()
}

sqldelight {
NoQueries {
packageName = "app.cash.sqldelight.derive.schema.from.migrations.no.queries"
deriveSchemaFromMigrations = true
}
}

dependencies {
implementation libs.sqliteJdbc
implementation "app.cash.sqldelight:sqlite-driver:${app.cash.sqldelight.VersionKt.VERSION}"
implementation libs.truth
}
@@ -0,0 +1,9 @@
apply from: "../settings.gradle"

rootProject.name = 'derive-schema-no-queries'

buildCache {
local {
directory = new File(rootDir, 'build-cache')
}
}
@@ -0,0 +1,5 @@
CREATE TABLE person (
_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL
);
@@ -0,0 +1,18 @@
package app.cash.sqldelight.integration

import app.cash.sqldelight.derive.schema.from.migrations.no.queries.NoQueries
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
import org.junit.After
import org.junit.Test
import java.io.File

class IntegrationTests {
@After fun after() {
File("test.db").delete()
}

@Test fun `creating db works without query files`() {
val database = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
NoQueries.Schema.create(database)
}
}
Expand Up @@ -282,4 +282,13 @@ class IntegrationTest {
val result = runner.build()
assertThat(result.output).contains("BUILD SUCCESSFUL")
}

@Test fun `deriveSchemaFromMigrations creates a db without queries`() {
val runner = GradleRunner.create()
.withCommonConfiguration(File("src/test/derive-schema-no-queries"))
.withArguments("clean", "build", "--stacktrace")

val result = runner.build()
assertThat(result.output).contains("BUILD SUCCESSFUL")
}
}

0 comments on commit 5fc354d

Please sign in to comment.