diesel
This commit is contained in:
parent
a48d7bcc68
commit
c2f8993d07
3
.cargo/config
Executable file
3
.cargo/config
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
[target.x86_64-pc-windows-msvc.gnu]
|
||||||
|
rustc-link-search = ["C:\\Program Files\\PostgreSQL\\pg96\\lib"]
|
||||||
|
|
||||||
1
.env
Executable file
1
.env
Executable file
@ -0,0 +1 @@
|
|||||||
|
DATABASE_URL=postgres://cryps:craftbeer@localhost/cryps
|
||||||
@ -11,3 +11,5 @@ serde_derive = "1"
|
|||||||
serde_cbor = "0.9"
|
serde_cbor = "0.9"
|
||||||
ws = "*"
|
ws = "*"
|
||||||
env_logger = "*"
|
env_logger = "*"
|
||||||
|
diesel = { version = "1.0.0", features = ["postgres", "uuid"] }
|
||||||
|
dotenv = "0.9.0"
|
||||||
|
|||||||
7
WORKLOG.md
Normal file → Executable file
7
WORKLOG.md
Normal file → Executable file
@ -1,10 +1,13 @@
|
|||||||
* Battling
|
* Battling
|
||||||
* Cryp Serialisation
|
|
||||||
* RPC
|
|
||||||
* Logins
|
* Logins
|
||||||
* Cryp Ownership
|
* Cryp Ownership
|
||||||
* Matchmaking
|
* Matchmaking
|
||||||
|
* Lobbies
|
||||||
|
* Create
|
||||||
|
* Join
|
||||||
|
* Resolve
|
||||||
* Stats
|
* Stats
|
||||||
|
* Missions
|
||||||
|
|
||||||
* Cryp Generation
|
* Cryp Generation
|
||||||
*
|
*
|
||||||
|
|||||||
5
diesel.toml
Normal file
5
diesel.toml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# For documentation on how to configure this file,
|
||||||
|
# see diesel.rs/guides/configuring-diesel-cli
|
||||||
|
|
||||||
|
[print_schema]
|
||||||
|
file = "src/schema.rs"
|
||||||
0
migrations/.gitkeep
Normal file
0
migrations/.gitkeep
Normal file
6
migrations/00000000000000_diesel_initial_setup/down.sql
Normal file
6
migrations/00000000000000_diesel_initial_setup/down.sql
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
-- This file was automatically created by Diesel to setup helper functions
|
||||||
|
-- and other internal bookkeeping. This file is safe to edit, any future
|
||||||
|
-- changes will be added to existing projects as new migrations.
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
|
||||||
|
DROP FUNCTION IF EXISTS diesel_set_updated_at();
|
||||||
36
migrations/00000000000000_diesel_initial_setup/up.sql
Normal file
36
migrations/00000000000000_diesel_initial_setup/up.sql
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
-- This file was automatically created by Diesel to setup helper functions
|
||||||
|
-- and other internal bookkeeping. This file is safe to edit, any future
|
||||||
|
-- changes will be added to existing projects as new migrations.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Sets up a trigger for the given table to automatically set a column called
|
||||||
|
-- `updated_at` whenever the row is modified (unless `updated_at` was included
|
||||||
|
-- in the modified columns)
|
||||||
|
--
|
||||||
|
-- # Example
|
||||||
|
--
|
||||||
|
-- ```sql
|
||||||
|
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
|
||||||
|
--
|
||||||
|
-- SELECT diesel_manage_updated_at('users');
|
||||||
|
-- ```
|
||||||
|
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
|
||||||
|
BEGIN
|
||||||
|
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
|
||||||
|
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
|
||||||
|
BEGIN
|
||||||
|
IF (
|
||||||
|
NEW IS DISTINCT FROM OLD AND
|
||||||
|
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
|
||||||
|
) THEN
|
||||||
|
NEW.updated_at := current_timestamp;
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
1
migrations/2018-09-11-113648_create_lobbies/down.sql
Executable file
1
migrations/2018-09-11-113648_create_lobbies/down.sql
Executable file
@ -0,0 +1 @@
|
|||||||
|
DROP TABLE lobbies;
|
||||||
6
migrations/2018-09-11-113648_create_lobbies/up.sql
Executable file
6
migrations/2018-09-11-113648_create_lobbies/up.sql
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
CREATE TABLE lobbies (
|
||||||
|
id uuid PRIMARY KEY,
|
||||||
|
a uuid NOT NULL,
|
||||||
|
b uuid,
|
||||||
|
data bytea
|
||||||
|
);
|
||||||
@ -91,16 +91,22 @@ pub fn test_battle() {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use *;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pve_test() {
|
fn pve_test() {
|
||||||
// let player = Cryp::new()
|
let player = Cryp::new()
|
||||||
// .named("ca phe sua da".to_string())
|
.named("ca phe sua da".to_string())
|
||||||
// .level(2)
|
.level(2)
|
||||||
// .create();
|
.create();
|
||||||
|
|
||||||
// levelling(player);
|
levelling(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn battle_test() {
|
||||||
|
test_battle();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
src/db.rs
Executable file
13
src/db.rs
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
use diesel::prelude::*;
|
||||||
|
use diesel::pg::PgConnection;
|
||||||
|
use dotenv::dotenv;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
pub fn establish_connection() -> PgConnection {
|
||||||
|
dotenv().ok();
|
||||||
|
|
||||||
|
let database_url = env::var("DATABASE_URL")
|
||||||
|
.expect("DATABASE_URL must be set");
|
||||||
|
PgConnection::establish(&database_url)
|
||||||
|
.expect(&format!("Error connecting to {}", database_url))
|
||||||
|
}
|
||||||
6
src/lib.rs
Executable file
6
src/lib.rs
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
extern crate uuid;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate diesel;
|
||||||
|
|
||||||
|
pub mod schema;
|
||||||
|
pub mod models;
|
||||||
@ -3,6 +3,10 @@ extern crate uuid;
|
|||||||
extern crate ws;
|
extern crate ws;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate diesel;
|
||||||
|
extern crate dotenv;
|
||||||
|
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_cbor;
|
extern crate serde_cbor;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -14,6 +18,8 @@ mod net;
|
|||||||
mod combat;
|
mod combat;
|
||||||
mod skill;
|
mod skill;
|
||||||
mod rpc;
|
mod rpc;
|
||||||
|
mod schema;
|
||||||
|
mod models;
|
||||||
|
|
||||||
use net::{start};
|
use net::{start};
|
||||||
|
|
||||||
|
|||||||
9
src/models.rs
Executable file
9
src/models.rs
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
use diesel::sql_types::{Uuid,Bytea};
|
||||||
|
|
||||||
|
#[derive(Queryable)]
|
||||||
|
pub struct Lobby {
|
||||||
|
pub id: Uuid,
|
||||||
|
pub a: Uuid,
|
||||||
|
pub b: Uuid,
|
||||||
|
pub data: Bytea,
|
||||||
|
}
|
||||||
8
src/schema.rs
Executable file
8
src/schema.rs
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
table! {
|
||||||
|
lobbies (id) {
|
||||||
|
id -> Uuid,
|
||||||
|
a -> Uuid,
|
||||||
|
b -> Nullable<Uuid>,
|
||||||
|
data -> Nullable<Bytea>,
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user