1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*!
Sibyl is an [OCI][1]-based interface between Rust applications and Oracle databases. Sibyl supports both sync (blocking) and async (nonblocking) API.
## Blocking Mode Example
```
# #[cfg(feature="blocking")]
fn main() -> sibyl::Result<()> {
let oracle = sibyl::env()?;
let dbname = std::env::var("DBNAME").expect("database name");
let dbuser = std::env::var("DBUSER").expect("user name");
let dbpass = std::env::var("DBPASS").expect("password");
let session = oracle.connect(&dbname, &dbuser, &dbpass)?;
let stmt = session.prepare("
SELECT c.country_name, Median(e.salary)
FROM hr.employees e
JOIN hr.departments d ON d.department_id = e.department_id
JOIN hr.locations l ON l.location_id = d.location_id
JOIN hr.countries c ON c.country_id = l.country_id
JOIN hr.regions r ON r.region_id = c.region_id
WHERE r.region_name = :REGION_NAME
GROUP BY c.country_name
")?;
let rows = stmt.query("Europe")?;
while let Some(row) = rows.next()? {
let country_name : &str = row.get(0)?;
let median_salary : u16 = row.get(1)?;
println!("{:25}: {:>5}", country_name, median_salary);
}
Ok(())
}
# #[cfg(feature="nonblocking")]
# fn main() {}
```
## Nonblocking Mode Example
```
# #[cfg(feature="nonblocking")]
fn main() -> sibyl::Result<()> {
# use sibyl::block_on;
block_on(async {
let oracle = sibyl::env()?;
let dbname = std::env::var("DBNAME").expect("database name");
let dbuser = std::env::var("DBUSER").expect("user name");
let dbpass = std::env::var("DBPASS").expect("password");
let session = oracle.connect(&dbname, &dbuser, &dbpass).await?;
let stmt = session.prepare("
SELECT c.country_name, Median(e.salary)
FROM hr.employees e
JOIN hr.departments d ON d.department_id = e.department_id
JOIN hr.locations l ON l.location_id = d.location_id
JOIN hr.countries c ON c.country_id = l.country_id
JOIN hr.regions r ON r.region_id = c.region_id
WHERE r.region_name = :REGION_NAME
GROUP BY c.country_name
").await?;
let rows = stmt.query("Europe").await?;
while let Some(row) = rows.next().await? {
let country_name : &str = row.get(0)?;
let median_salary : u16 = row.get(1)?;
println!("{:25}: {:>5}", country_name, median_salary);
}
Ok(())
})
}
# #[cfg(feature="blocking")]
# fn main() {}
```
> Note that `block_on` in the example is an internal abstraction over `block_on` of different async executors. It is intended only to help running Sibyl's own tests and examples.
# Features
Sibyl has 2 main features - `blocking` and `nonblocking`. They are **exclusive** and **one** must be explicitly selected as neither is the default.
Sibyl compiled with a `nonblocking` feature needs to integrate with the async executor that the application uses. At the moment Sybil supports
[Tokio][2], [Actix][3], [async-std][4], and [async-global-executor][5]. One (and only one) of those must be selected together with a `nonblocking` feature:
| Feature | async Runtime |
| ------- | ------------- |
| `tokio` | [Tokio][2] |
| `actix` | [Actix][3] |
| `async-std` | [async-std][4] |
| `async-global` | [async-global-executor][5] |
Thus, for example, when Sibyl is used as a dependency, it might be included as:
```toml
[dependencies]
sibyl = { version = "0.6", features = ["blocking"] }
```
Or, when Sibyl is used in nonblocking mode as:
```toml
[dependencies]
sibyl = { version = "0.6", features = ["nonblocking", "tokio"] }
```
[1]: https://docs.oracle.com/en/database/oracle/oracle-database/19/lnoci/index.html
[2]: https://crates.io/crates/tokio
[3]: https://crates.io/crates/actix-rt
[4]: https://crates.io/crates/async-std
[5]: https://crates.io/crates/async-global-executor
*/
compile_error!;
compile_error!;
pub use ConnectionPool;
pub use ;
pub use Error;
pub use Environment;
pub use Session;
pub use ;
pub use ;
pub use NChar;
pub use ;
pub use Integer;
pub use ;
pub use LOB;
pub use Nvl;
/// A specialized `Result` type for Sibyl.
pub type Result<T> = Result;
/// Represents the `TIMESTAMP` data type. It stores year, month, day, hour, minute, second and fractional seconds.
pub type Timestamp<'a> = DateTime;
/// Represents the `TIMESTAMP WITH TIME ZONE` data type. It's a variant of `TIMESTAMP` that includes of a time zone region name or time zone offset in its value.
pub type TimestampTZ<'a> = DateTime;
/// Represents the `TIMESTAMP WITH LOCAL TIME ZONE` data type. It's a variant of `TIMESTAMP` that is normalized to the database time zone.
pub type TimestampLTZ<'a> = DateTime;
/// Represents `INTERVAL YEAR TO MONTH` data type. It stores a period of time in terms of years and months.
pub type IntervalYM<'a> = Interval;
/// Represents `INTERVAL DAY TO SECOND` data type. It stores a period of time in terms of days, hours, minutes, and seconds.
pub type IntervalDS<'a> = Interval;
/// A character large object locator.
pub type CLOB<'a> = ;
/// A binary large object locator.
pub type BLOB<'a> = ;
/// A locator to a large binary file.
pub type BFile<'a> = ;
/**
Returns a new environment handle, which is then used by the OCI functions.
While there can be multiple environments, most applications most likely will
need only one.
As nothing can outlive its environment, when only one environment is used,
it might be created either in the `main` function:
```
use sibyl as oracle; // pun intended :)
fn main() {
let oracle = oracle::env().expect("Oracle OCI environment");
// ...
}
```
and passed around, or it might be created statically:
```
use sibyl::{Environment, Result};
use once_cell::sync::OnceCell;
fn oracle() -> Result<&'static Environment> {
static OCI_ENV: OnceCell<Environment> = OnceCell::new();
OCI_ENV.get_or_try_init(||
sibyl::env()
)
}
fn main() -> Result<()> {
let oracle = oracle()?;
// ...
Ok(())
}
```
*/