Add non-blob columns to SQLite (#27236)

This commit is contained in:
Kirill Bulatov 2025-03-21 12:04:59 +02:00 committed by GitHub
parent 33fc1f4af2
commit 2ffce4f516
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 66 additions and 22 deletions

View file

@ -20,13 +20,20 @@ pub(crate) struct SerializedEditor {
impl StaticColumnCount for SerializedEditor {
fn column_count() -> usize {
5
6
}
}
impl Bind for SerializedEditor {
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
let start_index = statement.bind(&self.abs_path, start_index)?;
let start_index = statement.bind(
&self
.abs_path
.as_ref()
.map(|p| p.to_string_lossy().to_string()),
start_index,
)?;
let start_index = statement.bind(&self.contents, start_index)?;
let start_index = statement.bind(&self.language, start_index)?;
@ -51,6 +58,8 @@ impl Column for SerializedEditor {
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
let (abs_path, start_index): (Option<PathBuf>, i32) =
Column::column(statement, start_index)?;
let (_abs_path, start_index): (Option<PathBuf>, i32) =
Column::column(statement, start_index)?;
let (contents, start_index): (Option<String>, i32) =
Column::column(statement, start_index)?;
let (language, start_index): (Option<String>, i32) =
@ -147,6 +156,10 @@ define_connection!(
ON DELETE CASCADE
) STRICT;
),
sql! (
ALTER TABLE editors ADD COLUMN buffer_path TEXT;
UPDATE editors SET buffer_path = CAST(path AS TEXT);
),
];
);
@ -158,7 +171,7 @@ const MAX_QUERY_PLACEHOLDERS: usize = 32000;
impl EditorDb {
query! {
pub fn get_serialized_editor(item_id: ItemId, workspace_id: WorkspaceId) -> Result<Option<SerializedEditor>> {
SELECT path, contents, language, mtime_seconds, mtime_nanos FROM editors
SELECT path, buffer_path, contents, language, mtime_seconds, mtime_nanos FROM editors
WHERE item_id = ? AND workspace_id = ?
}
}
@ -166,17 +179,18 @@ impl EditorDb {
query! {
pub async fn save_serialized_editor(item_id: ItemId, workspace_id: WorkspaceId, serialized_editor: SerializedEditor) -> Result<()> {
INSERT INTO editors
(item_id, workspace_id, path, contents, language, mtime_seconds, mtime_nanos)
(item_id, workspace_id, path, buffer_path, contents, language, mtime_seconds, mtime_nanos)
VALUES
(?1, ?2, ?3, ?4, ?5, ?6, ?7)
(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)
ON CONFLICT DO UPDATE SET
item_id = ?1,
workspace_id = ?2,
path = ?3,
contents = ?4,
language = ?5,
mtime_seconds = ?6,
mtime_nanos = ?7
buffer_path = ?4,
contents = ?5,
language = ?6,
mtime_seconds = ?7,
mtime_nanos = ?8
}
}