File tree Expand file tree Collapse file tree 6 files changed +49
-1
lines changed
main/kotlin/com/faire/sqldelight/dialects/cockroachdb/grammar
test/fixtures_cockroachdb/blob-data-type
sqldelight/com/faire/sqldelight/dialects/cockroachdb
test/kotlin/com/faire/sqldelight/dialects/cockroachdb Expand file tree Collapse file tree 6 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -12,4 +12,5 @@ This doesn't fully cover the whole SQL syntax of CockroachDB. It's a work in pro
12
12
* Supports STRING data type
13
13
* Supports storing index
14
14
* Supports unnamed index
15
- * Index tracking and validation has been disabled until there's a way to track unnamed indexes
15
+ * Index tracking and validation has been disabled until there's a way to track unnamed indexes
16
+ * Blob types (BYTEA, BLOB, BYTES)
Original file line number Diff line number Diff line change 74
74
75
75
overrides ::= table_constraint
76
76
| string_data_type
77
+ | blob_data_type
77
78
| generated_clause
78
79
| alter_table_rules
79
80
@@ -93,6 +94,12 @@ string_data_type ::= ((( 'CHARACTER' 'VARYING' ) | 'VARCHAR' | 'CHARACTER' | 'CH
93
94
override = true
94
95
}
95
96
97
+ blob_data_type ::= 'BYTEA' | 'BLOB' | 'BYTES' {
98
+ extends = "app.cash.sqldelight.dialects.postgresql.grammar.psi.impl.PostgreSqlBlobDataTypeImpl"
99
+ implements = "app.cash.sqldelight.dialects.postgresql.grammar.psi.PostgreSqlBlobDataType"
100
+ override = true
101
+ }
102
+
96
103
create_index_stmt ::= CREATE [ UNIQUE ] INDEX [ IF NOT EXISTS ] [ [ ansi_database_name DOT ] ansi_index_name ] ON ansi_table_name LP ansi_indexed_column ( COMMA ansi_indexed_column ) * RP ['STORING' LP ansi_indexed_column ( COMMA ansi_indexed_column ) * RP ] [ WHERE <<expr '-1'>> ] {
97
104
extends = "com.faire.sqldelight.dialects.cockroachdb.grammar.mixins.CreateIndexMixin"
98
105
implements = "com.alecstrong.sql.psi.core.psi.SqlCreateIndexStmt"
Original file line number Diff line number Diff line change
1
+ CREATE TABLE foo(
2
+ id INT NOT NULL ,
3
+ bar1 BYTEA NOT NULL ,
4
+ bar2 BLOB NOT NULL ,
5
+ bar3 BYTES NOT NULL ,
6
+ PRIMARY KEY (id)
7
+ ) ;
Original file line number Diff line number Diff line change
1
+ CREATE TABLE blob_data_types(
2
+ id INT NOT NULL,
3
+ bytea_col BYTEA NOT NULL,
4
+ blob_col BLOB NOT NULL,
5
+ bytes_col BYTES NOT NULL,
6
+ PRIMARY KEY (id)
7
+ );
Original file line number Diff line number Diff line change
1
+ create:
2
+ INSERT INTO blob_data_types VALUES ?;
3
+
4
+ selectAll:
5
+ SELECT *
6
+ FROM blob_data_types;
Original file line number Diff line number Diff line change 1
1
package com.faire.sqldelight.dialects.cockroachdb
2
2
3
+ import Blob_data_types
3
4
import Computed_column
4
5
import String_type
5
6
import app.cash.sqldelight.driver.jdbc.JdbcDriver
@@ -44,6 +45,25 @@ class IntegrationTest {
44
45
).containsExactlyInAnyOrder(" hello" , " world" )
45
46
}
46
47
48
+ @Test
49
+ fun `persist BLOB types` () {
50
+ val charset = Charsets .UTF_8
51
+ database.blobTypesQueries.create(
52
+ Blob_data_types (
53
+ id = 1 ,
54
+ bytea_col = " foo" .toByteArray(charset),
55
+ blob_col = " bar" .toByteArray(charset),
56
+ bytes_col = " baz" .toByteArray(charset),
57
+ ),
58
+ )
59
+ with (database.blobTypesQueries.selectAll().executeAsOne()) {
60
+ assertThat(id).isEqualTo(1 )
61
+ assertThat(bytea_col.toString(charset)).isEqualTo(" foo" )
62
+ assertThat(blob_col.toString(charset)).isEqualTo(" bar" )
63
+ assertThat(bytes_col.toString(charset)).isEqualTo(" baz" )
64
+ }
65
+ }
66
+
47
67
companion object {
48
68
private lateinit var database: CockroachDBIntegrationTesting
49
69
You can’t perform that action at this time.
0 commit comments