const SOURCE: &str = include_str!("../../queries/psql/posts.sql");
const _: () = assert!(
SOURCE.len() == 4758usize,
"tests/queries/psql/posts.sql changed after it was generated from; re-run keelson-gen"
);
#[derive(Debug, Clone, PartialEq)]
pub struct PostsForUserParams {
pub user_id: i32,
pub limit: i64,
}
impl PostsForUserParams {
pub fn new(user_id: i32, 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<(i32, i64)> for PostsForUserParams {
fn from(v: (i32, i64)) -> Self {
PostsForUserParams::new(v.0, v.1)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PostsForUserRow {
pub id: i32,
pub title: String,
pub status: Option<String>,
pub views: i32,
pub published_at: Option<chrono::DateTime<chrono::Utc>>,
}
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[619usize..706usize]);
w.push_arg(args[0].clone());
w.push_str(&SOURCE[708usize..744usize]);
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_psql::Psql
}
}
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_psql::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_psql::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[680usize..687usize]);
}),
),
);
}
}
{
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[694usize..706usize]);
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[718usize..737usize]);
}),
),
);
}
{
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: i32,
}
impl CommentsWithAuthorParams {
pub fn new(post_id: i32) -> Self {
CommentsWithAuthorParams {
post_id,
}
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.post_id)]
}
}
impl From<i32> for CommentsWithAuthorParams {
fn from(v: i32) -> Self {
CommentsWithAuthorParams::new(v)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct CommentsWithAuthorAuthor {
pub id: i32,
pub name: String,
pub email: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CommentsWithAuthorRow {
pub id: i32,
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<i32> = 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[1137usize..1331usize]);
w.push_arg(args[0].clone());
w.push_str(&SOURCE[1333usize..1347usize]);
}
}
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_psql::Psql
}
}
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_psql::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_psql::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[1264usize..1312usize]);
}),
),
);
}
}
{
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[1319usize..1331usize]);
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[1343usize..1347usize]);
}),
),
);
}
})
}
#[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: i32,
pub name: String,
pub email: Option<String>,
pub post_count: i64,
pub best_views: Option<i32>,
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[1722usize..2031usize]);
}
}
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_psql::Psql
}
}
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_psql::SelectQuery> {
let _ = params;
keelson_core::mod_fn(move |q: &mut keelson_psql::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[1915usize..1960usize]);
}),
),
);
}
}
{
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[1967usize..1986usize]);
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[1996usize..2017usize]);
}),
),
);
}
{
q.order_by
.append_order(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[2027usize..2031usize]);
}),
),
);
}
})
}
#[derive(Debug, Clone, PartialEq)]
pub struct PostFlagsParams {
pub views: i32,
}
impl PostFlagsParams {
pub fn new(views: i32) -> Self {
PostFlagsParams { views }
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.views)]
}
}
impl From<i32> for PostFlagsParams {
fn from(v: i32) -> Self {
PostFlagsParams::new(v)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PostFlagsRow {
pub id: i32,
pub has_status: bool,
pub is_popular: bool,
pub is_published: Option<bool>,
pub heat: String,
pub maybe_heat: Option<String>,
pub views_wide: i64,
}
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_wide: row.take("views_wide")?,
})
}
}
#[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[2419usize..2517usize]);
w.push_arg(args[0].clone());
w.push_str(&SOURCE[2519usize..2866usize]);
}
}
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_psql::Psql
}
}
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_psql::SelectQuery> {
let _ = params;
keelson_core::mod_fn(move |q: &mut keelson_psql::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[2845usize..2852usize]);
}),
),
);
}
}
{
q.order_by
.append_order(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[2862usize..2866usize]);
}),
),
);
}
})
}
#[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: i32,
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[3030usize..3189usize]);
}
}
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_psql::Psql
}
}
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_psql::SelectQuery> {
let _ = params;
keelson_core::mod_fn(move |q: &mut keelson_psql::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[3079usize..3167usize]);
}),
),
);
}
}
{
q.order_by
.append_order(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[3177usize..3189usize]);
}),
),
);
}
})
}
#[derive(Debug, Clone, PartialEq)]
pub struct UserByIdParams {
pub id: i32,
}
impl UserByIdParams {
pub fn new(id: i32) -> Self {
UserByIdParams { id }
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.id)]
}
}
impl From<i32> for UserByIdParams {
fn from(v: i32) -> Self {
UserByIdParams::new(v)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct UserByIdRow {
pub id: i32,
pub name: String,
pub email: Option<String>,
pub age: Option<i32>,
pub is_active: bool,
pub created_at: chrono::DateTime<chrono::Utc>,
}
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[3272usize..3361usize]);
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_psql::Psql
}
}
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_psql::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_psql::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[3340usize..3347usize]);
}),
),
);
}
}
{
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[3354usize..3361usize]);
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: i32,
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[3702usize..3772usize]);
w.push_arg(args[0].clone());
w.push_str(&SOURCE[3774usize..3788usize]);
}
}
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_psql::Psql
}
}
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_psql::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_psql::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[3745usize..3752usize]);
}),
),
);
}
}
{
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[3759usize..3772usize]);
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[3784usize..3788usize]);
}),
),
);
}
})
}
#[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[3954usize..4035usize]);
}
}
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_psql::Psql
}
}
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: i32,
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[4122usize..4171usize]);
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_psql::Psql
}
}
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_psql::SelectQuery> {
let args = params.into().args();
keelson_core::mod_fn(move |q: &mut keelson_psql::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[4147usize..4154usize]);
}),
),
);
}
}
{
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[4161usize..4171usize]);
w.push_arg(a0.clone());
w.push_str(")");
}),
),
);
}
})
}
#[derive(Debug, Clone, PartialEq)]
pub struct BumpViewsParams {
pub id: i32,
}
impl BumpViewsParams {
pub fn new(id: i32) -> Self {
BumpViewsParams { id }
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![keelson_core::ToValue::to_value(self.id)]
}
}
impl From<i32> for BumpViewsParams {
fn from(v: i32) -> 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[4337usize..4383usize]);
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_psql::Psql
}
}
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, Default)]
pub struct CommentsWithPrefixedAuthorParams {}
impl CommentsWithPrefixedAuthorParams {
pub fn new() -> Self {
CommentsWithPrefixedAuthorParams {
}
}
pub fn args(&self) -> Vec<keelson_core::Value> {
vec![]
}
}
impl From<()> for CommentsWithPrefixedAuthorParams {
fn from((): ()) -> Self {
CommentsWithPrefixedAuthorParams::new()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct CommentsWithPrefixedAuthorAuthor {
pub id: i32,
pub name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CommentsWithPrefixedAuthorRow {
pub id: i32,
pub author: Option<CommentsWithPrefixedAuthorAuthor>,
}
impl keelson_exec::FromRow for CommentsWithPrefixedAuthorRow {
fn from_row(row: &mut keelson_exec::Row) -> Result<Self, keelson_exec::ExecError> {
Ok(CommentsWithPrefixedAuthorRow {
id: row.take("id")?,
author: {
let id: Option<i32> = row.take("author_id")?;
let name: Option<String> = row.take("author_name")?;
match (id, name) {
(Some(id), Some(name)) => {
Some(CommentsWithPrefixedAuthorAuthor {
id,
name,
})
}
_ => None,
}
},
})
}
}
#[derive(Debug, Clone)]
pub struct CommentsWithPrefixedAuthorQuery {
params: CommentsWithPrefixedAuthorParams,
}
impl CommentsWithPrefixedAuthorQuery {
pub fn params(&self) -> &CommentsWithPrefixedAuthorParams {
&self.params
}
}
impl keelson_core::Expression for CommentsWithPrefixedAuthorQuery {
fn write_sql(&self, w: &mut keelson_core::SqlWriter<'_>) {
w.push_str(&SOURCE[4635usize..4756usize]);
}
}
impl keelson_core::Query for CommentsWithPrefixedAuthorQuery {
fn query_type(&self) -> keelson_core::QueryType {
keelson_core::QueryType::Select
}
fn dialect(&self) -> &dyn keelson_core::Dialect {
&keelson_psql::Psql
}
}
impl<H, L, M> keelson_core::QueryExtensions<H, L, M>
for CommentsWithPrefixedAuthorQuery {}
pub fn comments_with_prefixed_author_query(
params: impl Into<CommentsWithPrefixedAuthorParams>,
) -> CommentsWithPrefixedAuthorQuery {
CommentsWithPrefixedAuthorQuery {
params: params.into(),
}
}
pub async fn comments_with_prefixed_author(
db: &dyn keelson_exec::Executor,
params: impl Into<CommentsWithPrefixedAuthorParams>,
) -> Result<Vec<CommentsWithPrefixedAuthorRow>, keelson_exec::ExecError> {
use keelson_exec::Execute as _;
comments_with_prefixed_author_query(params)
.fetch_all::<CommentsWithPrefixedAuthorRow>(db)
.await
}
pub fn comments_with_prefixed_author_mod(
params: impl Into<CommentsWithPrefixedAuthorParams>,
) -> impl keelson_core::Mod<keelson_psql::SelectQuery> {
let _ = params;
keelson_core::mod_fn(move |q: &mut keelson_psql::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[4694usize..4742usize]);
}),
),
);
}
}
{
q.order_by
.append_order(
keelson_core::dyn_expr(
keelson_core::expr_fn(move |w: &mut keelson_core::SqlWriter<'_>| {
w.push_str(&SOURCE[4752usize..4756usize]);
}),
),
);
}
})
}