MCPcopy Create free account
hub / github.com/erans/pgsqlite / setup_test_db

Function setup_test_db

tests/implicit_cast_test.rs:7–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5use sqlparser::dialect::PostgreSqlDialect;
6
7fn setup_test_db() -> Connection {
8 let conn = Connection::open_in_memory().unwrap();
9
10 // Initialize metadata table
11 TypeMetadata::init(&conn).unwrap();
12
13 // Register decimal functions
14 pgsqlite::functions::register_all_functions(&conn).unwrap();
15
16 // Create test tables
17 conn.execute(
18 "CREATE TABLE products (
19 id INTEGER PRIMARY KEY,
20 name TEXT,
21 price TEXT,
22 quantity INTEGER,
23 category_id INTEGER
24 )",
25 [],
26 ).unwrap();
27
28 // Insert metadata for NUMERIC columns
29 conn.execute(
30 "INSERT INTO __pgsqlite_schema (table_name, column_name, pg_type, sqlite_type) VALUES
31 ('products', 'id', 'INT4', 'INTEGER'),
32 ('products', 'price', 'NUMERIC', 'DECIMAL'),
33 ('products', 'quantity', 'INT4', 'INTEGER'),
34 ('products', 'category_id', 'INT4', 'INTEGER')",
35 [],
36 ).unwrap();
37
38 conn.execute(
39 "CREATE TABLE orders (
40 id INTEGER PRIMARY KEY,
41 product_id INTEGER,
42 amount TEXT,
43 discount_pct TEXT
44 )",
45 [],
46 ).unwrap();
47
48 conn.execute(
49 "INSERT INTO __pgsqlite_schema (table_name, column_name, pg_type, sqlite_type) VALUES
50 ('orders', 'product_id', 'INT4', 'INTEGER'),
51 ('orders', 'amount', 'NUMERIC', 'DECIMAL'),
52 ('orders', 'discount_pct', 'NUMERIC', 'DECIMAL')",
53 [],
54 ).unwrap();
55
56 conn
57}
58
59fn rewrite_query(conn: &Connection, sql: &str) -> Result<String, String> {
60 let dialect = PostgreSqlDialect {};

Calls 2

register_all_functionsFunction · 0.85
executeMethod · 0.45

Tested by

no test coverage detected