Преглед на файлове

Add timestamp to gists

master
Dylan Baker преди 5 години
родител
ревизия
c4171ae006
променени са 7 файла, в които са добавени 13 реда и са изтрити 3 реда
  1. 3
    0
      Cargo.lock
  2. 2
    1
      Cargo.toml
  3. 1
    0
      migrations/2019-05-01-183414_add_timestamp_to_gists/down.sql
  4. 1
    0
      migrations/2019-05-01-183414_add_timestamp_to_gists/up.sql
  5. 4
    2
      src/gists/mod.rs
  6. 1
    0
      src/main.rs
  7. 1
    0
      src/schema.rs

+ 3
- 0
Cargo.lock Целия файл

121
 dependencies = [
121
 dependencies = [
122
  "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
122
  "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
123
  "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
123
  "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
124
+ "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
124
  "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
125
  "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
125
 ]
126
 ]
126
 
127
 
184
 dependencies = [
185
 dependencies = [
185
  "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
186
  "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
186
  "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
187
  "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
188
+ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
187
  "diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
189
  "diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
188
  "pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
190
  "pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
189
 ]
191
 ]
286
 name = "gist-server"
288
 name = "gist-server"
287
 version = "0.1.0"
289
 version = "0.1.0"
288
 dependencies = [
290
 dependencies = [
291
+ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
289
  "diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
292
  "diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
290
  "dotenv 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
293
  "dotenv 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
291
  "r2d2 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)",
294
  "r2d2 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)",

+ 2
- 1
Cargo.toml Целия файл

5
 edition = "2018"
5
 edition = "2018"
6
 
6
 
7
 [dependencies]
7
 [dependencies]
8
-diesel = { version = "1.0.0", features = ["postgres"] }
8
+chrono = { version = "0.4.6", features = ["serde"] }
9
+diesel = { version = "1.0.0", features = ["postgres", "chrono"] }
9
 dotenv = "0.9.0"
10
 dotenv = "0.9.0"
10
 r2d2 = "0.8.3"
11
 r2d2 = "0.8.3"
11
 r2d2-diesel = "1.0.0"
12
 r2d2-diesel = "1.0.0"

+ 1
- 0
migrations/2019-05-01-183414_add_timestamp_to_gists/down.sql Целия файл

1
+ALTER TABLE gists DROP COLUMN created_at;

+ 1
- 0
migrations/2019-05-01-183414_add_timestamp_to_gists/up.sql Целия файл

1
+ALTER TABLE gists ADD COLUMN created_at TIMESTAMP DEFAULT NOW();

+ 4
- 2
src/gists/mod.rs Целия файл

1
+use chrono::NaiveDateTime;
1
 use diesel::pg::PgConnection as PGC;
2
 use diesel::pg::PgConnection as PGC;
2
 use diesel::prelude::*;
3
 use diesel::prelude::*;
3
 
4
 
4
 use crate::schema::gists;
5
 use crate::schema::gists;
5
 
6
 
6
-#[derive(Queryable, AsChangeset, Serialize, Deserialize)]
7
+#[derive(Queryable, Serialize, Deserialize)]
7
 pub struct Gist {
8
 pub struct Gist {
8
     pub id: i32,
9
     pub id: i32,
9
     pub title: String,
10
     pub title: String,
10
     pub body: String,
11
     pub body: String,
12
+    pub created_at: Option<NaiveDateTime>,
11
 }
13
 }
12
 
14
 
13
-#[derive(Insertable, Serialize, Deserialize)]
15
+#[derive(Insertable, AsChangeset, Serialize, Deserialize)]
14
 #[table_name = "gists"]
16
 #[table_name = "gists"]
15
 pub struct InsertableGist {
17
 pub struct InsertableGist {
16
     pub title: String,
18
     pub title: String,

+ 1
- 0
src/main.rs Целия файл

1
 #![feature(proc_macro_hygiene, decl_macro)]
1
 #![feature(proc_macro_hygiene, decl_macro)]
2
 
2
 
3
+extern crate chrono;
3
 #[macro_use]
4
 #[macro_use]
4
 extern crate diesel;
5
 extern crate diesel;
5
 extern crate dotenv;
6
 extern crate dotenv;

+ 1
- 0
src/schema.rs Целия файл

3
         id -> Int4,
3
         id -> Int4,
4
         title -> Varchar,
4
         title -> Varchar,
5
         body -> Text,
5
         body -> Text,
6
+        created_at -> Nullable<Timestamp>,
6
     }
7
     }
7
 }
8
 }

Loading…
Отказ
Запис