Add an example to fn main()
This commit is contained in:
parent
5e4abc3cb1
commit
3c57b0eb6c
1 changed files with 77 additions and 0 deletions
|
|
@ -589,6 +589,83 @@ enum Error {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
use DbValue::*;
|
||||
use IndexableDbValue::*;
|
||||
use Operation::*;
|
||||
use ColumnSelection::*;
|
||||
use Condition::*;
|
||||
|
||||
let users_schema = {
|
||||
let id: ColumnPosition = 0;
|
||||
let name: ColumnPosition = 1;
|
||||
let age: ColumnPosition = 2;
|
||||
|
||||
TableSchema {
|
||||
table_name: "users".to_string(),
|
||||
primary_key: id,
|
||||
column_name_position_mapping: {
|
||||
let mut mapping: BiMap<ColumnName, ColumnPosition> = BiMap::new();
|
||||
mapping.insert("id".to_string(), id);
|
||||
mapping.insert("name".to_string(), name);
|
||||
mapping.insert("age".to_string(), age);
|
||||
mapping
|
||||
},
|
||||
types: vec![DbType::UUID, DbType::String, DbType::Int],
|
||||
}
|
||||
};
|
||||
let users = users_schema.table_name.clone();
|
||||
|
||||
|
||||
let mut state = State::new();
|
||||
state.interpret(Operation::CreateTable(users.clone(), users_schema)).unwrap();
|
||||
|
||||
let (id0, name0, age0) = (
|
||||
Indexable(UUID(0)),
|
||||
Indexable(String("Plato".to_string())),
|
||||
Indexable(Int(64))
|
||||
);
|
||||
println!("==INSERT Plato==");
|
||||
state.interpret(Insert(users.clone(), vec![
|
||||
("id".to_string(), id0.clone()),
|
||||
("name".to_string(), name0.clone()),
|
||||
("age".to_string(), age0.clone()),
|
||||
])).unwrap();
|
||||
|
||||
let (id1, name1, age1) = (
|
||||
Indexable(UUID(1)),
|
||||
Indexable(String("Aristotle".to_string())),
|
||||
Indexable(Int(20))
|
||||
);
|
||||
println!("==INSERT Aristotle==");
|
||||
state.interpret(Insert(users.clone(), vec![
|
||||
("id".to_string(), id1.clone()),
|
||||
("name".to_string(), name1.clone()),
|
||||
("age".to_string(), age1.clone()),
|
||||
])).unwrap();
|
||||
println!();
|
||||
|
||||
{
|
||||
let response: Response = state.interpret(Operation::Select(users.clone(), ColumnSelection::All, None)).unwrap();
|
||||
println!("==SELECT ALL==");
|
||||
println!("{:?}", response);
|
||||
println!();
|
||||
}
|
||||
{
|
||||
let response: Response = state.interpret(Select(users.clone(), All, Some(Eq("id".to_string(), id0.clone())))).unwrap();
|
||||
println!("==SELECT Plato==");
|
||||
println!("{:?}", response);
|
||||
println!();
|
||||
}
|
||||
|
||||
{
|
||||
let delete_response: Response = state.interpret(Delete(users.clone(), Some(Eq("id".to_string(), id0.clone())))).unwrap();
|
||||
println!("==DELETE Plato==");
|
||||
let response: Response = state.interpret(Select(users.clone(), Columns(vec!["name".to_string(), "id".to_string()]), None)).unwrap();
|
||||
println!("==SELECT All==");
|
||||
println!("{:?}", response);
|
||||
println!();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue