summaryrefslogtreecommitdiff
path: root/src/data.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/data.rs')
-rw-r--r--src/data.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/data.rs b/src/data.rs
index 8178bb9..c9e5b92 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -69,6 +69,8 @@ pub fn init(c: &Connection) -> Result<()> {
quote_date DATE CHECK (DATE(quote_date, '+0 days') IS quote_date),
author TEXT NOT NULL,
content TEXT NOT NULL,
+ ip TEXT NOT NULL,
+ timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT unique_content UNIQUE (quote_date, content)
);
@@ -77,6 +79,8 @@ pub fn init(c: &Connection) -> Result<()> {
user_id INTEGER NOT NULL,
quote_id INTEGER NOT NULL,
score INTEGER NOT NULL,
+ ip TEXT NOT NULL,
+ timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(quote_id) REFERENCES quotes(id)
CONSTRAINT unique_vote UNIQUE (user_id, quote_id)
);
@@ -135,25 +139,25 @@ pub fn get_key(c: &Connection, id: &str) -> Result<Vec<u8>> {
Ok(key)
}
-pub fn new_quote(c: &Connection, date: &str, author: &str, content: &str) -> Result<()> {
+pub fn new_quote(c: &Connection, date: &str, author: &str, content: &str, ip: &str) -> Result<()> {
c.execute(
r#"
- INSERT INTO quotes (quote_date, author, content) VALUES
- (?1, ?2, ?3);
+ INSERT INTO quotes (quote_date, author, content, ip) VALUES
+ (?1, ?2, ?3, ?4);
"#,
- &[&date, &author, &content],
+ &[&date, &author, &content, &ip],
)?;
info!("New quote added by {}", author);
Ok(())
}
-pub fn new_vote(c: &Connection, user_id: i64, quote_id: i64, score: i32) -> Result<()> {
+pub fn new_vote(c: &Connection, user_id: i64, quote_id: i64, score: i32, ip: &str) -> Result<()> {
c.execute(
r#"
- INSERT OR REPLACE INTO votes (quote_id, user_id, score) VALUES
- (?1, ?2, ?3)
+ INSERT OR REPLACE INTO votes (quote_id, user_id, score, ip) VALUES
+ (?1, ?2, ?3, ?4)
"#,
- &[&quote_id, &user_id, &score],
+ &[&quote_id, &user_id, &score, &ip],
)?;
info!("New vote: quote_id({}) score({})", quote_id, score);
Ok(())