fixed compiler errors
also manually fixed scheme, as the automatic mapping uses Integer on PRIMARY KEY INTEGER, Integer manually replaced by BigInt
This commit is contained in:
parent
58f6b349df
commit
91deda2614
@ -7,4 +7,7 @@ edition = "2018"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
chrono = { features = ["serde"] }
|
||||||
diesel = { version = "*", features = ["sqlite"] }
|
diesel = { version = "*", features = ["sqlite"] }
|
||||||
|
serde = { version = "1.0" , features = ["derive"]}
|
||||||
|
# serde_json = "1.0"
|
@ -1,19 +1,20 @@
|
|||||||
use super::schema::*;
|
use chrono::{DateTime, Utc};
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Serialize, Queryable)]
|
#[derive(Serialize, Queryable)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
id: i64,
|
pub id: Option<i64>,
|
||||||
nickname: String,
|
pub nickname: Option<String>,
|
||||||
pronouns: String,
|
pub pronouns: Option<String>,
|
||||||
address_1_name: String,
|
pub address_1_name: Option<String>,
|
||||||
address_2_additional: String,
|
pub address_2_additional: Option<String>,
|
||||||
address_4_street: String,
|
pub address_4_street: Option<String>,
|
||||||
adress_house_number: String,
|
pub adress_house_number: Option<String>,
|
||||||
adress_city_code: String,
|
pub adress_city_code: Option<String>,
|
||||||
adress_country: String,
|
pub adress_country: Option<String>,
|
||||||
Ehrenaemter: String,
|
pub ehrenaemter: Option<String>,
|
||||||
gravatar_email: String,
|
pub gravatar_email: Option<String>,
|
||||||
Freitext: String,
|
pub freitext: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Queryable)]
|
#[derive(Serialize, Queryable)]
|
||||||
@ -30,11 +31,11 @@ pub struct UserLanguage {
|
|||||||
|
|
||||||
user_id: i64,
|
user_id: i64,
|
||||||
language_id: i64,
|
language_id: i64,
|
||||||
level: i64,
|
level: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Queryable)]
|
#[derive(Serialize, Queryable)]
|
||||||
pub struct skill {
|
pub struct Skill {
|
||||||
id: i64,
|
id: i64,
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
@ -44,8 +45,8 @@ pub struct UserExperience {
|
|||||||
id: i64,
|
id: i64,
|
||||||
user_id: i64,
|
user_id: i64,
|
||||||
description: String,
|
description: String,
|
||||||
start: Date,
|
start: DateTime<Utc>,
|
||||||
end: Date,
|
end: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Queryable)]
|
#[derive(Serialize, Queryable)]
|
||||||
@ -70,13 +71,13 @@ pub struct Topic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Queryable)]
|
#[derive(Serialize, Queryable)]
|
||||||
pub struct language {
|
pub struct Language {
|
||||||
id: i64,
|
id: i64,
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Queryable)]
|
#[derive(Serialize, Queryable)]
|
||||||
pub struct experience {
|
pub struct Experience {
|
||||||
id: i64,
|
id: i64,
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
@ -1,51 +1,51 @@
|
|||||||
table! {
|
table! {
|
||||||
contact_types (id) {
|
contact_types (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
name -> Nullable<Text>,
|
name -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
experiences (id) {
|
experiences (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
name -> Nullable<Text>,
|
name -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
languages (id) {
|
languages (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
name -> Nullable<Text>,
|
name -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
skills (id) {
|
skills (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
name -> Nullable<Text>,
|
name -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
topics (id) {
|
topics (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
name -> Nullable<Text>,
|
name -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
user_contacts (id) {
|
user_contacts (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
user_id -> Integer,
|
user_id -> BigInt,
|
||||||
contact_type_id -> Integer,
|
contact_type_id -> BigInt,
|
||||||
content_ -> Nullable<Text>,
|
content_ -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
user_experiences (id) {
|
user_experiences (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
user_id -> Integer,
|
user_id -> BigInt,
|
||||||
description -> Nullable<Text>,
|
description -> Nullable<Text>,
|
||||||
start -> Nullable<Date>,
|
start -> Nullable<Date>,
|
||||||
end -> Nullable<Date>,
|
end -> Nullable<Date>,
|
||||||
@ -54,33 +54,33 @@ table! {
|
|||||||
|
|
||||||
table! {
|
table! {
|
||||||
user_languages (id) {
|
user_languages (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
user_id -> Integer,
|
user_id -> BigInt,
|
||||||
language_id -> Integer,
|
language_id -> BigInt,
|
||||||
level -> Nullable<Integer>,
|
level -> Nullable<Integer>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
user_search_topics (id) {
|
user_search_topics (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
user_id -> Integer,
|
user_id -> BigInt,
|
||||||
topic_id -> Integer,
|
topic_id -> BigInt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
user_skills (id) {
|
user_skills (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
user_id -> Integer,
|
user_id -> BigInt,
|
||||||
skill_id -> Nullable<Integer>,
|
skill_id -> Nullable<BigInt>,
|
||||||
level -> Nullable<Integer>,
|
level -> Nullable<Integer>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
users (id) {
|
users (id) {
|
||||||
id -> Nullable<Integer>,
|
id -> Nullable<BigInt>,
|
||||||
nickname -> Nullable<Text>,
|
nickname -> Nullable<Text>,
|
||||||
pronouns -> Nullable<Text>,
|
pronouns -> Nullable<Text>,
|
||||||
address_1_name -> Nullable<Text>,
|
address_1_name -> Nullable<Text>,
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
|
extern crate chrono;
|
||||||
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
extern crate serde;
|
||||||
|
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::db::models::User;
|
||||||
|
use crate::db::schema::users::dsl::*;
|
||||||
|
|
||||||
|
use diesel::prelude::*;
|
||||||
use diesel::Connection;
|
use diesel::Connection;
|
||||||
use diesel::SqliteConnection;
|
use diesel::SqliteConnection;
|
||||||
|
|
||||||
@ -13,17 +20,16 @@ mod tests {
|
|||||||
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
assert_eq!(2 + 2, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_users() {
|
fn list_users() {
|
||||||
use schema::dsl::*;
|
|
||||||
let connection = establish_connection();
|
let connection = establish_connection();
|
||||||
// db::schema::
|
let all_users = users
|
||||||
|
.load::<User>(&connection)
|
||||||
|
.expect("Error loading users");
|
||||||
|
|
||||||
// users.loa
|
println!("Displaying {} users", all_users.len());
|
||||||
|
for user in all_users {
|
||||||
|
println!("{:?}", user.nickname.unwrap());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user