Merge pull request #226 from igalic/feat/sqlite
Add SQLite as supported database
This commit is contained in:
+7
-5
@@ -1,23 +1,25 @@
|
||||
use canapi::Provider;
|
||||
use diesel::PgConnection;
|
||||
use rocket::http::uri::Origin;
|
||||
use rocket_contrib::Json;
|
||||
use serde_json;
|
||||
use serde_qs;
|
||||
|
||||
use plume_api::posts::PostEndpoint;
|
||||
use plume_models::db_conn::DbConn;
|
||||
use plume_models::posts::Post;
|
||||
use plume_models::{
|
||||
Connection,
|
||||
db_conn::DbConn,
|
||||
posts::Post,
|
||||
};
|
||||
|
||||
#[get("/posts/<id>")]
|
||||
fn get(id: i32, conn: DbConn) -> Json<serde_json::Value> {
|
||||
let post = <Post as Provider<PgConnection>>::get(&*conn, id).ok();
|
||||
let post = <Post as Provider<Connection>>::get(&*conn, id).ok();
|
||||
Json(json!(post))
|
||||
}
|
||||
|
||||
#[get("/posts")]
|
||||
fn list(conn: DbConn, uri: &Origin) -> Json<serde_json::Value> {
|
||||
let query: PostEndpoint = serde_qs::from_str(uri.query().unwrap_or("")).expect("Invalid query string");
|
||||
let post = <Post as Provider<PgConnection>>::list(&*conn, query);
|
||||
let post = <Post as Provider<Connection>>::list(&*conn, query);
|
||||
Json(json!(post))
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
use activitypub::{activity::{Announce, Create, Delete, Like, Undo, Update}, object::Tombstone};
|
||||
use diesel::PgConnection;
|
||||
use failure::Error;
|
||||
use serde_json;
|
||||
|
||||
use plume_common::activity_pub::{Id, inbox::{Deletable, FromActivity, InboxError}};
|
||||
use plume_models::{
|
||||
Connection,
|
||||
comments::Comment,
|
||||
follows::Follow,
|
||||
instance::Instance,
|
||||
@@ -15,7 +15,7 @@ use plume_models::{
|
||||
};
|
||||
|
||||
pub trait Inbox {
|
||||
fn received(&self, conn: &PgConnection, act: serde_json::Value) -> Result<(), Error> {
|
||||
fn received(&self, conn: &Connection, act: serde_json::Value) -> Result<(), Error> {
|
||||
let actor_id = Id::new(act["actor"].as_str().unwrap_or_else(|| act["actor"]["id"].as_str().expect("No actor ID for incoming activity")));
|
||||
match act["type"].as_str() {
|
||||
Some(t) => {
|
||||
|
||||
+2
-3
@@ -1,5 +1,4 @@
|
||||
use atom_syndication::{ContentBuilder, Entry, EntryBuilder, LinkBuilder, Person, PersonBuilder};
|
||||
use diesel::PgConnection;
|
||||
use rocket::{
|
||||
http::uri::{FromUriParam, UriDisplay},
|
||||
response::NamedFile
|
||||
@@ -9,7 +8,7 @@ use std::{
|
||||
path::{Path, PathBuf}
|
||||
};
|
||||
|
||||
use plume_models::posts::Post;
|
||||
use plume_models::{Connection, posts::Post};
|
||||
|
||||
macro_rules! may_fail {
|
||||
($account:expr, $expr:expr, $template:expr, $msg:expr, | $res:ident | $block:block) => {
|
||||
@@ -79,7 +78,7 @@ impl Page {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn post_to_atom(post: Post, conn: &PgConnection) -> Entry {
|
||||
pub fn post_to_atom(post: Post, conn: &Connection) -> Entry {
|
||||
EntryBuilder::default()
|
||||
.title(post.title.clone())
|
||||
.content(ContentBuilder::default()
|
||||
|
||||
+6
-5
@@ -1,5 +1,5 @@
|
||||
use colored::Colorize;
|
||||
use diesel::{pg::PgConnection, r2d2::{ConnectionManager, Pool}};
|
||||
use diesel::r2d2::{ConnectionManager, Pool};
|
||||
use dotenv::dotenv;
|
||||
use std::fs::{self, File};
|
||||
use std::io;
|
||||
@@ -9,21 +9,22 @@ use rpassword;
|
||||
use plume_models::safe_string::SafeString;
|
||||
|
||||
use plume_models::{
|
||||
Connection,
|
||||
DB_URL,
|
||||
db_conn::{DbConn, PgPool},
|
||||
db_conn::{DbConn, DbPool},
|
||||
instance::*,
|
||||
users::*
|
||||
};
|
||||
|
||||
/// Initializes a database pool.
|
||||
fn init_pool() -> Option<PgPool> {
|
||||
fn init_pool() -> Option<DbPool> {
|
||||
dotenv().ok();
|
||||
|
||||
let manager = ConnectionManager::<PgConnection>::new(DB_URL.as_str());
|
||||
let manager = ConnectionManager::<Connection>::new(DB_URL.as_str());
|
||||
Pool::new(manager).ok()
|
||||
}
|
||||
|
||||
pub fn check() -> PgPool {
|
||||
pub fn check() -> DbPool {
|
||||
if let Some(pool) = init_pool() {
|
||||
match pool.get() {
|
||||
Ok(conn) => {
|
||||
|
||||
Reference in New Issue
Block a user