Skip to content
This repository was archived by the owner on Apr 27, 2019. It is now read-only.

Commit d21997b

Browse files
author
jcesar
committed
merged Fiedzia initial mysql support, added examples for mysql
1 parent 29b2cce commit d21997b

30 files changed

+1147
-171
lines changed

Cargo.lock

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ rusqlite = "*"
3131
time = "*"
3232
r2d2 = "*"
3333
r2d2_postgres = "*"
34+
mysql = "*"

MySQL.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## connecting to mysql
2+
3+
mysql -u root -h localhost -p
4+
5+
6+
create user 'test'@'localhost' identified by 'test';
7+
8+
create user 'bazaar'@'localhost' identified by 'b4z44r';
9+
10+
SET PASSWORD FOR 'test'@'localhost' = password('test');
11+
12+
create database bazaar_v6;
13+
14+
15+
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP on bazaar.* to 'bazaar'@'localhost';

examples/complex_query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl IsDao for Photo{
4040
fn main(){
4141
let url = "postgres://postgres:p0stgr3s@localhost/bazaar_v6";
4242
let mut pool = ManagedPool::init(&url, 1);
43-
let db = pool.connect().unwrap();
43+
let mut db = pool.connect().unwrap();
4444

4545
let mut query = Query::select_all();
4646

@@ -60,7 +60,7 @@ fn main(){
6060
.asc("product.name")
6161
.desc("product.created")
6262
;
63-
let frag = query.build(db.as_ref());
63+
let frag = query.build(db.as_ref_mut());
6464

6565
let expected = "
6666
SELECT *

examples/delete_category.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use rustorm::pool::ManagedPool;
1313
fn main(){
1414
let url = "postgres://postgres:p0stgr3s@localhost/bazaar_v6";
1515
let mut pool = ManagedPool::init(&url, 1);
16-
let db = pool.connect().unwrap();
16+
let mut db = pool.connect().unwrap();
1717
match Query::delete()
1818
.from_table("bazaar.category")
1919
.filter("name", Equality::LIKE, &"Test%")
20-
.execute(db.as_ref()){
20+
.execute(db.as_ref_mut()){
2121

2222
Ok(x) => println!("deleted {}", x),
2323
Err(e) => println!("Error {}", e)

examples/formal_usage.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ impl IsTable for Product{
6666
fn main(){
6767
let url = "postgres://postgres:p0stgr3s@localhost/bazaar_v6";
6868
let mut pool = ManagedPool::init(url, 1);
69-
let db = pool.connect();
69+
let mut db = pool.connect();
7070

7171
match db{
72-
Ok(db) => {
73-
show_product(db.as_ref());//borrow a database
72+
Ok(mut db) => {
73+
show_product(db.as_ref_mut());//borrow a database
7474
}
7575
Err(e) => {
7676
println!("Unable to connect to database {}", e);
@@ -79,7 +79,7 @@ fn main(){
7979
}
8080

8181
/// a dispatched controller with an accesss to a database reference
82-
fn show_product(db: &Database){
82+
fn show_product(db: &mut Database){
8383
let prod: Product = Query::select_all()
8484
.from_table("bazaar.product")
8585
.filter("name", Equality::EQ, &"GTX660 Ti videocard")

examples/get_exact_record.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ impl IsTable for Product{
9494
fn main(){
9595
let url = "postgres://postgres:p0stgr3s@localhost/bazaar_v6";
9696
let mut pool = ManagedPool::init(&url, 1);
97-
let db = pool.connect().unwrap();
98-
let em = EntityManager::new(db.as_ref());
97+
let mut db = pool.connect().unwrap();
98+
let mut em = EntityManager::new(db.as_ref_mut());
9999

100100
let pid = Uuid::parse_str("6db712e6-cc50-4c3a-8269-451c98ace5ad").unwrap();
101101
let prod: Product = em.get_exact(&pid).unwrap();

examples/get_one_product_photo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl IsTable for Photo{
5555
fn main(){
5656
let url = "postgres://postgres:p0stgr3s@localhost/bazaar_v6";
5757
let mut pool = ManagedPool::init(url, 1);
58-
let db = pool.connect().unwrap();
58+
let mut db = pool.connect().unwrap();
5959

6060
let photo: Photo = Query::select_all()
6161
.column("photo.url")
@@ -65,7 +65,7 @@ fn main(){
6565
.left_join_table("bazaar.photo",
6666
"product_photo.photo_id", "photo.photo_id")
6767
.filter("product.name", Equality::EQ, &"GTX660 Ti videocard")
68-
.collect_one(db.as_ref()).unwrap();
68+
.collect_one(db.as_ref_mut()).unwrap();
6969

7070
println!("photo: {} {}",photo.photo_id, photo.url.unwrap());
7171
}

examples/insert_category.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use rustorm::pool::ManagedPool;
77
fn main(){
88
let url = "postgres://postgres:p0stgr3s@localhost/bazaar_v6";
99
let mut pool = ManagedPool::init(&url, 1);
10-
let db = pool.connect().unwrap();
10+
let mut db = pool.connect().unwrap();
1111

1212
Query::insert()
1313
.set("name", &"Test Category112")
1414
.into_table(&"bazaar.category")
15-
.execute(db.as_ref());
15+
.execute(db.as_ref_mut());
1616
}

examples/insert_category_with_return.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ impl IsTable for Category{
106106
fn main(){
107107
let url = "postgres://postgres:p0stgr3s@localhost/bazaar_v6";
108108
let mut pool = ManagedPool::init(&url, 1);
109-
let db = pool.connect().unwrap();
109+
let mut db = pool.connect().unwrap();
110110

111111
let category: Category = Query::insert()
112112
.set("name", &"Test Category12121")
113113
.into_table(&"bazaar.category")
114114
.return_all()
115-
.collect_one(db.as_ref()).unwrap();
115+
.collect_one(db.as_ref_mut()).unwrap();
116116
println!("category: {}", category.name.unwrap());
117117
}

examples/multiple_dispatch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ fn main(){
7777
let mut pool = Arc::new(Mutex::new(ManagedPool::init(url, 5)));
7878
for i in 0..3000{
7979
let pool = pool.clone();
80-
let db: Platform = pool.lock().unwrap().connect().unwrap();//important to obtain a connection before opening a thread
80+
let mut db: Platform = pool.lock().unwrap().connect().unwrap();//important to obtain a connection before opening a thread
8181
thread::spawn(move || {
8282
println!("spawning thread {}", i);
83-
show_product(db.as_ref());//borrow a database
83+
show_product(db.as_ref_mut());//borrow a database
8484
});
8585
}
8686
thread::sleep_ms(5000);
8787
}
8888

8989

9090
/// a dispatched controller with an accesss to a database reference
91-
fn show_product(db: &Database){
91+
fn show_product(db: &mut Database){
9292
let prod: Product = Query::select_all()
9393
.from_table("bazaar.product")
9494
.filter("name", Equality::EQ, &"GTX660 Ti videocard")

0 commit comments

Comments
 (0)