171 lines
3 KiB
TOML
171 lines
3 KiB
TOML
[[snippets]]
|
|
prefix = "drv"
|
|
body = """#[derive(Clone, Debug)]
|
|
$1struct $2 {
|
|
$3
|
|
}"""
|
|
|
|
[[snippets]]
|
|
prefix = "pbc"
|
|
body = "pub(crate) "
|
|
|
|
[[snippets]]
|
|
prefix = "pbs"
|
|
body = "pub(super) "
|
|
|
|
[[snippets]]
|
|
prefix = "phono_model"
|
|
body = """
|
|
use derive_builder::Builder;
|
|
use serde::{Deserialize, Serialize};
|
|
use sqlx::query_as;
|
|
use uuid::Uuid;
|
|
|
|
use crate::{client::AppDbClient, language::Language};
|
|
|
|
///
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct $1 {
|
|
/// Primary key (defaults to UUIDv7).
|
|
pub id: Uuid,
|
|
}
|
|
|
|
impl $1 {
|
|
/// Build an insert statement to create a new object.
|
|
pub fn insert() -> InsertBuilder {
|
|
InsertBuilder::default()
|
|
}
|
|
|
|
/// Build an update statement to alter the content of an existing object.
|
|
pub fn update() -> UpdateBuilder {
|
|
UpdateBuilder::default()
|
|
}
|
|
|
|
/// Build a single-field query by ID.
|
|
pub fn with_id(id: Uuid) -> WithIdQuery {
|
|
WithIdQuery { id }
|
|
}
|
|
}
|
|
|
|
#[derive(Builder, Clone, Debug)]
|
|
pub struct Insertable {
|
|
}
|
|
|
|
impl Insertable {
|
|
pub async fn execute(self, app_db: &mut AppDbClient) -> Result<$1, sqlx::Error> {
|
|
query_as!(
|
|
$1,
|
|
r#"
|
|
insert into $2 () values ()
|
|
returning
|
|
id
|
|
"#,
|
|
)
|
|
.fetch_one(app_db.get_conn())
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(Builder, Clone, Debug, Default)]
|
|
pub struct Update {
|
|
}
|
|
|
|
impl Update {
|
|
pub async fn execute(self, app_db: &mut AppDbClient) -> Result<$1, sqlx::Error> {
|
|
query_as!(
|
|
$1,
|
|
r#"
|
|
insert into $2
|
|
()
|
|
values ()
|
|
returning
|
|
id
|
|
"#,
|
|
)
|
|
.fetch_one(&mut *app_db.conn)
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct WithIdQuery {
|
|
id: Uuid,
|
|
}
|
|
|
|
impl WithIdQuery {
|
|
pub async fn fetch_all(
|
|
self,
|
|
app_db: &mut AppDbClient,
|
|
) -> Result<$1, sqlx::Error> {
|
|
query_as!(
|
|
FieldFormPrompt,
|
|
r#"
|
|
select
|
|
id
|
|
from $2
|
|
where id = $$1
|
|
"#,
|
|
self.id,
|
|
)
|
|
.fetch_one(app_db.get_conn())
|
|
.await
|
|
}
|
|
}
|
|
"""
|
|
|
|
[[snippets]]
|
|
prefix = "resptemp"
|
|
body = """#[derive(Template)]
|
|
#[template(path = $1)]
|
|
struct ResponseTemplate {
|
|
base_path: String,
|
|
breadcrumbs: BreadcrumbTrail,
|
|
csrf_token: String,
|
|
navbar: Navbar,
|
|
}
|
|
|
|
Ok(Html(
|
|
ResponseTemplate {
|
|
breadcrumbs: BreadcrumbTrail::from_base_path(&base_path),
|
|
base_path,
|
|
csrf_token,
|
|
navbar: navbar_template.build(),
|
|
}.render()?,
|
|
).into_response())"""
|
|
|
|
[[snippets]]
|
|
prefix = "dieselmodel"
|
|
body = """
|
|
use diesel::{
|
|
dsl::{auto_type, AsSelect},
|
|
pg::Pg,
|
|
prelude::*,
|
|
};
|
|
|
|
use crate::schema::$1;
|
|
|
|
pub use crate::schema::$1::{dsl, table};
|
|
|
|
#[derive(Clone, Debug, Identifiable, Queryable, Selectable)]
|
|
#[diesel(table_name = $1)]
|
|
pub struct $2 {
|
|
pub id: Uuid,
|
|
}
|
|
|
|
impl $2 {
|
|
#[auto_type(no_type_alias)]
|
|
pub fn all() -> _ {
|
|
let select: AsSelect<Self, Pg> = Self::as_select();
|
|
table.select(select)
|
|
}
|
|
|
|
#[auto_type(no_type_alias)]
|
|
pub fn with_id<'a>(id: &'a Uuid) -> _ {
|
|
dsl::id.eq(id)
|
|
}
|
|
}
|
|
"""
|
|
|
|
[[snippets]]
|
|
prefix = "atnta"
|
|
body = "#[auto_type(no_type_alias)]"
|