Skip to content

Commit

Permalink
Fix AS (#3370)
Browse files Browse the repository at this point in the history
* Fix AS

* Fix AS in IntelliJ test

* Workaround for not working DEFAULT usage

Co-authored-by: hfhbd <hfhbd@users.noreply.github.com>
  • Loading branch information
hfhbd and hfhbd committed Jul 15, 2022
1 parent af1e044 commit dfacc9d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
Expand Up @@ -25,6 +25,7 @@
parserImports=[
// If you want to use a token from the core grammar it must be statically imported.
"static com.alecstrong.sql.psi.core.psi.SqlTypes.DEFAULT"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.AS"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.LOCK"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.VALUE"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.VALUES"
Expand All @@ -49,7 +50,7 @@ stmt_clojure_stmt_list ::= {stmt} ';' ( {stmt} ';' ) * {
extends="app.cash.sqldelight.core.lang.psi.ClojureStmtListMixin"
pin(".*") = 1
}
column_type ::= {type_name} [ 'AS' ( VALUE | LOCK | ('@' annotation) * java_type_name ) ] {
column_type ::= {type_name} [ AS ( VALUE | LOCK | ('@' annotation) * java_type_name ) ] {
implements=[
"com.alecstrong.sql.psi.core.psi.SqlColumnType";
"app.cash.sqldelight.core.lang.psi.TypedColumn"
Expand Down
Expand Up @@ -62,8 +62,7 @@ class SyntaxErrors {
)

assertThat(result.errors).containsExactly(
"Test.sq: (2, 8): Reserved keyword in sqlite",
"Test.sq: (2, 16): Expected 'AS', got 'as'",
"Test.sq: (2, 16): ')', ',', <column constraint real> or AS expected, got 'as'",
)
}
}
@@ -1,13 +1,15 @@
CREATE TABLE dog (
name VARCHAR(8) NOT NULL,
breed VARCHAR(40) NOT NULL,
is_good BOOLEAN DEFAULT TRUE NOT NULL
is_good BOOLEAN DEFAULT TRUE NOT NULL,
id INTEGER NOT NULL,
id_bigger_than_ten BOOLEAN AS kotlin.Boolean GENERATED ALWAYS AS (id > 10) NOT NULL
);

insertDog:
INSERT INTO dog
VALUES (?, ?, ?);
INSERT INTO dog (name, breed, is_good, id)
VALUES (?, ?, ?, ?);

selectDogs:
SELECT *
FROM dog;
FROM dog;
Expand Up @@ -29,13 +29,15 @@ class HsqlTest {
}

@Test fun simpleSelect() {
database.dogQueries.insertDog("Tilda", "Pomeranian", true)
database.dogQueries.insertDog("Tilda", "Pomeranian", true, 1)
assertThat(database.dogQueries.selectDogs().executeAsOne())
.isEqualTo(
Dog(
name = "Tilda",
breed = "Pomeranian",
is_good = true,
id = 1,
id_bigger_than_ten = false,
),
)
}
Expand Down
Expand Up @@ -9,10 +9,10 @@ import kotlin.collections.Set;
import org.jetbrains.annotations.Nullable;

CREATE TABLE hockeyPlayer(
column1 TEXT as @Nullable String NOT NULL,
column2 TEXT as OffsetDateTime NOT NULL,
column3 TEXT as List<String> NOT NULL,
column4 TEXT as Integer NOT NULL,
column5 TEXT as Map<Int, Int> NOT NULL,
column6 TEXT as List<Short> NOT NULL
);
column1 TEXT AS @Nullable String NOT NULL,
column2 TEXT AS OffsetDateTime NOT NULL,
column3 TEXT AS List<String> NOT NULL,
column4 TEXT AS Integer NOT NULL,
column5 TEXT AS Map<Int, Int> NOT NULL,
column6 TEXT AS List<Short> NOT NULL
);

0 comments on commit dfacc9d

Please sign in to comment.