Skip to content

Commit

Permalink
Add migration test fixtures
Browse files Browse the repository at this point in the history
New test for MigrationQueryTest for Postgresql - not relevant for Sqlite as can't alter table to add primary keys

Add tests for compiler generation for single and compound primary keys
  • Loading branch information
griffio committed Feb 13, 2024
1 parent 7e6bd3b commit 7ced7f6
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class MigrationQueryTest {
checkFixtureCompiles("alter-table-alter-column", PostgreSqlDialect())
}

@Test fun `alter table add constraint`() {
checkFixtureCompiles("alter-table-add-constraint", PostgreSqlDialect())
}

@Test fun `varying query migration packages`() {
checkFixtureCompiles("varying-query-migration-packages", PostgreSqlDialect())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE TestSingle(
first INTEGER,
second TEXT
);

CREATE TABLE TestCompound (
first INTEGER,
second TEXT
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE TestSingle ADD PRIMARY KEY (first);
ALTER TABLE TestCompound ADD CONSTRAINT pk_first_second PRIMARY KEY (first, second);

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
selectSingle:
SELECT *
FROM TestSingle;

selectCompound:
SELECT *
FROM TestCompound;

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.example

import app.cash.sqldelight.Query
import app.cash.sqldelight.TransacterImpl
import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.driver.jdbc.JdbcCursor
import kotlin.Any
import kotlin.Int
import kotlin.String

public class DataQueries(
driver: SqlDriver,
) : TransacterImpl(driver) {
public fun <T : Any> selectSingle(mapper: (first: Int, second: String?) -> T): Query<T> =
Query(-79_317_191, arrayOf("TestSingle"), driver, "Data.sq", "selectSingle", """
|SELECT *
|FROM TestSingle
""".trimMargin()) { cursor ->
check(cursor is JdbcCursor)
mapper(
cursor.getInt(0)!!,
cursor.getString(1)
)
}

public fun selectSingle(): Query<TestSingle> = selectSingle { first, second ->
TestSingle(
first,
second
)
}

public fun <T : Any> selectCompound(mapper: (first: Int, second: String) -> T): Query<T> =
Query(-19_725_220, arrayOf("TestCompound"), driver, "Data.sq", "selectCompound", """
|SELECT *
|FROM TestCompound
""".trimMargin()) { cursor ->
check(cursor is JdbcCursor)
mapper(
cursor.getInt(0)!!,
cursor.getString(1)!!
)
}

public fun selectCompound(): Query<TestCompound> = selectCompound { first, second ->
TestCompound(
first,
second
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example

import kotlin.Int
import kotlin.String

public data class TestCompound(
public val first: Int,
public val second: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example

import kotlin.Int
import kotlin.String

public data class TestSingle(
public val first: Int,
public val second: String?,
)

0 comments on commit 7ced7f6

Please sign in to comment.