blob: d25957fd9e1e003688c31e5a3ed24effb9cc4c59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
/*
This file is part of jellything (https://codeberg.org/metamuffin/jellything)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
use anyhow::Result;
use jellycommon::{
NO_SLUG,
jellyobject::{OBB, Path},
};
use jellydb::{Filter, Query, RowNum, Transaction};
pub fn get_or_insert_slug(txn: &mut dyn Transaction, slug: &str) -> Result<RowNum> {
match txn.query_single(Query {
filter: Filter::Match(Path(vec![NO_SLUG.0]), slug.into()),
..Default::default()
})? {
Some(r) => Ok(r),
None => txn.insert(OBB::new().with(NO_SLUG, slug).finish()),
}
}
|