Oracle SQL Tools
A crate that makes simple Oracle SQL queries easy to implement into your codebase. Built as an extension to the Rust-oracle crate (required).
How To Use
Set Up Dependencies
Add these inside your cargo.toml
file:
[]
= "0.1"
= "0.5"
# chrono is required if you're working with dates
= "0.4"
Implement FormatData
Trait for Local Enums
To use the .prep_data()
method on a vector or grid that uses an enum you created as the values, you need to implement the trait FormatData
for it.
Implement FormatData
Trait for Foreign Enums
If you need to implement the trait on a enum from a crate you imported:
use SomeForeignType;
;
Examples
Select
let conn: Connection = match connect?;
let col_names: = vec!;
let table_data: = col_names.prep_data.select?;
Is the same as:
SELECT employee_id, name, job_title, department, business_unit FROM my_table;
Insert
let conn: Connection = match connect?;
let data: = vec!;
// `res` is [oracle::Connection] that's Atomically Reference Counted
let res: = data.prep_data.insert?;
// `res` has the executed Batch(es), you only need to commit it
res.commit?;
Ok
Is the same as:
INSERT ALL
INTO my_table (ColA, ColB, ColC) VALUES ('A1', 'B1', 'C1')
INTO my_table (ColA, ColB, ColC) VALUES ('A2', 'B2', 'C2')
INTO my_table (ColA, ColB, ColC) VALUES ('A3', 'B3', 'C3')
SELECT 1 FROM dual;
Or in Oracle 23c
:
INSERT INTO my_table (ColA, ColB, ColC) VALUES
('A1', 'B1', 'C1'),
('A2', 'B2', 'C2'),
('A3', 'B3', 'C3');