Added sql! proc macro which checks syntax errors on sql code and displays them with reasonable underline locations

Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Kay Simmons 2022-11-28 17:42:18 -08:00 committed by Mikayla Maki
parent 260164a711
commit dd9d20be25
15 changed files with 342 additions and 211 deletions

View file

@ -1,12 +1,11 @@
use std::path::PathBuf;
use crate::Editor;
use db::sqlez_macros::sql;
use db::{connection, query};
use indoc::indoc;
use sqlez::domain::Domain;
use workspace::{ItemId, Workspace, WorkspaceId};
use crate::Editor;
connection!(DB: EditorDb<(Workspace, Editor)>);
impl Domain for Editor {
@ -15,7 +14,7 @@ impl Domain for Editor {
}
fn migrations() -> &'static [&'static str] {
&[indoc! {"
&[sql! (
CREATE TABLE editors(
item_id INTEGER NOT NULL,
workspace_id INTEGER NOT NULL,
@ -26,26 +25,22 @@ impl Domain for Editor {
ON UPDATE CASCADE
) STRICT;
"}]
)]
}
}
impl EditorDb {
query! {
pub fn get_path(item_id: ItemId, workspace_id: WorkspaceId) -> Result<PathBuf> {
indoc!{"
SELECT path FROM editors
WHERE item_id = ? AND workspace_id = ?
"}
SELECT path FROM editors
WHERE item_id = ? AND workspace_id = ?
}
}
query! {
pub async fn save_path(item_id: ItemId, workspace_id: WorkspaceId, path: PathBuf) -> Result<()> {
indoc!{"
INSERT OR REPLACE INTO editors(item_id, workspace_id, path)
VALUES (?, ?, ?)
"}
INSERT OR REPLACE INTO editors(item_id, workspace_id, path)
VALUES (?, ?, ?)
}
}
}