crates.io Documentation MIT

include-oracle-sql is an extension of include-sql for using Oracle SQL in Rust. It completes include-sql by providing impl_sql macro to generate database access methods from the included SQL. include-oracle-sql uses Sibyl for database access.

Example

Write your SQL and save it in a file. For example, let's say the following is saved as library.sql in the project's sql folder:

```sql

-- name: getloanedbooks ?

-- Returns the list of books loaned to a patron

-- # Parameters

-- param: user_id: &str - user ID

SELECT booktitle FROM library WHERE loanedto = :user_id ORDER BY 1

-- name: loan_books!

-- Updates the book records to reflect loan to a patron

-- # Parameters

-- param: book_titles: &str - book titles

-- param: user_id: &str - user ID

UPDATE library SET loanedto = :userid , loanedon = currenttimestamp WHERE booktitle IN (:booktitles) ```

And then use it in Rust as:

```rust use includeoraclesql::{includesql, implsql};

include_sql!("sql/library.sql");

fn main() -> sibyl::Result<()> { let dbname = std::env::var("DBNAME").expect("database name"); let dbuser = std::env::var("DBUSER").expect("user name"); let db_pass = std::env::var("DBPASS").expect("password");

let oracle = sibyl::env()?;
let session = oracle.connect(&db_name, &db_user, &db_pass)?;

db.loan_books(&["War and Peace", "Gone With the Wind"], "Sheldon Cooper")?;

db.get_loaned_books("Sheldon Cooper", |row| {
    let book_title : &str = row.get("BOOK_TITLE")?;
    println!("{}", book_title);
    Ok(())
})?;

Ok(())

} ```

Documentation

The included documentation describes the supported SQL file format and provides additional details on the generated code.

💥 Breaking Changes in 0.2