const SOURCE: &str = include_str!("../../queries/sqlite/posts.sql");
const _: () = assert!(
SOURCE.len() == 3261usize,
"tests/queries/sqlite/posts.sql changed after it was generated from; re-run keelson-gen"
);
#[derive(Debug, Clone, PartialEq)]
pub struct PostsForUserParams {
pub user_id: i64,
pub limit: i64,
}
impl PostsForUserParams {
pub fn new(user_id: i64, limit: i64) -> Self {
PostsForUserParams {
user_id,
limit,
}
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![
keelson_core::ToValue::to_value(self.user_id),
keelson_core::ToValue::to_value(self.limit)
]
}
}
impl From<(i64, i64)> for PostsForUserParams {
fn from(v: (i64, i64)) -> Self {
PostsForUserParams::new(v.0, v.1)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PostsForUserRow {
pub id: i64,
pub title: String,
pub status: Option<String>,
pub views: i64,
pub published_at: Option<chrono::NaiveDateTime>,
}
impl keelson_exec::FromRow for PostsForUserRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(PostsForUserRow {
id: row.take("id")?,
title: row.take("title")?,
status: row.take("status")?,
views: row.take("views")?,
published_at: row.take("published_at")?,
})
}
}
#[derive(Debug, Clone)]
pub struct PostsForUserQuery {
params: PostsForUserParams,
}
impl PostsForUserQuery {
pub fn params(&self) -> &PostsForUserParams {
&self.params
}
}
impl keelson_core::Expression for PostsForUserQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
let args = self.params.args();
w.push_str(&SOURCE[407usize..494usize]);
w.push_arg(args[0].clone());
w.push_str(&SOURCE[496usize..532usize]);
w.push_arg(args[1].clone());
}
}
impl keelson_core::Query for PostsForUserQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for PostsForUserQuery {}
pub fn posts_for_user_query(params: impl Into<PostsForUserParams>) -> PostsForUserQuery {
PostsForUserQuery {
params: params.into(),
}
}
pub async fn posts_for_user(
db: &dyn keelson_exec::Executor,
params: impl Into<PostsForUserParams>,
) -> Result<Vec<PostsForUserRow>, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
posts_for_user_query(params).fetch_all::<PostsForUserRow>(db).await
}
pub fn posts_for_user_mod(
params: impl Into<PostsForUserParams>,
) -> impl keelson_core::Mod<keelson_sqlite::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_sqlite::SelectQuery| {
{
if q.from.expression.is_none() {
q.from
.set_table(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |
w: &mut keelson_core::SqlWriter<'_>|
{
w.push_str(&SOURCE[468usize..475usize]);
}),
),
);
}
}
{
let a0 = args[0].clone();
q.where_
.append_where(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str("(");
w.push_str(&SOURCE[482usize..494usize]);
w.push_arg(a0.clone());
w.push_str(")");
}),
),
);
}
{
q.order_by
.append_order(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[506usize..525usize]);
}),
),
);
}
{
let a1 = args[1].clone();
if q.limit.is_empty() {
q.limit
.set_limit(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |
w: &mut keelson_core::SqlWriter<'_>|
{
w.push_arg(a1.clone());
}),
),
);
}
}
})
}
#[derive(Debug, Clone, PartialEq)]
pub struct CommentsWithAuthorParams {
pub post_id: i64,
}
impl CommentsWithAuthorParams {
pub fn new(post_id: i64) -> Self {
CommentsWithAuthorParams {
post_id,
}
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.post_id)]
}
}
impl From<i64> for CommentsWithAuthorParams {
fn from(v: i64) -> Self {
CommentsWithAuthorParams::new(v)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct CommentsWithAuthorAuthor {
pub id: i64,
pub name: String,
pub email: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CommentsWithAuthorRow {
pub id: i64,
pub body: String,
pub author: Option<CommentsWithAuthorAuthor>,
}
impl keelson_exec::FromRow for CommentsWithAuthorRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(CommentsWithAuthorRow {
id: row.take("id")?,
body: row.take("body")?,
author: {
let id: Option<i64> = row.take("author__id")?;
let name: Option<String> = row.take("author__name")?;
let email: Option<String> = row.take("author__email")?;
match (id, name) {
(Some(id), Some(name)) => {
Some(CommentsWithAuthorAuthor {
id,
name,
email,
})
}
_ => None,
}
},
})
}
}
#[derive(Debug, Clone)]
pub struct CommentsWithAuthorQuery {
params: CommentsWithAuthorParams,
}
impl CommentsWithAuthorQuery {
pub fn params(&self) -> &CommentsWithAuthorParams {
&self.params
}
}
impl keelson_core::Expression for CommentsWithAuthorQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
let args = self.params.args();
w.push_str(&SOURCE[723usize..917usize]);
w.push_arg(args[0].clone());
w.push_str(&SOURCE[919usize..933usize]);
}
}
impl keelson_core::Query for CommentsWithAuthorQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for CommentsWithAuthorQuery {}
pub fn comments_with_author_query(
params: impl Into<CommentsWithAuthorParams>,
) -> CommentsWithAuthorQuery {
CommentsWithAuthorQuery {
params: params.into(),
}
}
pub async fn comments_with_author(
db: &dyn keelson_exec::Executor,
params: impl Into<CommentsWithAuthorParams>,
) -> Result<Vec<CommentsWithAuthorRow>, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
comments_with_author_query(params).fetch_all::<CommentsWithAuthorRow>(db).await
}
pub fn comments_with_author_mod(
params: impl Into<CommentsWithAuthorParams>,
) -> impl keelson_core::Mod<keelson_sqlite::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_sqlite::SelectQuery| {
{
if q.from.expression.is_none() {
q.from
.set_table(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |
w: &mut keelson_core::SqlWriter<'_>|
{
w.push_str(&SOURCE[850usize..898usize]);
}),
),
);
}
}
{
let a0 = args[0].clone();
q.where_
.append_where(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str("(");
w.push_str(&SOURCE[905usize..917usize]);
w.push_arg(a0.clone());
w.push_str(")");
}),
),
);
}
{
q.order_by
.append_order(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[929usize..933usize]);
}),
),
);
}
})
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct UserStatsParams {}
impl UserStatsParams {
pub fn new() -> Self {
UserStatsParams {}
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![]
}
}
impl From<()> for UserStatsParams {
fn from((): ()) -> Self {
UserStatsParams::new()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct UserStatsRow {
pub id: i64,
pub name: String,
pub email: Option<String>,
pub post_count: i64,
pub best_views: Option<i64>,
pub total_views: i64,
}
impl keelson_exec::FromRow for UserStatsRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(UserStatsRow {
id: row.take("id")?,
name: row.take("name")?,
email: row.take("email")?,
post_count: row.take("post_count")?,
best_views: row.take("best_views")?,
total_views: row.take("total_views")?,
})
}
}
#[derive(Debug, Clone)]
pub struct UserStatsQuery {
params: UserStatsParams,
}
impl UserStatsQuery {
pub fn params(&self) -> &UserStatsParams {
&self.params
}
}
impl keelson_core::Expression for UserStatsQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
w.push_str(&SOURCE[1112usize..1421usize]);
}
}
impl keelson_core::Query for UserStatsQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for UserStatsQuery {}
pub fn user_stats_query(params: impl Into<UserStatsParams>) -> UserStatsQuery {
UserStatsQuery {
params: params.into(),
}
}
pub async fn user_stats(
db: &dyn keelson_exec::Executor,
params: impl Into<UserStatsParams>,
) -> Result<Vec<UserStatsRow>, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
user_stats_query(params).fetch_all::<UserStatsRow>(db).await
}
pub fn user_stats_mod(
params: impl Into<UserStatsParams>,
) -> impl keelson_core::Mod<keelson_sqlite::SelectQuery> {
let _ = params;
keelson_core::mod_fn(move |q: &mut keelson_sqlite::SelectQuery| {
{
if q.from.expression.is_none() {
q.from
.set_table(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |
w: &mut keelson_core::SqlWriter<'_>|
{
w.push_str(&SOURCE[1305usize..1350usize]);
}),
),
);
}
}
{
q.where_
.append_where(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str("(");
w.push_str(&SOURCE[1357usize..1376usize]);
w.push_str(")");
}),
),
);
}
{
q.group_by
.append_group(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[1386usize..1407usize]);
}),
),
);
}
{
q.order_by
.append_order(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[1417usize..1421usize]);
}),
),
);
}
})
}
#[derive(Debug, Clone, PartialEq)]
pub struct PostFlagsParams {
pub views: i64,
}
impl PostFlagsParams {
pub fn new(views: i64) -> Self {
PostFlagsParams { views }
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.views)]
}
}
impl From<i64> for PostFlagsParams {
fn from(v: i64) -> Self {
PostFlagsParams::new(v)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PostFlagsRow {
pub id: i64,
pub has_status: i64,
pub is_popular: i64,
pub is_published: Option<i64>,
pub heat: String,
pub maybe_heat: Option<String>,
pub views_text: String,
}
impl keelson_exec::FromRow for PostFlagsRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(PostFlagsRow {
id: row.take("id")?,
has_status: row.take("has_status")?,
is_popular: row.take("is_popular")?,
is_published: row.take("is_published")?,
heat: row.take("heat")?,
maybe_heat: row.take("maybe_heat")?,
views_text: row.take("views_text")?,
})
}
}
#[derive(Debug, Clone)]
pub struct PostFlagsQuery {
params: PostFlagsParams,
}
impl PostFlagsQuery {
pub fn params(&self) -> &PostFlagsParams {
&self.params
}
}
impl keelson_core::Expression for PostFlagsQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
let args = self.params.args();
w.push_str(&SOURCE[1536usize..1611usize]);
w.push_arg(args[0].clone());
w.push_str(&SOURCE[1613usize..1896usize]);
}
}
impl keelson_core::Query for PostFlagsQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for PostFlagsQuery {}
pub fn post_flags_query(params: impl Into<PostFlagsParams>) -> PostFlagsQuery {
PostFlagsQuery {
params: params.into(),
}
}
pub async fn post_flags(
db: &dyn keelson_exec::Executor,
params: impl Into<PostFlagsParams>,
) -> Result<Vec<PostFlagsRow>, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
post_flags_query(params).fetch_all::<PostFlagsRow>(db).await
}
pub fn post_flags_mod(
params: impl Into<PostFlagsParams>,
) -> impl keelson_core::Mod<keelson_sqlite::SelectQuery> {
let _ = params;
keelson_core::mod_fn(move |q: &mut keelson_sqlite::SelectQuery| {
{
if q.from.expression.is_none() {
q.from
.set_table(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |
w: &mut keelson_core::SqlWriter<'_>|
{
w.push_str(&SOURCE[1875usize..1882usize]);
}),
),
);
}
}
{
q.order_by
.append_order(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[1892usize..1896usize]);
}),
),
);
}
})
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct PostsWithTagsParams {}
impl PostsWithTagsParams {
pub fn new() -> Self {
PostsWithTagsParams {}
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![]
}
}
impl From<()> for PostsWithTagsParams {
fn from((): ()) -> Self {
PostsWithTagsParams::new()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PostsWithTagsTags {
pub name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PostsWithTagsRow {
pub id: i64,
pub title: String,
pub tags: Vec<PostsWithTagsTags>,
}
impl keelson_exec::FromRow for PostsWithTagsRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(PostsWithTagsRow {
id: row.take("id")?,
title: row.take("title")?,
tags: {
let name: Option<String> = row.take("tags.name")?;
match (name,) {
(Some(name),) => Some(PostsWithTagsTags { name }),
_ => None,
}
}
.into_iter()
.collect::<Vec<_>>(),
})
}
}
#[derive(Debug, Clone)]
pub struct PostsWithTagsQuery {
params: PostsWithTagsParams,
}
impl PostsWithTagsQuery {
pub fn params(&self) -> &PostsWithTagsParams {
&self.params
}
}
impl keelson_core::Expression for PostsWithTagsQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
w.push_str(&SOURCE[1959usize..2118usize]);
}
}
impl keelson_core::Query for PostsWithTagsQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for PostsWithTagsQuery {}
pub fn posts_with_tags_query(
params: impl Into<PostsWithTagsParams>,
) -> PostsWithTagsQuery {
PostsWithTagsQuery {
params: params.into(),
}
}
fn fold_posts_with_tags(rows: Vec<PostsWithTagsRow>) -> Vec<PostsWithTagsRow> {
let mut out: Vec<PostsWithTagsRow> = Vec::with_capacity(rows.len());
for mut row in rows {
if let Some(kept) = out
.iter_mut()
.find(|kept| kept.id == row.id && kept.title == row.title)
{
kept.tags.append(&mut row.tags);
continue;
}
out.push(row);
}
out
}
pub async fn posts_with_tags(
db: &dyn keelson_exec::Executor,
params: impl Into<PostsWithTagsParams>,
) -> Result<Vec<PostsWithTagsRow>, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
let rows = posts_with_tags_query(params).fetch_all::<PostsWithTagsRow>(db).await?;
let rows = fold_posts_with_tags(rows);
Ok(rows)
}
pub fn posts_with_tags_mod(
params: impl Into<PostsWithTagsParams>,
) -> impl keelson_core::Mod<keelson_sqlite::SelectQuery> {
let _ = params;
keelson_core::mod_fn(move |q: &mut keelson_sqlite::SelectQuery| {
{
if q.from.expression.is_none() {
q.from
.set_table(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |
w: &mut keelson_core::SqlWriter<'_>|
{
w.push_str(&SOURCE[2008usize..2096usize]);
}),
),
);
}
}
{
q.order_by
.append_order(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[2106usize..2118usize]);
}),
),
);
}
})
}
#[derive(Debug, Clone, PartialEq)]
pub struct UserByIdParams {
pub id: i64,
}
impl UserByIdParams {
pub fn new(id: i64) -> Self {
UserByIdParams { id }
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.id)]
}
}
impl From<i64> for UserByIdParams {
fn from(v: i64) -> Self {
UserByIdParams::new(v)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct UserByIdRow {
pub id: i64,
pub name: String,
pub email: Option<String>,
pub age: Option<i64>,
pub is_active: bool,
pub created_at: chrono::NaiveDateTime,
}
impl keelson_exec::FromRow for UserByIdRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(UserByIdRow {
id: row.take("id")?,
name: row.take("name")?,
email: row.take("email")?,
age: row.take("age")?,
is_active: row.take("is_active")?,
created_at: row.take("created_at")?,
})
}
}
#[derive(Debug, Clone)]
pub struct UserByIdQuery {
params: UserByIdParams,
}
impl UserByIdQuery {
pub fn params(&self) -> &UserByIdParams {
&self.params
}
}
impl keelson_core::Expression for UserByIdQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
let args = self.params.args();
w.push_str(&SOURCE[2166usize..2255usize]);
w.push_arg(args[0].clone());
}
}
impl keelson_core::Query for UserByIdQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for UserByIdQuery {}
pub fn user_by_id_query(params: impl Into<UserByIdParams>) -> UserByIdQuery {
UserByIdQuery {
params: params.into(),
}
}
pub async fn user_by_id(
db: &dyn keelson_exec::Executor,
params: impl Into<UserByIdParams>,
) -> Result<UserByIdRow, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
user_by_id_query(params).fetch_one::<UserByIdRow>(db).await
}
pub fn user_by_id_mod(
params: impl Into<UserByIdParams>,
) -> impl keelson_core::Mod<keelson_sqlite::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_sqlite::SelectQuery| {
{
if q.from.expression.is_none() {
q.from
.set_table(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |
w: &mut keelson_core::SqlWriter<'_>|
{
w.push_str(&SOURCE[2234usize..2241usize]);
}),
),
);
}
}
{
let a0 = args[0].clone();
q.where_
.append_where(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str("(");
w.push_str(&SOURCE[2248usize..2255usize]);
w.push_arg(a0.clone());
w.push_str(")");
}),
),
);
}
})
}
#[derive(Debug, Clone, PartialEq)]
pub struct AnnotatedParams {
pub title_pattern: String,
}
impl AnnotatedParams {
pub fn new(title_pattern: String) -> Self {
AnnotatedParams { title_pattern }
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.title_pattern.clone())]
}
}
impl From<String> for AnnotatedParams {
fn from(v: String) -> Self {
AnnotatedParams::new(v)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct AnnotatedRow {
pub id: i64,
pub shouty: String,
}
impl keelson_exec::FromRow for AnnotatedRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(AnnotatedRow {
id: row.take("id")?,
shouty: row.take("shouty")?,
})
}
}
#[derive(Debug, Clone)]
pub struct AnnotatedQuery {
params: AnnotatedParams,
}
impl AnnotatedQuery {
pub fn params(&self) -> &AnnotatedParams {
&self.params
}
}
impl keelson_core::Expression for AnnotatedQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
let args = self.params.args();
w.push_str(&SOURCE[2427usize..2497usize]);
w.push_arg(args[0].clone());
w.push_str(&SOURCE[2499usize..2513usize]);
}
}
impl keelson_core::Query for AnnotatedQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for AnnotatedQuery {}
pub fn annotated_query(params: impl Into<AnnotatedParams>) -> AnnotatedQuery {
AnnotatedQuery {
params: params.into(),
}
}
pub async fn annotated(
db: &dyn keelson_exec::Executor,
params: impl Into<AnnotatedParams>,
) -> Result<Vec<AnnotatedRow>, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
annotated_query(params).fetch_all::<AnnotatedRow>(db).await
}
pub fn annotated_mod(
params: impl Into<AnnotatedParams>,
) -> impl keelson_core::Mod<keelson_sqlite::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_sqlite::SelectQuery| {
{
if q.from.expression.is_none() {
q.from
.set_table(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |
w: &mut keelson_core::SqlWriter<'_>|
{
w.push_str(&SOURCE[2470usize..2477usize]);
}),
),
);
}
}
{
let a0 = args[0].clone();
q.where_
.append_where(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str("(");
w.push_str(&SOURCE[2484usize..2497usize]);
w.push_arg(a0.clone());
w.push_str(")");
}),
),
);
}
{
q.order_by
.append_order(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[2509usize..2513usize]);
}),
),
);
}
})
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct TitlesUnionParams {}
impl TitlesUnionParams {
pub fn new() -> Self {
TitlesUnionParams {}
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![]
}
}
impl From<()> for TitlesUnionParams {
fn from((): ()) -> Self {
TitlesUnionParams::new()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct TitlesUnionRow {
pub title: String,
}
impl keelson_exec::FromRow for TitlesUnionRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(TitlesUnionRow {
title: row.take("title")?,
})
}
}
#[derive(Debug, Clone)]
pub struct TitlesUnionQuery {
params: TitlesUnionParams,
}
impl TitlesUnionQuery {
pub fn params(&self) -> &TitlesUnionParams {
&self.params
}
}
impl keelson_core::Expression for TitlesUnionQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
w.push_str(&SOURCE[2679usize..2760usize]);
}
}
impl keelson_core::Query for TitlesUnionQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for TitlesUnionQuery {}
pub fn titles_union_query(params: impl Into<TitlesUnionParams>) -> TitlesUnionQuery {
TitlesUnionQuery {
params: params.into(),
}
}
pub async fn titles_union(
db: &dyn keelson_exec::Executor,
params: impl Into<TitlesUnionParams>,
) -> Result<Vec<TitlesUnionRow>, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
titles_union_query(params).fetch_all::<TitlesUnionRow>(db).await
}
const _: () = ();
#[derive(Debug, Clone, PartialEq)]
pub struct UserByEmailParams {
pub email: String,
}
impl UserByEmailParams {
pub fn new(email: String) -> Self {
UserByEmailParams { email }
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.email.clone())]
}
}
impl From<String> for UserByEmailParams {
fn from(v: String) -> Self {
UserByEmailParams::new(v)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct UserByEmailRow {
pub id: i64,
pub name: String,
}
impl keelson_exec::FromRow for UserByEmailRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(UserByEmailRow {
id: row.take("id")?,
name: row.take("name")?,
})
}
}
#[derive(Debug, Clone)]
pub struct UserByEmailQuery {
params: UserByEmailParams,
}
impl UserByEmailQuery {
pub fn params(&self) -> &UserByEmailParams {
&self.params
}
}
impl keelson_core::Expression for UserByEmailQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
let args = self.params.args();
w.push_str(&SOURCE[2816usize..2865usize]);
w.push_arg(args[0].clone());
}
}
impl keelson_core::Query for UserByEmailQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for UserByEmailQuery {}
pub fn user_by_email_query(params: impl Into<UserByEmailParams>) -> UserByEmailQuery {
UserByEmailQuery {
params: params.into(),
}
}
pub async fn user_by_email(
db: &dyn keelson_exec::Executor,
params: impl Into<UserByEmailParams>,
) -> Result<Option<UserByEmailRow>, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
user_by_email_query(params).fetch_optional::<UserByEmailRow>(db).await
}
pub fn user_by_email_mod(
params: impl Into<UserByEmailParams>,
) -> impl keelson_core::Mod<keelson_sqlite::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_sqlite::SelectQuery| {
{
if q.from.expression.is_none() {
q.from
.set_table(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |
w: &mut keelson_core::SqlWriter<'_>|
{
w.push_str(&SOURCE[2841usize..2848usize]);
}),
),
);
}
}
{
let a0 = args[0].clone();
q.where_
.append_where(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str("(");
w.push_str(&SOURCE[2855usize..2865usize]);
w.push_arg(a0.clone());
w.push_str(")");
}),
),
);
}
})
}
#[derive(Debug, Clone, PartialEq)]
pub struct BumpViewsParams {
pub id: i64,
}
impl BumpViewsParams {
pub fn new(id: i64) -> Self {
BumpViewsParams { id }
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.id)]
}
}
impl From<i64> for BumpViewsParams {
fn from(v: i64) -> Self {
BumpViewsParams::new(v)
}
}
#[derive(Debug, Clone)]
pub struct BumpViewsQuery {
params: BumpViewsParams,
}
impl BumpViewsQuery {
pub fn params(&self) -> &BumpViewsParams {
&self.params
}
}
impl keelson_core::Expression for BumpViewsQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
let args = self.params.args();
w.push_str(&SOURCE[2956usize..3002usize]);
w.push_arg(args[0].clone());
}
}
impl keelson_core::Query for BumpViewsQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for BumpViewsQuery {}
pub fn bump_views_query(params: impl Into<BumpViewsParams>) -> BumpViewsQuery {
BumpViewsQuery {
params: params.into(),
}
}
pub async fn bump_views(
db: &dyn keelson_exec::Executor,
params: impl Into<BumpViewsParams>,
) -> Result<keelson_exec::ExecResult, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
bump_views_query(params).execute(db).await
}
const _: () = ();
#[derive(Debug, Clone, PartialEq)]
pub struct HotOrRecentParams {
pub views: i64,
}
impl HotOrRecentParams {
pub fn new(views: i64) -> Self {
HotOrRecentParams { views }
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.views)]
}
}
impl From<i64> for HotOrRecentParams {
fn from(v: i64) -> Self {
HotOrRecentParams::new(v)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct HotOrRecentRow {
pub id: i64,
pub title: String,
}
impl keelson_exec::FromRow for HotOrRecentRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(HotOrRecentRow {
id: row.take("id")?,
title: row.take("title")?,
})
}
}
#[derive(Debug, Clone)]
pub struct HotOrRecentQuery {
params: HotOrRecentParams,
}
impl HotOrRecentQuery {
pub fn params(&self) -> &HotOrRecentParams {
&self.params
}
}
impl keelson_core::Expression for HotOrRecentQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
let args = self.params.args();
w.push_str(&SOURCE[3181usize..3231usize]);
w.push_arg(args[0].clone());
w.push_str(&SOURCE[3233usize..3259usize]);
}
}
impl keelson_core::Query for HotOrRecentQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_sqlite::Sqlite
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M> for HotOrRecentQuery {}
pub fn hot_or_recent_query(params: impl Into<HotOrRecentParams>) -> HotOrRecentQuery {
HotOrRecentQuery {
params: params.into(),
}
}
pub async fn hot_or_recent(
db: &dyn keelson_exec::Executor,
params: impl Into<HotOrRecentParams>,
) -> Result<Vec<HotOrRecentRow>, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
hot_or_recent_query(params).fetch_all::<HotOrRecentRow>(db).await
}
pub fn hot_or_recent_mod(
params: impl Into<HotOrRecentParams>,
) -> impl keelson_core::Mod<keelson_sqlite::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_sqlite::SelectQuery| {
{
if q.from.expression.is_none() {
q.from
.set_table(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |
w: &mut keelson_core::SqlWriter<'_>|
{
w.push_str(&SOURCE[3207usize..3214usize]);
}),
),
);
}
}
{
let a0 = args[0].clone();
q.where_
.append_where(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str("(");
w.push_str(&SOURCE[3221usize..3231usize]);
w.push_arg(a0.clone());
w.push_str(&SOURCE[3233usize..3259usize]);
w.push_str(")");
}),
),
);
}
})
}