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;
|
pub mod models;
|
||||||
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use dotenv::dotenv;
|
use schema::invites::dsl::*;
|
||||||
|
use models::Invite;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
|
||||||
struct DB {
|
struct DB {
|
||||||
conn: MysqlConnection,
|
conn: MysqlConnection,
|
||||||
url: String,
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use super::models::*;
|
//use super::models::*;
|
||||||
use super::diesel::prelude::*;
|
use super::diesel::prelude::*;
|
||||||
use super::dotenv::dotenv;
|
use super::dotenv::dotenv;
|
||||||
use std::env;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_conn() {
|
fn test_conn() {
|
||||||
let url = env::var("DATABASE_URL")
|
dotenv().ok();
|
||||||
.expect("DATABASE_URL not set!");
|
let db = get_conn();
|
||||||
let conn = MysqlConnection::establish(&url)
|
println!("{}", db.url);
|
||||||
.expect(&format!("Error connecting to {}", url));
|
}
|
||||||
|
#[test]
|
||||||
let db = DB{conn, url};
|
fn get_conn_wrapper() {
|
||||||
|
dotenv().ok();
|
||||||
|
let db = get_conn();
|
||||||
println!("{}", db.url);
|
println!("{}", db.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#[derive(Queryable)]
|
#[derive(Serialize, Deserialize, Queryable)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
pub strid: String,
|
pub strid: String,
|
||||||
@ -14,7 +14,7 @@ pub struct channels {
|
|||||||
pub ctype: i64,
|
pub ctype: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable)]
|
#[derive(Serialize, Deserialize, Queryable)]
|
||||||
pub struct Invite {
|
pub struct Invite {
|
||||||
pub hash: i64,
|
pub hash: i64,
|
||||||
pub uses: i32, // simple that tracks the number of uses a thing has left
|
pub uses: i32, // simple that tracks the number of uses a thing has left
|
||||||
|
Loading…
Reference in New Issue
Block a user