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

Function setup_test_db

tests/decimal_optimization_test.rs:7–58  ·  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 tables - some with decimal columns, some without
17
18 // Table with only integer columns
19 conn.execute(
20 "CREATE TABLE users (
21 id INTEGER PRIMARY KEY,
22 name TEXT,
23 age INTEGER,
24 active INTEGER
25 )",
26 [],
27 ).unwrap();
28
29 // Table with decimal columns
30 conn.execute(
31 "CREATE TABLE products (
32 id INTEGER PRIMARY KEY,
33 name TEXT,
34 price TEXT,
35 cost TEXT
36 )",
37 [],
38 ).unwrap();
39
40 conn.execute(
41 "INSERT INTO __pgsqlite_schema (table_name, column_name, pg_type, sqlite_type) VALUES
42 ('products', 'price', 'NUMERIC', 'DECIMAL'),
43 ('products', 'cost', 'NUMERIC', 'DECIMAL')",
44 [],
45 ).unwrap();
46
47 // Another table without decimal columns
48 conn.execute(
49 "CREATE TABLE categories (
50 id INTEGER PRIMARY KEY,
51 name TEXT,
52 parent_id INTEGER
53 )",
54 [],
55 ).unwrap();
56
57 conn
58}
59
60fn rewrite_query(conn: &Connection, sql: &str) -> Result<String, String> {
61 let dialect = PostgreSqlDialect {};

Calls 2

register_all_functionsFunction · 0.85
executeMethod · 0.45

Tested by

no test coverage detected