Skip to content

Commit 03e6d5f

Browse files
committed
add tests for mysql
1 parent 96d459a commit 03e6d5f

30 files changed

Lines changed: 3387 additions & 2 deletions

.sqlxrc.sample.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"DB_PORT": 54321,
1212
"DB_USER": "postgres",
1313
"DB_PASS": "postgres",
14-
"DB_NAME": "postgres",
15-
"PG_SEARCH_PATH": "public,myschema"
14+
"DB_NAME": "postgres"
1615
},
1716
"db_mysql": {
1817
"DB_TYPE": "mysql",

playpen/db/mysql_migration.sql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,54 @@ CREATE TABLE random (
172172
-- JSON types
173173
json1 JSON
174174
);
175+
176+
-- JSON Test Data Table
177+
-- This table contains various JSON structures for testing JSON operators and functions
178+
CREATE TABLE json_test_data (
179+
id INT AUTO_INCREMENT PRIMARY KEY,
180+
name VARCHAR(100) NOT NULL,
181+
data JSON NOT NULL,
182+
metadata JSON,
183+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
184+
);
185+
186+
INSERT INTO json_test_data (name, data, metadata) VALUES
187+
-- Simple object
188+
('user_profile',
189+
'{"userId": 1, "username": "john_doe", "email": "john@example.com", "age": 30, "active": true}',
190+
'{"source": "api", "version": "1.0"}'),
191+
192+
-- Nested object with address
193+
('user_with_address',
194+
'{"userId": 2, "username": "jane_smith", "email": "jane@example.com", "address": {"street": "123 Main St", "city": "Springfield", "state": "IL", "zipCode": "62701", "country": "USA"}}',
195+
'{"source": "import", "version": "1.0"}'),
196+
197+
-- Array of items
198+
('shopping_cart',
199+
'{"cartId": 101, "items": [{"productId": 1, "name": "Laptop", "quantity": 1, "price": 999.99}, {"productId": 2, "name": "Mouse", "quantity": 2, "price": 25.50}], "totalPrice": 1050.99}',
200+
'{"source": "web", "version": "2.0"}'),
201+
202+
-- Array of strings
203+
('tags',
204+
'{"postId": 42, "title": "MySQL JSON Functions", "tags": ["database", "mysql", "json", "tutorial"], "published": true}',
205+
'{"source": "cms", "version": "1.0"}'),
206+
207+
-- Nested arrays and objects
208+
('game_stats',
209+
'{"playerId": 123, "stats": {"level": 50, "experience": 125000, "inventory": [{"slot": 1, "item": "Sword of Fire", "rarity": "legendary"}, {"slot": 2, "item": "Shield of Light", "rarity": "epic"}], "achievements": ["First Kill", "Level 50", "Legendary Item"]}}',
210+
'{"source": "game_server", "version": "3.0"}'),
211+
212+
-- Deep nesting
213+
('nested_config',
214+
'{"app": {"name": "MyApp", "version": "1.0.0", "settings": {"database": {"host": "localhost", "port": 3306, "credentials": {"username": "admin", "encrypted": true}}, "features": {"darkMode": true, "notifications": {"email": true, "push": false}}}}}',
215+
'{"source": "config", "version": "1.0"}'),
216+
217+
-- Array of objects with nulls
218+
('product_reviews',
219+
'{"productId": 456, "reviews": [{"reviewId": 1, "rating": 5, "comment": "Excellent product!", "reviewer": "Alice"}, {"reviewId": 2, "rating": 4, "comment": null, "reviewer": "Bob"}, {"reviewId": 3, "rating": 3, "comment": "Average", "reviewer": null}]}',
220+
'{"source": "reviews", "version": "1.0"}'),
221+
222+
-- Mixed types
223+
('analytics',
224+
'{"date": "2024-01-15", "metrics": {"visitors": 1500, "pageViews": 4500, "bounceRate": 0.35, "sources": {"organic": 850, "direct": 400, "referral": 250}}}',
225+
'{"source": "analytics", "version": "1.0"}');

playpen/db/postgres_migration.sql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,54 @@ INSERT INTO classes (name, specialization) VALUES
218218
('druid', '{"role": "hybrid", "weapon": "staff", "abilities": ["shapeshift", "moonfire", "regrowth"]}'),
219219
('mage', '{"role": "ranged", "weapon": "wand", "abilities": ["fireball", "frostbolt", "arcane blast"]}'),
220220
('warlock', '{"role": "ranged", "weapon": "dagger", "abilities": ["summon demon", "shadowbolt", "curse of agony"]}');
221+
222+
-- JSON Test Data Table
223+
-- This table contains various JSON structures for testing JSON operators and functions
224+
CREATE TABLE json_test_data (
225+
id SERIAL PRIMARY KEY,
226+
name VARCHAR(100) NOT NULL,
227+
data JSONB NOT NULL,
228+
metadata JSON,
229+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
230+
);
231+
232+
INSERT INTO json_test_data (name, data, metadata) VALUES
233+
-- Simple object
234+
('user_profile',
235+
'{"userId": 1, "username": "john_doe", "email": "john@example.com", "age": 30, "active": true}',
236+
'{"source": "api", "version": "1.0"}'),
237+
238+
-- Nested object with address
239+
('user_with_address',
240+
'{"userId": 2, "username": "jane_smith", "email": "jane@example.com", "address": {"street": "123 Main St", "city": "Springfield", "state": "IL", "zipCode": "62701", "country": "USA"}}',
241+
'{"source": "import", "version": "1.0"}'),
242+
243+
-- Array of items
244+
('shopping_cart',
245+
'{"cartId": 101, "items": [{"productId": 1, "name": "Laptop", "quantity": 1, "price": 999.99}, {"productId": 2, "name": "Mouse", "quantity": 2, "price": 25.50}], "totalPrice": 1050.99}',
246+
'{"source": "web", "version": "2.0"}'),
247+
248+
-- Array of strings
249+
('tags',
250+
'{"postId": 42, "title": "PostgreSQL JSON Functions", "tags": ["database", "postgresql", "json", "tutorial"], "published": true}',
251+
'{"source": "cms", "version": "1.0"}'),
252+
253+
-- Nested arrays and objects
254+
('game_stats',
255+
'{"playerId": 123, "stats": {"level": 50, "experience": 125000, "inventory": [{"slot": 1, "item": "Sword of Fire", "rarity": "legendary"}, {"slot": 2, "item": "Shield of Light", "rarity": "epic"}], "achievements": ["First Kill", "Level 50", "Legendary Item"]}}',
256+
'{"source": "game_server", "version": "3.0"}'),
257+
258+
-- Deep nesting
259+
('nested_config',
260+
'{"app": {"name": "MyApp", "version": "1.0.0", "settings": {"database": {"host": "localhost", "port": 5432, "credentials": {"username": "admin", "encrypted": true}}, "features": {"darkMode": true, "notifications": {"email": true, "push": false}}}}}',
261+
'{"source": "config", "version": "1.0"}'),
262+
263+
-- Array of objects with nulls
264+
('product_reviews',
265+
'{"productId": 456, "reviews": [{"reviewId": 1, "rating": 5, "comment": "Excellent product!", "reviewer": "Alice"}, {"reviewId": 2, "rating": 4, "comment": null, "reviewer": "Bob"}, {"reviewId": 3, "rating": 3, "comment": "Average", "reviewer": null}]}',
266+
'{"source": "reviews", "version": "1.0"}'),
267+
268+
-- Mixed types
269+
('analytics',
270+
'{"date": "2024-01-15", "metrics": {"visitors": 1500, "pageViews": 4500, "bounceRate": 0.35, "sources": {"organic": 850, "direct": 400, "referral": 250}}}',
271+
'{"source": "analytics", "version": "1.0"}');
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
export type JsonFieldAccessParams = [];
2+
3+
export interface IJsonFieldAccessResult {
4+
activeJson: string;
5+
ageJson: string;
6+
id: number;
7+
name: string;
8+
usernameJson: string;
9+
}
10+
11+
export interface IJsonFieldAccessQuery {
12+
params: JsonFieldAccessParams;
13+
result: IJsonFieldAccessResult;
14+
}
15+
16+
export type JsonFieldAccessTextParams = [];
17+
18+
export interface IJsonFieldAccessTextResult {
19+
active: number;
20+
age: number;
21+
email: string;
22+
id: number;
23+
name: string;
24+
username: string;
25+
}
26+
27+
export interface IJsonFieldAccessTextQuery {
28+
params: JsonFieldAccessTextParams;
29+
result: IJsonFieldAccessTextResult;
30+
}
31+
32+
export type JsonNestedAccessParams = [];
33+
34+
export interface IJsonNestedAccessResult {
35+
addressJson: string;
36+
city: any;
37+
cityJson: string;
38+
id: number;
39+
name: string;
40+
street: any;
41+
zipCode: any;
42+
}
43+
44+
export interface IJsonNestedAccessQuery {
45+
params: JsonNestedAccessParams;
46+
result: IJsonNestedAccessResult;
47+
}
48+
49+
export type JsonArrayAccessParams = [];
50+
51+
export interface IJsonArrayAccessResult {
52+
firstItemJson: string;
53+
firstItemName: any;
54+
firstItemPrice: number;
55+
id: number;
56+
itemsJson: string;
57+
name: string;
58+
secondItemJson: string;
59+
}
60+
61+
export interface IJsonArrayAccessQuery {
62+
params: JsonArrayAccessParams;
63+
result: IJsonArrayAccessResult;
64+
}
65+
66+
export type JsonPathAccessParams = [];
67+
68+
export interface IJsonPathAccessResult {
69+
firstItemJson: string;
70+
firstItemName: any;
71+
firstItemRarity: any;
72+
id: number;
73+
level: number;
74+
levelJson: string;
75+
name: string;
76+
}
77+
78+
export interface IJsonPathAccessQuery {
79+
params: JsonPathAccessParams;
80+
result: IJsonPathAccessResult;
81+
}
82+
83+
export type JsonDeepPathAccessParams = [];
84+
85+
export interface IJsonDeepPathAccessResult {
86+
darkMode: number;
87+
dbHost: any;
88+
dbHostJson: string;
89+
dbPort: number;
90+
emailNotifications: number;
91+
id: number;
92+
name: string;
93+
}
94+
95+
export interface IJsonDeepPathAccessQuery {
96+
params: JsonDeepPathAccessParams;
97+
result: IJsonDeepPathAccessResult;
98+
}
99+
100+
export type JsonFilterByFieldParams = [];
101+
102+
export interface IJsonFilterByFieldResult {
103+
email: string;
104+
id: number;
105+
name: string;
106+
username: string;
107+
}
108+
109+
export interface IJsonFilterByFieldQuery {
110+
params: JsonFilterByFieldParams;
111+
result: IJsonFilterByFieldResult;
112+
}
113+
114+
export type JsonNullHandlingParams = [];
115+
116+
export interface IJsonNullHandlingResult {
117+
firstComment: any;
118+
firstReviewer: any;
119+
id: number;
120+
secondComment: any;
121+
thirdComment: any;
122+
thirdReviewer: any;
123+
}
124+
125+
export interface IJsonNullHandlingQuery {
126+
params: JsonNullHandlingParams;
127+
result: IJsonNullHandlingResult;
128+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
export type JsonFieldAccessParams = [];
2+
3+
export interface IJsonFieldAccessResult {
4+
activeJson: string;
5+
ageJson: string;
6+
id: number;
7+
name: string;
8+
usernameJson: string;
9+
}
10+
11+
export interface IJsonFieldAccessQuery {
12+
params: JsonFieldAccessParams;
13+
result: IJsonFieldAccessResult;
14+
}
15+
16+
export type JsonFieldAccessTextParams = [];
17+
18+
export interface IJsonFieldAccessTextResult {
19+
active: number;
20+
age: number;
21+
email: string;
22+
id: number;
23+
name: string;
24+
username: string;
25+
}
26+
27+
export interface IJsonFieldAccessTextQuery {
28+
params: JsonFieldAccessTextParams;
29+
result: IJsonFieldAccessTextResult;
30+
}
31+
32+
export type JsonNestedAccessParams = [];
33+
34+
export interface IJsonNestedAccessResult {
35+
addressJson: string;
36+
city: any;
37+
cityJson: string;
38+
id: number;
39+
name: string;
40+
street: any;
41+
zipCode: any;
42+
}
43+
44+
export interface IJsonNestedAccessQuery {
45+
params: JsonNestedAccessParams;
46+
result: IJsonNestedAccessResult;
47+
}
48+
49+
export type JsonArrayAccessParams = [];
50+
51+
export interface IJsonArrayAccessResult {
52+
firstItemJson: string;
53+
firstItemName: any;
54+
firstItemPrice: number;
55+
id: number;
56+
itemsJson: string;
57+
name: string;
58+
secondItemJson: string;
59+
}
60+
61+
export interface IJsonArrayAccessQuery {
62+
params: JsonArrayAccessParams;
63+
result: IJsonArrayAccessResult;
64+
}
65+
66+
export type JsonPathAccessParams = [];
67+
68+
export interface IJsonPathAccessResult {
69+
firstItemJson: string;
70+
firstItemName: any;
71+
firstItemRarity: any;
72+
id: number;
73+
level: number;
74+
levelJson: string;
75+
name: string;
76+
}
77+
78+
export interface IJsonPathAccessQuery {
79+
params: JsonPathAccessParams;
80+
result: IJsonPathAccessResult;
81+
}
82+
83+
export type JsonDeepPathAccessParams = [];
84+
85+
export interface IJsonDeepPathAccessResult {
86+
darkMode: number;
87+
dbHost: any;
88+
dbHostJson: string;
89+
dbPort: number;
90+
emailNotifications: number;
91+
id: number;
92+
name: string;
93+
}
94+
95+
export interface IJsonDeepPathAccessQuery {
96+
params: JsonDeepPathAccessParams;
97+
result: IJsonDeepPathAccessResult;
98+
}
99+
100+
export type JsonFilterByFieldParams = [];
101+
102+
export interface IJsonFilterByFieldResult {
103+
email: string;
104+
id: number;
105+
name: string;
106+
username: string;
107+
}
108+
109+
export interface IJsonFilterByFieldQuery {
110+
params: JsonFilterByFieldParams;
111+
result: IJsonFilterByFieldResult;
112+
}
113+
114+
export type JsonNullHandlingParams = [];
115+
116+
export interface IJsonNullHandlingResult {
117+
firstComment: any;
118+
firstReviewer: any;
119+
id: number;
120+
secondComment: any;
121+
thirdComment: any;
122+
thirdReviewer: any;
123+
}
124+
125+
export interface IJsonNullHandlingQuery {
126+
params: JsonNullHandlingParams;
127+
result: IJsonNullHandlingResult;
128+
}

0 commit comments

Comments
 (0)