WIP: Some bugs switching to database provided IDs, terminal titles don't reload when restored from serialized, workspace tests are no longer passing but should be easy to fix when it isn't 11:44

This commit is contained in:
Mikayla Maki 2022-11-20 23:44:30 -08:00
parent a47f2ca445
commit e1eff3f4cd
9 changed files with 37 additions and 80 deletions

View file

@ -22,7 +22,6 @@ lazy_static = "1.4.0"
log = { version = "0.4.16", features = ["kv_unstable_serde"] }
parking_lot = "0.11.1"
serde = { version = "1.0", features = ["derive"] }
uuid = { version = "1.2.2", features = ["v4", "fast-rng"] }
[dev-dependencies]
gpui = { path = "../gpui", features = ["test-support"] }

View file

@ -5,7 +5,6 @@ pub use anyhow;
pub use indoc::indoc;
pub use lazy_static;
pub use sqlez;
use sqlez::bindable::{Bind, Column};
#[cfg(any(test, feature = "test-support"))]
use anyhow::Result;
@ -20,7 +19,6 @@ use std::fs::{create_dir_all, remove_dir_all};
use std::path::Path;
use util::channel::{ReleaseChannel, RELEASE_CHANNEL, RELEASE_CHANNEL_NAME};
use util::paths::DB_DIR;
use uuid::Uuid as RealUuid;
const INITIALIZE_QUERY: &'static str = indoc! {"
PRAGMA journal_mode=WAL;
@ -30,47 +28,6 @@ const INITIALIZE_QUERY: &'static str = indoc! {"
PRAGMA case_sensitive_like=TRUE;
"};
#[derive(Debug, Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Uuid(RealUuid);
impl std::ops::Deref for Uuid {
type Target = RealUuid;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Bind for Uuid {
fn bind(
&self,
statement: &sqlez::statement::Statement,
start_index: i32,
) -> anyhow::Result<i32> {
statement.bind(self.as_bytes(), start_index)
}
}
impl Column for Uuid {
fn column(
statement: &mut sqlez::statement::Statement,
start_index: i32,
) -> anyhow::Result<(Self, i32)> {
let blob = statement.column_blob(start_index)?;
Ok((Uuid::from_bytes(blob)?, start_index + 1))
}
}
impl Uuid {
pub fn new() -> Self {
Uuid(RealUuid::new_v4())
}
fn from_bytes(bytes: &[u8]) -> anyhow::Result<Self> {
Ok(Uuid(RealUuid::from_bytes(bytes.try_into()?)))
}
}
/// Open or create a database at the given directory path.
pub fn open_file_db<M: Migrator>() -> ThreadSafeConnection<M> {
// Use 0 for now. Will implement incrementing and clearing of old db files soon TM
@ -186,7 +143,7 @@ macro_rules! select_row_method {
pub fn $id(&self) -> $crate::sqlez::anyhow::Result<Option<$return_type>> {
use $crate::anyhow::Context;
self.select_row::<$return_type>($sql)?(())
self.select_row::<$return_type>($sql)?()
.context(::std::format!(
"Error in {}, select_row failed to execute or parse for: {}",
::std::stringify!($id),