Update the usage example

This commit is contained in:
Ivan Ukhov 2015-06-14 11:33:55 -04:00
parent a31345da43
commit 610aea0221
4 changed files with 35 additions and 36 deletions

View File

@ -15,12 +15,10 @@ cargo run --example workflow
```rust
extern crate sqlite;
use std::fs;
use std::path::PathBuf;
use std::path::Path;
fn main() {
let path = setup();
let database = sqlite::open(&path).unwrap();
let database = sqlite::open(&Path::new(":memory:")).unwrap();
database.execute(r#"
CREATE TABLE `users` (id INTEGER, name VARCHAR(255));
@ -34,14 +32,6 @@ fn main() {
true
}).unwrap();
}
fn setup() -> PathBuf {
let path = PathBuf::from("database.sqlite3");
if fs::metadata(&path).is_ok() {
fs::remove_file(&path).unwrap();
}
path
}
```
## Contributing

View File

@ -1,11 +1,9 @@
extern crate sqlite;
use std::fs;
use std::path::PathBuf;
use std::path::Path;
fn main() {
let path = setup();
let database = sqlite::open(&path).unwrap();
let database = sqlite::open(&Path::new(":memory:")).unwrap();
database.execute(r#"
CREATE TABLE `users` (id INTEGER, name VARCHAR(255));
@ -19,11 +17,3 @@ fn main() {
true
}).unwrap();
}
fn setup() -> PathBuf {
let path = PathBuf::from("database.sqlite3");
if fs::metadata(&path).is_ok() {
fs::remove_file(&path).unwrap();
}
path
}

View File

@ -1,3 +1,27 @@
//! Interface to [SQLite][1].
//!
//! ## Example
//!
//! ```
//! use std::path::Path;
//!
//! let database = sqlite::open(&Path::new(":memory:")).unwrap();
//!
//! database.execute(r#"
//! CREATE TABLE `users` (id INTEGER, name VARCHAR(255));
//! INSERT INTO `users` (id, name) VALUES (1, 'Alice');
//! "#).unwrap();
//!
//! database.process("SELECT * FROM `users`;", |pairs| {
//! for &(column, value) in pairs.iter() {
//! println!("{} = {}", column, value.unwrap());
//! }
//! true
//! }).unwrap();
//! ```
//!
//! [1]: https://www.sqlite.org
#![allow(unused_unsafe)]
extern crate libc;

View File

@ -1,10 +1,6 @@
extern crate sqlite;
extern crate temporary;
use std::path::PathBuf;
use std::thread;
use temporary::Directory;
macro_rules! ok(
($result:expr) => ($result.unwrap());
);
@ -13,13 +9,13 @@ macro_rules! ok(
fn workflow() {
use sqlite::Binding::*;
use sqlite::State;
use std::path::Path;
macro_rules! pair(
($one:expr, $two:expr) => (($one, Some($two)));
);
let (path, _directory) = setup();
let database = ok!(sqlite::open(&path));
let database = ok!(sqlite::open(&Path::new(":memory:")));
let sql = r#"CREATE TABLE `users` (id INTEGER, name VARCHAR(255), age REAL);"#;
ok!(database.execute(sql));
@ -60,8 +56,12 @@ fn workflow() {
fn stress() {
use sqlite::Binding::*;
use sqlite::State;
use std::path::PathBuf;
use std::thread;
use temporary::Directory;
let (path, _directory) = setup();
let directory = ok!(Directory::new("sqlite"));
let path = directory.path().join("database.sqlite3");
let database = ok!(sqlite::open(&path));
let sql = r#"CREATE TABLE `users` (id INTEGER, name VARCHAR(255), age REAL);"#;
@ -84,8 +84,3 @@ fn stress() {
assert!(guard.join().unwrap());
}
}
fn setup() -> (PathBuf, Directory) {
let directory = ok!(Directory::new("sqlite"));
(directory.path().join("database.sqlite3"), directory)
}