commiting old but nearly done work before goal shifting
This commit is contained in:
parent
4c1820f910
commit
6634641937
@ -6,33 +6,62 @@ pub mod schema;
|
||||
pub mod models;
|
||||
|
||||
use diesel::prelude::*;
|
||||
use dotenv::dotenv;
|
||||
use schema::invites::dsl::*;
|
||||
use models::Invite;
|
||||
use std::env;
|
||||
|
||||
|
||||
struct DB {
|
||||
conn: MysqlConnection,
|
||||
url: String,
|
||||
}
|
||||
|
||||
fn get_conn() -> DB {
|
||||
let url_ = env::var("DATABASE_URL")
|
||||
.expect("DATABASE_URL not set!");
|
||||
|
||||
DB {
|
||||
url: url_.clone(),
|
||||
conn: MysqlConnection::establish(&url_)
|
||||
.expect(&format!("Error connecting to {}", url_)),
|
||||
}
|
||||
}
|
||||
|
||||
impl DB {
|
||||
pub fn get_invite(&mut self) {
|
||||
let connection = get_conn();
|
||||
let results = invites
|
||||
.filter(uses.eq(1))
|
||||
.limit(5)
|
||||
.load::<Invite>(&connection.conn)
|
||||
.expect("Error loading posts");
|
||||
|
||||
for i in results {
|
||||
println!("hash {}", i.hash);
|
||||
println!("uses {}", i.uses);
|
||||
println!("timestamp {}", i.expire);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate diesel;
|
||||
|
||||
use super::*;
|
||||
use super::models::*;
|
||||
//use super::models::*;
|
||||
use super::diesel::prelude::*;
|
||||
use super::dotenv::dotenv;
|
||||
use std::env;
|
||||
|
||||
#[test]
|
||||
fn test_conn() {
|
||||
let url = env::var("DATABASE_URL")
|
||||
.expect("DATABASE_URL not set!");
|
||||
let conn = MysqlConnection::establish(&url)
|
||||
.expect(&format!("Error connecting to {}", url));
|
||||
|
||||
let db = DB{conn, url};
|
||||
dotenv().ok();
|
||||
let db = get_conn();
|
||||
println!("{}", db.url);
|
||||
}
|
||||
#[test]
|
||||
fn get_conn_wrapper() {
|
||||
dotenv().ok();
|
||||
let db = get_conn();
|
||||
println!("{}", db.url);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#[derive(Queryable)]
|
||||
#[derive(Serialize, Deserialize, Queryable)]
|
||||
pub struct User {
|
||||
pub id: u64,
|
||||
pub strid: String,
|
||||
@ -14,7 +14,7 @@ pub struct channels {
|
||||
pub ctype: i64,
|
||||
}
|
||||
|
||||
#[derive(Queryable)]
|
||||
#[derive(Serialize, Deserialize, Queryable)]
|
||||
pub struct Invite {
|
||||
pub hash: i64,
|
||||
pub uses: i32, // simple that tracks the number of uses a thing has left
|
||||
|
Loading…
Reference in New Issue
Block a user