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

Function setup_test_db

tests/float_decimal_test.rs:8–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6use sqlparser::dialect::PostgreSqlDialect;
7
8fn setup_test_db() -> Connection {
9 let conn = Connection::open_in_memory().unwrap();
10
11 // Initialize metadata table
12 TypeMetadata::init(&conn).unwrap();
13
14 // Register decimal functions
15 pgsqlite::functions::register_all_functions(&conn).unwrap();
16
17 // Create test tables with REAL and DOUBLE PRECISION columns
18 conn.execute(
19 "CREATE TABLE measurements (
20 id INTEGER PRIMARY KEY,
21 temperature TEXT,
22 pressure TEXT,
23 humidity TEXT
24 )",
25 [],
26 ).unwrap();
27
28 conn.execute(
29 "INSERT INTO __pgsqlite_schema (table_name, column_name, pg_type, sqlite_type) VALUES
30 ('measurements', 'temperature', 'REAL', 'DECIMAL'),
31 ('measurements', 'pressure', 'DOUBLE PRECISION', 'DECIMAL'),
32 ('measurements', 'humidity', 'FLOAT4', 'DECIMAL')",
33 [],
34 ).unwrap();
35
36 conn.execute(
37 "CREATE TABLE calculations (
38 id INTEGER PRIMARY KEY,
39 value1 TEXT,
40 value2 TEXT,
41 result TEXT
42 )",
43 [],
44 ).unwrap();
45
46 conn.execute(
47 "INSERT INTO __pgsqlite_schema (table_name, column_name, pg_type, sqlite_type) VALUES
48 ('calculations', 'value1', 'FLOAT8', 'DECIMAL'),
49 ('calculations', 'value2', 'FLOAT4', 'DECIMAL'),
50 ('calculations', 'result', 'DOUBLE PRECISION', 'DECIMAL')",
51 [],
52 ).unwrap();
53
54 conn
55}
56
57fn rewrite_query(conn: &Connection, sql: &str) -> Result<String, String> {
58 let dialect = PostgreSqlDialect {};

Calls 2

register_all_functionsFunction · 0.85
executeMethod · 0.45

Tested by

no test coverage detected