Skip to content

Commit 29340aa

Browse files
JasonShinNydauron
andauthored
PR-256: mysql set support (#263)
* Add MySQL `SET` type support Adds `SET` to be represented as a `string` in Typescript since MySQL returns back a comma delimited string, and typescript expects a comma delimited string for update/insertion. * Add tests for `SET` type generation * organise tests * compatiblity.yaml retry * try 5 * linux only --------- Co-authored-by: Jareth Gomes <jarethgomes@gmail.com>
1 parent 1e76172 commit 29340aa

File tree

8 files changed

+206
-3
lines changed

8 files changed

+206
-3
lines changed

.github/workflows/compatibility.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ jobs:
7373

7474
- name: Build docker-compose services for integration tests (Linux only)
7575
if: runner.os == 'Linux'
76-
run: docker compose -f docker-compose.yml up -d
76+
uses: Wandalen/wretry.action@v3.5.0
77+
with:
78+
attempt_limit: 5
79+
attempt_delay: 5000
80+
command: docker compose -f docker-compose.yml up -d
7781
env:
7882
MYSQL_VERSION: ${{ matrix.db.mysql }}
7983
PG_VERSION: ${{ matrix.db.postgres }}
@@ -212,7 +216,11 @@ jobs:
212216
uses: actions/checkout@v3
213217

214218
- name: Build docker-compose services
215-
run: docker compose -f docker-compose.yml up -d
219+
uses: Wandalen/wretry.action@v3.5.0
220+
with:
221+
attempt_limit: 5
222+
attempt_delay: 5000
223+
command: docker compose -f docker-compose.yml up -d
216224
env:
217225
MYSQL_VERSION: ${{ matrix.db.mysql }}
218226
PG_VERSION: ${{ matrix.db.postgres }}

src/ts_generator/types/ts_query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl TsFieldType {
223223
) -> Self {
224224
match mysql_field_type.as_str() {
225225
"bigint" | "decimal" | "double" | "float" | "int" | "mediumint" | "smallint" | "year" => Self::Number,
226-
"binary" | "bit" | "blob" | "char" | "text" | "varbinary" | "varchar" => Self::String,
226+
"binary" | "bit" | "blob" | "char" | "text" | "varbinary" | "varchar" | "set" => Self::String,
227227
"tinyint" => Self::Boolean,
228228
"date" | "datetime" | "timestamp" => Self::Date,
229229
"json" => Self::Object,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export type SetInsert1Params = [[string | null]];
2+
3+
export interface ISetInsert1Result {
4+
5+
}
6+
7+
export interface ISetInsert1Query {
8+
params: SetInsert1Params;
9+
result: ISetInsert1Result;
10+
}
11+
12+
export type SetInsert2Params = [[number | null, string | null, string | null]];
13+
14+
export interface ISetInsert2Result {
15+
16+
}
17+
18+
export interface ISetInsert2Query {
19+
params: SetInsert2Params;
20+
result: ISetInsert2Result;
21+
}
22+
23+
export type SetInsert3Params = [[string | null], [string | null]];
24+
25+
export interface ISetInsert3Result {
26+
27+
}
28+
29+
export interface ISetInsert3Query {
30+
params: SetInsert3Params;
31+
result: ISetInsert3Result;
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export type SetInsert1Params = [[string | null]];
2+
3+
export interface ISetInsert1Result {
4+
5+
}
6+
7+
export interface ISetInsert1Query {
8+
params: SetInsert1Params;
9+
result: ISetInsert1Result;
10+
}
11+
12+
export type SetInsert2Params = [[number | null, string | null, string | null]];
13+
14+
export interface ISetInsert2Result {
15+
16+
}
17+
18+
export interface ISetInsert2Query {
19+
params: SetInsert2Params;
20+
result: ISetInsert2Result;
21+
}
22+
23+
export type SetInsert3Params = [[string | null], [string | null]];
24+
25+
export interface ISetInsert3Result {
26+
27+
}
28+
29+
export interface ISetInsert3Query {
30+
params: SetInsert3Params;
31+
result: ISetInsert3Result;
32+
}
33+

tests/demo/mysql/set_insert.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { sql } from 'sqlx-ts'
2+
3+
// MySQL SET type - insert single value
4+
const setInsert1 = sql`
5+
-- @db: db_mysql
6+
INSERT INTO
7+
random (set1)
8+
VALUES
9+
(?)
10+
`
11+
12+
// MySQL SET type - insert multiple columns including SET
13+
const setInsert2 = sql`
14+
-- @db: db_mysql
15+
INSERT INTO
16+
random (intz, set1, varchar1)
17+
VALUES
18+
(?, ?, ?)
19+
`
20+
21+
// MySQL SET type - insert with multiple rows
22+
const setInsert3 = sql`
23+
-- @db: db_mysql
24+
INSERT INTO
25+
random (set1)
26+
VALUES
27+
(?),
28+
(?)
29+
`
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export type SetSelect1Params = [];
2+
3+
export interface ISetSelect1Result {
4+
set1: string | null;
5+
}
6+
7+
export interface ISetSelect1Query {
8+
params: SetSelect1Params;
9+
result: ISetSelect1Result;
10+
}
11+
12+
export type SetSelect2Params = [];
13+
14+
export interface ISetSelect2Result {
15+
intz: number | null;
16+
set1: string | null;
17+
varchar1: string | null;
18+
}
19+
20+
export interface ISetSelect2Query {
21+
params: SetSelect2Params;
22+
result: ISetSelect2Result;
23+
}
24+
25+
export type SetSelect3Params = [number | null];
26+
27+
export interface ISetSelect3Result {
28+
set1: string | null;
29+
}
30+
31+
export interface ISetSelect3Query {
32+
params: SetSelect3Params;
33+
result: ISetSelect3Result;
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export type SetSelect1Params = [];
2+
3+
export interface ISetSelect1Result {
4+
set1: string | null;
5+
}
6+
7+
export interface ISetSelect1Query {
8+
params: SetSelect1Params;
9+
result: ISetSelect1Result;
10+
}
11+
12+
export type SetSelect2Params = [];
13+
14+
export interface ISetSelect2Result {
15+
intz: number | null;
16+
set1: string | null;
17+
varchar1: string | null;
18+
}
19+
20+
export interface ISetSelect2Query {
21+
params: SetSelect2Params;
22+
result: ISetSelect2Result;
23+
}
24+
25+
export type SetSelect3Params = [number | null];
26+
27+
export interface ISetSelect3Result {
28+
set1: string | null;
29+
}
30+
31+
export interface ISetSelect3Query {
32+
params: SetSelect3Params;
33+
result: ISetSelect3Result;
34+
}
35+

tests/demo/mysql/set_select.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { sql } from 'sqlx-ts'
2+
3+
// MySQL SET type - select single SET column
4+
const setSelect1 = sql`
5+
-- @db: db_mysql
6+
SELECT
7+
set1
8+
FROM
9+
random
10+
`
11+
12+
// MySQL SET type - select multiple columns including SET
13+
const setSelect2 = sql`
14+
-- @db: db_mysql
15+
SELECT
16+
intz,
17+
set1,
18+
varchar1
19+
FROM
20+
random
21+
`
22+
23+
// MySQL SET type - with WHERE clause
24+
const setSelect3 = sql`
25+
-- @db: db_mysql
26+
SELECT
27+
set1
28+
FROM
29+
random
30+
WHERE
31+
intz = ?
32+
`

0 commit comments

Comments
 (0)