Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Reuse arguments on building #262

Open
@GrandChaman

Description

@GrandChaman

Hi !

Some database specific features are missing from this library. Rather than implementing everyone of them. It would be nice to be able to reuse an argument vectors, so that when concatenating queries, the arguments will be correctly numbered.

Something like (pseudo-code) :

let main_insert = Insert::single_into("my_table")
	.value("foo", 10)
	.build()
	.returning("id");
let following_insert = Insert::single_into("my_dep_table")
	.value("foo", 10)
	.value("main_id", Select::from_table("main_insert").column("id"))
	.build()
	.returning("id");
let final_select = Select::from_table("main_insert")
	.and_from("following_insert")
	.column(Column::from(("main_insert", "id")).alias("main_insert_id"))
	.column(Column::from(("following_insert", "id")).alias("following_insert_id"));
let params: Vec<Value<'_>> = Vec::with_capacity(128);
let (main_insert_query, params) = Postgres::build_with_params(main_insert, params);
let (following_insert_query, params) = Postgres::build_with_params(following_insert, params);
let (final_select_query, params) = Postgres::build_with_params(final_select, params);
let query = format!("WITH 'main_insert' AS ({}), 'following_insert' AS ({}) {};",
	main_insert_query, following_insert_query, final_select_query);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions