fix: resolve ownership and borrowing errors and add serde traits
Co-authored-by: aider (openai/andrew/openrouter/google/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -29,6 +29,9 @@ pub enum CoreError {
|
||||
|
||||
impl From<rusqlite_migration::Error> for CoreError {
|
||||
fn from(err: rusqlite_migration::Error) -> Self {
|
||||
CoreError::Database(rusqlite::Error::from(err))
|
||||
match err {
|
||||
rusqlite_migration::Error::Rusqlite(e) => CoreError::Database(e),
|
||||
e => CoreError::Other(e.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ use crate::db::{self, Meta};
|
||||
use crate::compression_engine::{get_compression_engine, CompressionType};
|
||||
use crate::modes::common::settings_compression_type;
|
||||
use clap::Command;
|
||||
use log::debug;
|
||||
use rusqlite::Connection;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use anyhow::{Context, Error, Result};
|
||||
use chrono::prelude::*;
|
||||
use lazy_static::lazy_static;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use log::*;
|
||||
use rusqlite::{Connection, OpenFlags, params};
|
||||
use rusqlite_migration::{M, Migrations};
|
||||
@@ -37,7 +38,7 @@ lazy_static! {
|
||||
]);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Item {
|
||||
pub id: Option<i64>,
|
||||
pub ts: DateTime<Utc>,
|
||||
@@ -45,13 +46,13 @@ pub struct Item {
|
||||
pub compression: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Tag {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Meta {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
|
||||
@@ -74,7 +74,7 @@ fn show_item(
|
||||
|
||||
let item = item_with_meta.item;
|
||||
let item_id = item.id.unwrap();
|
||||
let item_tags: Vec<String> = item_with_meta.tags.into_iter().map(|t| t.name).collect();
|
||||
let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
|
||||
|
||||
let mut table = Table::new();
|
||||
if std::io::stdout().is_terminal() {
|
||||
@@ -156,7 +156,7 @@ fn show_item_structured(
|
||||
) -> Result<()> {
|
||||
let item = item_with_meta.item;
|
||||
let item_id = item.id.unwrap();
|
||||
let item_tags: Vec<String> = item_with_meta.tags.into_iter().map(|t| t.name).collect();
|
||||
let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
|
||||
|
||||
let mut item_path_buf = data_path.clone();
|
||||
item_path_buf.push(item_id.to_string());
|
||||
|
||||
@@ -71,7 +71,7 @@ pub fn mode_list(
|
||||
|
||||
for item_with_meta in items_with_meta {
|
||||
let item = item_with_meta.item;
|
||||
let tags: Vec<String> = item_with_meta.tags.into_iter().map(|t| t.name).collect();
|
||||
let tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
|
||||
let meta = item_with_meta.meta_as_map();
|
||||
|
||||
let mut item_path = data_path.clone();
|
||||
@@ -297,7 +297,7 @@ fn show_list_structured(
|
||||
for item_with_meta in items_with_meta {
|
||||
let item = item_with_meta.item;
|
||||
let item_id = item.id.unwrap();
|
||||
let tags = item_with_meta.tags.into_iter().map(|t| t.name).collect();
|
||||
let tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
|
||||
let meta = item_with_meta.meta_as_map();
|
||||
|
||||
let mut item_path = data_path.clone();
|
||||
|
||||
@@ -57,7 +57,7 @@ pub async fn handle_list_items(
|
||||
// Apply ordering (default is newest first)
|
||||
match params.order.as_deref().unwrap_or("newest") {
|
||||
"newest" => items_with_meta.sort_by(|a, b| b.item.ts.cmp(&a.item.ts)),
|
||||
"oldest" => items_with_meta.sort_by(|a, b| a.item.ts.cmp(&a.item.ts)),
|
||||
"oldest" => items_with_meta.sort_by(|a, b| a.item.ts.cmp(&b.item.ts)),
|
||||
_ => items_with_meta.sort_by(|a, b| b.item.ts.cmp(&a.item.ts)), // default to newest
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ pub async fn handle_list_items(
|
||||
.into_iter()
|
||||
.map(|item_with_meta| {
|
||||
let item_id = item_with_meta.item.id.unwrap_or(0);
|
||||
let item_tags = item_with_meta.tags.into_iter().map(|t| t.name).collect();
|
||||
let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
|
||||
let item_meta = item_with_meta.meta_as_map();
|
||||
|
||||
ItemInfo {
|
||||
|
||||
@@ -100,7 +100,7 @@ impl KeepTools {
|
||||
|
||||
let item = item_with_content.item_with_meta.item;
|
||||
let content = String::from_utf8_lossy(&item_with_content.content).to_string();
|
||||
let tags: Vec<String> = item_with_content.item_with_meta.tags.into_iter().map(|t| t.name).collect();
|
||||
let tags: Vec<String> = item_with_content.item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
|
||||
let metadata = item_with_content.item_with_meta.meta_as_map();
|
||||
|
||||
let response = serde_json::json!({
|
||||
@@ -118,6 +118,7 @@ impl KeepTools {
|
||||
|
||||
pub async fn get_latest_item(&self, args: Option<Value>) -> Result<String, ToolError> {
|
||||
let tags: Vec<String> = args
|
||||
.as_ref()
|
||||
.and_then(|v| v.get("tags"))
|
||||
.and_then(|v| v.as_array())
|
||||
.map(|arr| arr.iter().filter_map(|v| v.as_str().map(|s| s.to_string())).collect())
|
||||
@@ -136,7 +137,7 @@ impl KeepTools {
|
||||
|
||||
let item = item_with_content.item_with_meta.item;
|
||||
let content = String::from_utf8_lossy(&item_with_content.content).to_string();
|
||||
let tags: Vec<String> = item_with_content.item_with_meta.tags.into_iter().map(|t| t.name).collect();
|
||||
let tags: Vec<String> = item_with_content.item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
|
||||
let metadata = item_with_content.item_with_meta.meta_as_map();
|
||||
|
||||
let response = serde_json::json!({
|
||||
@@ -182,7 +183,7 @@ impl KeepTools {
|
||||
.map(|item_with_meta| {
|
||||
let item = item_with_meta.item;
|
||||
let item_id = item.id.unwrap_or(0);
|
||||
let item_tags: Vec<String> = item_with_meta.tags.into_iter().map(|t| t.name).collect();
|
||||
let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
|
||||
let item_meta = item_with_meta.meta_as_map();
|
||||
|
||||
serde_json::json!({
|
||||
@@ -234,7 +235,7 @@ impl KeepTools {
|
||||
.map(|item_with_meta| {
|
||||
let item = item_with_meta.item;
|
||||
let item_id = item.id.unwrap_or(0);
|
||||
let item_tags: Vec<String> = item_with_meta.tags.into_iter().map(|t| t.name).collect();
|
||||
let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
|
||||
let item_meta = item_with_meta.meta_as_map();
|
||||
|
||||
serde_json::json!({
|
||||
|
||||
Reference in New Issue
Block a user