Nathan.fooo f9e7b5ffa4
feat: reload UI (#2999)
* chore: reload folder

* chore: reload folder

* chore: init sync

* chore: update tables

* chore: update database

* chore: load row

* chore: update

* chore: reload row

* test: fit test

* chore: retry

* chore: support batch fetch

* chore: enable sync

* chore: sync switch

* chore: sync switch

* chore: migration user data

* chore: migrate data

* chore: migrate folder

* chore: save user email

* chore: refresh user profile

* chore: fix test

* chore: delete translation files

* test: clippy format
2023-07-14 13:37:13 +08:00

54 lines
1.3 KiB
Rust

#[macro_use]
pub extern crate diesel;
#[macro_use]
pub extern crate diesel_derives;
#[macro_use]
extern crate diesel_migrations;
use std::{fmt::Debug, io, path::Path};
pub use diesel::*;
pub use diesel_derives::*;
use crate::sqlite::PoolConfig;
pub use crate::sqlite::{ConnectionPool, DBConnection, Database};
pub mod kv;
mod sqlite;
pub mod schema;
#[macro_use]
pub mod macros;
pub type Error = diesel::result::Error;
pub mod prelude {
pub use diesel::SqliteConnection;
pub use diesel::{query_dsl::*, BelongingToDsl, ExpressionMethods, RunQueryDsl};
pub use crate::*;
}
embed_migrations!("../flowy-sqlite/migrations/");
pub const DB_NAME: &str = "flowy-database.db";
pub fn init<P: AsRef<Path>>(storage_path: P) -> Result<Database, io::Error> {
let storage_path = storage_path.as_ref().to_str().unwrap();
if !Path::new(storage_path).exists() {
std::fs::create_dir_all(storage_path)?;
}
let pool_config = PoolConfig::default();
let database = Database::new(storage_path, DB_NAME, pool_config).map_err(as_io_error)?;
let conn = database.get_connection().map_err(as_io_error)?;
embedded_migrations::run(&*conn).map_err(as_io_error)?;
Ok(database)
}
fn as_io_error<E>(e: E) -> io::Error
where
E: Into<crate::sqlite::Error> + Debug,
{
let msg = format!("{:?}", e);
io::Error::new(io::ErrorKind::NotConnected, msg)
}