-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48e8976
commit b15a196
Showing
10 changed files
with
129 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
sqldelight-compiler/src/test/kotlin/app/cash/sqldelight/core/BindArgsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
sqldelight-gradle-plugin/src/test/integration-sqlite-json/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 { | ||
QueryWrapper { | ||
packageName = "app.cash.sqldelight.integration" | ||
dialect("app.cash.sqldelight:sqlite-3-18-dialect:${app.cash.sqldelight.VersionKt.VERSION}") | ||
module("app.cash.sqldelight:sqlite-json-module:${app.cash.sqldelight.VersionKt.VERSION}") | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation deps.sqliteJdbc | ||
implementation "app.cash.sqldelight:sqlite-driver:${app.cash.sqldelight.VersionKt.VERSION}" | ||
implementation deps.truth | ||
implementation("com.squareup.moshi:moshi:1.13.0") | ||
} |
1 change: 1 addition & 0 deletions
1
sqldelight-gradle-plugin/src/test/integration-sqlite-json/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
apply from: "../settings.gradle" |
21 changes: 21 additions & 0 deletions
21
.../integration-sqlite-json/src/main/sqldelight/app/cash/sqldelight/integration/JsonTable.sq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE TABLE user( | ||
name TEXT NOT NULL PRIMARY KEY, | ||
phone TEXT | ||
); | ||
|
||
insertUser: | ||
INSERT INTO user | ||
VALUES (?, ?); | ||
|
||
byAreaCode: | ||
SELECT DISTINCT user.name | ||
FROM user, json_each(user.phone) | ||
WHERE json_each.value LIKE :areaCode || '-%'; | ||
|
||
byAreaCode2: | ||
SELECT name FROM user WHERE phone LIKE :areaCode || '-%' | ||
UNION | ||
SELECT user.name | ||
FROM user, json_each(user.phone) | ||
WHERE json_valid(user.phone) | ||
AND json_each.value LIKE :areaCode || '-%'; |
53 changes: 53 additions & 0 deletions
53
...integration-sqlite-json/src/test/java/app/cash/sqldelight/integration/IntegrationTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package app.cash.sqldelight.integration | ||
|
||
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver | ||
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver.Companion.IN_MEMORY | ||
import com.google.common.truth.Truth.assertThat | ||
import com.squareup.moshi.Moshi | ||
import com.squareup.moshi.Types | ||
import com.squareup.moshi.adapter | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class IntegrationTests { | ||
private val moshi = Moshi.Builder().build() | ||
|
||
private lateinit var queryWrapper: QueryWrapper | ||
private lateinit var jsonQueries: JsonTableQueries | ||
|
||
@Before fun before() { | ||
val database = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY) | ||
QueryWrapper.Schema.create(database) | ||
|
||
queryWrapper = QueryWrapper(database) | ||
jsonQueries = queryWrapper.jsonTableQueries | ||
} | ||
|
||
@Test fun jsonArray() { | ||
with(jsonQueries) { | ||
insertUser("user1", jsonPhones("704-555-5555", "705-555-5555")) | ||
insertUser("user2", jsonPhones("604-555-5555", "605-555-5555")) | ||
assertThat(byAreaCode(areaCode = "704").executeAsList()).containsExactly( | ||
"user1" | ||
) | ||
} | ||
} | ||
|
||
@Test fun jsonArrayOrLiteral() { | ||
with(jsonQueries) { | ||
insertUser("user1", jsonPhones("704-555-5555", "705-555-5555")) | ||
insertUser("user2", jsonPhones("604-555-5555", "605-555-5555")) | ||
insertUser("user3", "704-666-6666") | ||
assertThat(byAreaCode2(areaCode = "704").executeAsList()).containsExactly( | ||
"user1", | ||
"user3" | ||
) | ||
} | ||
} | ||
|
||
private fun jsonPhones(vararg phoneNumbers: String): String { | ||
val adapter = | ||
moshi.adapter<List<String>>(Types.newParameterizedType(List::class.java, String::class.java)) | ||
return adapter.toJson(phoneNumbers.toList()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters