-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
30 changed files
with
13,336 additions
and
752 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CREATE TABLE after_streams2 ( | ||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
channel VARCHAR, | ||
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
user TEXT NOT NULL, | ||
text TEXT NOT NULL | ||
); | ||
|
||
INSERT INTO after_streams2 (channel, added_at, user, text) SELECT channel, added_at, user, text FROM after_streams; | ||
DROP TABLE after_streams; | ||
ALTER TABLE after_streams2 RENAME TO after_streams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::db::{self, models, schema}; | ||
use diesel::prelude::*; | ||
|
||
pub use self::models::AfterStream; | ||
|
||
#[derive(Clone)] | ||
pub struct AfterStreams { | ||
db: db::Database, | ||
} | ||
|
||
impl AfterStreams { | ||
/// Open the after streams database. | ||
pub fn load(db: db::Database) -> Result<Self, failure::Error> { | ||
Ok(AfterStreams { db }) | ||
} | ||
|
||
/// Push the given afterstream message. | ||
pub fn push(&self, channel: &str, user: &str, text: &str) -> Result<(), failure::Error> { | ||
use self::schema::after_streams::dsl; | ||
let c = self.db.pool.get()?; | ||
|
||
let after_stream = models::InsertAfterStream { | ||
channel: Some(String::from(channel)), | ||
user: String::from(user), | ||
text: String::from(text), | ||
}; | ||
|
||
diesel::insert_into(dsl::after_streams) | ||
.values(&after_stream) | ||
.execute(&c)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Delete the after stream with the given id. | ||
pub fn delete(&self, id: i32) -> Result<bool, failure::Error> { | ||
use self::schema::after_streams::dsl; | ||
let c = self.db.pool.get()?; | ||
let count = diesel::delete(dsl::after_streams.filter(dsl::id.eq(id))).execute(&c)?; | ||
Ok(count == 1) | ||
} | ||
|
||
/// List all available after streams. | ||
pub fn list(&self) -> Result<Vec<AfterStream>, failure::Error> { | ||
use self::schema::after_streams::dsl; | ||
let c = self.db.pool.get()?; | ||
Ok(dsl::after_streams | ||
.order(dsl::added_at.asc()) | ||
.load::<models::AfterStream>(&c)?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![recursion_limit = "128"] | ||
|
||
#[macro_use] | ||
extern crate diesel; | ||
#[macro_use] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.