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:
gulliver 2021-06-01 08:49:32 +02:00
parent 58f6b349df
commit 91deda2614
4 changed files with 57 additions and 47 deletions

View File

@ -7,4 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chrono = { features = ["serde"] }
diesel = { version = "*", features = ["sqlite"] }
serde = { version = "1.0" , features = ["derive"]}
# serde_json = "1.0"

View File

@ -1,19 +1,20 @@
use super::schema::*;
use chrono::{DateTime, Utc};
use serde::Serialize;
#[derive(Serialize, Queryable)]
pub struct User {
id: i64,
nickname: String,
pronouns: String,
address_1_name: String,
address_2_additional: String,
address_4_street: String,
adress_house_number: String,
adress_city_code: String,
adress_country: String,
Ehrenaemter: String,
gravatar_email: String,
Freitext: String,
pub id: Option<i64>,
pub nickname: Option<String>,
pub pronouns: Option<String>,
pub address_1_name: Option<String>,
pub address_2_additional: Option<String>,
pub address_4_street: Option<String>,
pub adress_house_number: Option<String>,
pub adress_city_code: Option<String>,
pub adress_country: Option<String>,
pub ehrenaemter: Option<String>,
pub gravatar_email: Option<String>,
pub freitext: Option<String>,
}
#[derive(Serialize, Queryable)]
@ -30,11 +31,11 @@ pub struct UserLanguage {
user_id: i64,
language_id: i64,
level: i64,
level: i32,
}
#[derive(Serialize, Queryable)]
pub struct skill {
pub struct Skill {
id: i64,
name: String,
}
@ -44,8 +45,8 @@ pub struct UserExperience {
id: i64,
user_id: i64,
description: String,
start: Date,
end: Date,
start: DateTime<Utc>,
end: DateTime<Utc>,
}
#[derive(Serialize, Queryable)]
@ -70,13 +71,13 @@ pub struct Topic {
}
#[derive(Serialize, Queryable)]
pub struct language {
pub struct Language {
id: i64,
name: String,
}
#[derive(Serialize, Queryable)]
pub struct experience {
pub struct Experience {
id: i64,
name: String,
}

View File

@ -1,51 +1,51 @@
table! {
contact_types (id) {
id -> Nullable<Integer>,
id -> Nullable<BigInt>,
name -> Nullable<Text>,
}
}
table! {
experiences (id) {
id -> Nullable<Integer>,
id -> Nullable<BigInt>,
name -> Nullable<Text>,
}
}
table! {
languages (id) {
id -> Nullable<Integer>,
id -> Nullable<BigInt>,
name -> Nullable<Text>,
}
}
table! {
skills (id) {
id -> Nullable<Integer>,
id -> Nullable<BigInt>,
name -> Nullable<Text>,
}
}
table! {
topics (id) {
id -> Nullable<Integer>,
id -> Nullable<BigInt>,
name -> Nullable<Text>,
}
}
table! {
user_contacts (id) {
id -> Nullable<Integer>,
user_id -> Integer,
contact_type_id -> Integer,
id -> Nullable<BigInt>,
user_id -> BigInt,
contact_type_id -> BigInt,
content_ -> Nullable<Text>,
}
}
table! {
user_experiences (id) {
id -> Nullable<Integer>,
user_id -> Integer,
id -> Nullable<BigInt>,
user_id -> BigInt,
description -> Nullable<Text>,
start -> Nullable<Date>,
end -> Nullable<Date>,
@ -54,33 +54,33 @@ table! {
table! {
user_languages (id) {
id -> Nullable<Integer>,
user_id -> Integer,
language_id -> Integer,
id -> Nullable<BigInt>,
user_id -> BigInt,
language_id -> BigInt,
level -> Nullable<Integer>,
}
}
table! {
user_search_topics (id) {
id -> Nullable<Integer>,
user_id -> Integer,
topic_id -> Integer,
id -> Nullable<BigInt>,
user_id -> BigInt,
topic_id -> BigInt,
}
}
table! {
user_skills (id) {
id -> Nullable<Integer>,
user_id -> Integer,
skill_id -> Nullable<Integer>,
id -> Nullable<BigInt>,
user_id -> BigInt,
skill_id -> Nullable<BigInt>,
level -> Nullable<Integer>,
}
}
table! {
users (id) {
id -> Nullable<Integer>,
id -> Nullable<BigInt>,
nickname -> Nullable<Text>,
pronouns -> Nullable<Text>,
address_1_name -> Nullable<Text>,

View File

@ -1,9 +1,16 @@
extern crate chrono;
#[macro_use]
extern crate diesel;
extern crate serde;
pub mod db;
#[cfg(test)]
mod tests {
use crate::db::models::User;
use crate::db::schema::users::dsl::*;
use diesel::prelude::*;
use diesel::Connection;
use diesel::SqliteConnection;
@ -13,17 +20,16 @@ mod tests {
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
}
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
#[test]
fn list_users() {
use schema::dsl::*;
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());
}
}
}