pinakes-core: add markdown link storage methods
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I5fa9fd045711664e5dcc7f1c12b6ca896a6a6964
This commit is contained in:
parent
7c4692a4d1
commit
27be136e01
3 changed files with 27 additions and 16 deletions
|
|
@ -801,7 +801,10 @@ pub trait StorageBackend: Send + Sync + 'static {
|
|||
) -> Result<()>;
|
||||
|
||||
/// Get outgoing links from a media item.
|
||||
async fn get_outgoing_links(&self, media_id: MediaId) -> Result<Vec<crate::model::MarkdownLink>>;
|
||||
async fn get_outgoing_links(
|
||||
&self,
|
||||
media_id: MediaId,
|
||||
) -> Result<Vec<crate::model::MarkdownLink>>;
|
||||
|
||||
/// Get backlinks (incoming links) to a media item.
|
||||
async fn get_backlinks(&self, media_id: MediaId) -> Result<Vec<crate::model::BacklinkInfo>>;
|
||||
|
|
|
|||
|
|
@ -6092,7 +6092,10 @@ impl StorageBackend for PostgresBackend {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_outgoing_links(&self, media_id: MediaId) -> Result<Vec<crate::model::MarkdownLink>> {
|
||||
async fn get_outgoing_links(
|
||||
&self,
|
||||
media_id: MediaId,
|
||||
) -> Result<Vec<crate::model::MarkdownLink>> {
|
||||
let client = self
|
||||
.pool
|
||||
.get()
|
||||
|
|
|
|||
|
|
@ -6413,7 +6413,7 @@ impl StorageBackend for SqliteBackend {
|
|||
"INSERT INTO markdown_links (
|
||||
id, source_media_id, target_path, target_media_id,
|
||||
link_type, link_text, line_number, context, created_at
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)"
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)",
|
||||
)?;
|
||||
|
||||
for link in &links {
|
||||
|
|
@ -6438,7 +6438,10 @@ impl StorageBackend for SqliteBackend {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_outgoing_links(&self, media_id: MediaId) -> Result<Vec<crate::model::MarkdownLink>> {
|
||||
async fn get_outgoing_links(
|
||||
&self,
|
||||
media_id: MediaId,
|
||||
) -> Result<Vec<crate::model::MarkdownLink>> {
|
||||
let conn = self.conn.clone();
|
||||
let media_id_str = media_id.0.to_string();
|
||||
|
||||
|
|
@ -6449,12 +6452,10 @@ impl StorageBackend for SqliteBackend {
|
|||
link_type, link_text, line_number, context, created_at
|
||||
FROM markdown_links
|
||||
WHERE source_media_id = ?1
|
||||
ORDER BY line_number"
|
||||
ORDER BY line_number",
|
||||
)?;
|
||||
|
||||
let rows = stmt.query_map([&media_id_str], |row| {
|
||||
row_to_markdown_link(row)
|
||||
})?;
|
||||
let rows = stmt.query_map([&media_id_str], |row| row_to_markdown_link(row))?;
|
||||
|
||||
let mut links = Vec::new();
|
||||
for row in rows {
|
||||
|
|
@ -6480,7 +6481,7 @@ impl StorageBackend for SqliteBackend {
|
|||
FROM markdown_links l
|
||||
JOIN media_items m ON l.source_media_id = m.id
|
||||
WHERE l.target_media_id = ?1
|
||||
ORDER BY m.title, l.line_number"
|
||||
ORDER BY m.title, l.line_number",
|
||||
)?;
|
||||
|
||||
let rows = stmt.query_map([&media_id_str], |row| {
|
||||
|
|
@ -6501,7 +6502,9 @@ impl StorageBackend for SqliteBackend {
|
|||
link_text,
|
||||
line_number,
|
||||
context,
|
||||
link_type: link_type_str.parse().unwrap_or(crate::model::LinkType::Wikilink),
|
||||
link_type: link_type_str
|
||||
.parse()
|
||||
.unwrap_or(crate::model::LinkType::Wikilink),
|
||||
})
|
||||
})?;
|
||||
|
||||
|
|
@ -6564,7 +6567,7 @@ impl StorageBackend for SqliteBackend {
|
|||
// Get outgoing links
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT target_media_id FROM markdown_links
|
||||
WHERE source_media_id = ?1 AND target_media_id IS NOT NULL"
|
||||
WHERE source_media_id = ?1 AND target_media_id IS NOT NULL",
|
||||
)?;
|
||||
let rows = stmt.query_map([node_id], |row| {
|
||||
let id: String = row.get(0)?;
|
||||
|
|
@ -6581,7 +6584,7 @@ impl StorageBackend for SqliteBackend {
|
|||
// Get incoming links
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT source_media_id FROM markdown_links
|
||||
WHERE target_media_id = ?1"
|
||||
WHERE target_media_id = ?1",
|
||||
)?;
|
||||
let rows = stmt.query_map([node_id], |row| {
|
||||
let id: String = row.get(0)?;
|
||||
|
|
@ -6605,7 +6608,7 @@ impl StorageBackend for SqliteBackend {
|
|||
let mut stmt = conn.prepare(
|
||||
"SELECT DISTINCT id FROM media_items
|
||||
WHERE media_type = 'markdown' AND deleted_at IS NULL
|
||||
LIMIT 500"
|
||||
LIMIT 500",
|
||||
)?;
|
||||
let rows = stmt.query_map([], |row| {
|
||||
let id: String = row.get(0)?;
|
||||
|
|
@ -6620,7 +6623,7 @@ impl StorageBackend for SqliteBackend {
|
|||
for node_id in &node_ids {
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT id, COALESCE(title, file_name) as label, title, media_type
|
||||
FROM media_items WHERE id = ?1"
|
||||
FROM media_items WHERE id = ?1",
|
||||
)?;
|
||||
if let Ok((id, label, title, media_type)) = stmt.query_row([node_id], |row| {
|
||||
Ok((
|
||||
|
|
@ -6660,7 +6663,7 @@ impl StorageBackend for SqliteBackend {
|
|||
let mut stmt = conn.prepare(
|
||||
"SELECT source_media_id, target_media_id, link_type
|
||||
FROM markdown_links
|
||||
WHERE source_media_id = ?1 AND target_media_id IS NOT NULL"
|
||||
WHERE source_media_id = ?1 AND target_media_id IS NOT NULL",
|
||||
)?;
|
||||
let rows = stmt.query_map([node_id], |row| {
|
||||
let source: String = row.get(0)?;
|
||||
|
|
@ -6674,7 +6677,9 @@ impl StorageBackend for SqliteBackend {
|
|||
edges.push(crate::model::GraphEdge {
|
||||
source,
|
||||
target,
|
||||
link_type: link_type_str.parse().unwrap_or(crate::model::LinkType::Wikilink),
|
||||
link_type: link_type_str
|
||||
.parse()
|
||||
.unwrap_or(crate::model::LinkType::Wikilink),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue