nightly(example): basic database structure and showcase
This commit is contained in:
commit
163c7ffc05
|
@ -0,0 +1 @@
|
||||||
|
/target
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,15 @@
|
||||||
|
[package]
|
||||||
|
name = "oauth"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tide = "0.16.0"
|
||||||
|
async-std = { version = "1.8.0", features = ["attributes"] }
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
tokio = { version = "1.37.0", features = ["full"] }
|
||||||
|
tokio-postgres = "0.7.10"
|
||||||
|
futures = "0.3.30"
|
|
@ -0,0 +1,13 @@
|
||||||
|
use tokio_postgres::{ NoTls, Error, tls::NoTlsStream };
|
||||||
|
|
||||||
|
pub struct Database {
|
||||||
|
client: tokio_postgres::Client,
|
||||||
|
connection: tokio_postgres::Connection<tokio_postgres::Socket, NoTlsStream>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub async fn new(host: &str, port: u16, user: &str, password: &str, dbname: &str) -> Result<Self, Error> {
|
||||||
|
let (client, connection) = tokio_postgres::connect(format!("host={} port={} user={} password={} dbname={}", host, port, user, password, dbname).as_str(), NoTls).await?;
|
||||||
|
Ok(Self { client, connection })
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
use async_std::io::prelude::SeekExt;
|
||||||
|
use tide::Request;
|
||||||
|
use tide::prelude::*;
|
||||||
|
|
||||||
|
|
||||||
|
use futures::executor::block_on;
|
||||||
|
|
||||||
|
mod db;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct Test {
|
||||||
|
x: i32,
|
||||||
|
y: i32
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Test {
|
||||||
|
fn new(x: i32, y: i32) -> Self {
|
||||||
|
Self { x, y }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let a = Test::new(2, 3);
|
||||||
|
let b = block_on(db::Database::new("localhost", 5432, "postgres", "configjson", "myoauth")).unwrap();
|
||||||
|
// let s = serde_json::to_string(&a);
|
||||||
|
// json!(a);
|
||||||
|
println!("{}", json!(a));
|
||||||
|
}
|
Loading…
Reference in New Issue