Skip to content

Commit

Permalink
Merge pull request #448 from ikrivosheev/feature/small_improvments
Browse files Browse the repository at this point in the history
Small improvments
  • Loading branch information
tyt2y3 authored Sep 25, 2022
2 parents a7f2def + e5284cf commit 99fd103
Show file tree
Hide file tree
Showing 37 changed files with 221 additions and 229 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ assert_eq!(
.column(Glyph::Image)
.from(Glyph::Table)
.and_where(Expr::col(Glyph::Image).like("A"))
.and_where(Expr::col(Glyph::Id).is_in(vec![1, 2, 3]))
.and_where(Expr::col(Glyph::Id).is_in([1, 2, 3]))
.build(PostgresQueryBuilder),
(
r#"SELECT "image" FROM "glyph" WHERE "image" LIKE $1 AND "id" IN ($2, $3, $4)"#
.to_owned(),
Values(vec![
Values([
Value::String(Some(Box::new("A".to_owned()))),
Value::Int(Some(1)),
Value::Int(Some(2)),
Expand Down Expand Up @@ -231,7 +231,7 @@ assert_eq!(
.and_where(
Expr::col(Char::SizeW).in_subquery(
Query::select()
.expr(Expr::cust_with_values("ln($1 ^ $2)", vec![2.4, 1.2]))
.expr(Expr::cust_with_values("ln($1 ^ $2)", [2.4, 1.2]))
.take()
)
)
Expand Down Expand Up @@ -270,7 +270,7 @@ assert_eq!(
)
.add(
Cond::all()
.add(Expr::col(Glyph::Aspect).is_in(vec![3, 4]))
.add(Expr::col(Glyph::Aspect).is_in([3, 4]))
.add(Expr::col(Glyph::Image).like("A%"))
)
)
Expand All @@ -290,7 +290,7 @@ There is also the [`any!`] and [`all!`] macro at your convenience:

```rust
Query::select().cond_where(any![
Expr::col(Glyph::Aspect).is_in(vec![3, 4]),
Expr::col(Glyph::Aspect).is_in([3, 4]),
all![
Expr::col(Glyph::Aspect).is_null(),
Expr::col(Glyph::Image).like("A%")
Expand Down
4 changes: 2 additions & 2 deletions examples/postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn main() {
Document::Decimal,
Document::Array,
])
.values_panic(vec![
.values_panic([
document_chrono.uuid.into(),
serde_json::to_value(document_chrono.json_field)
.unwrap()
Expand All @@ -101,7 +101,7 @@ fn main() {
document_chrono.decimal.into(),
document_chrono.array.into(),
])
.values_panic(vec![
.values_panic([
document_time.uuid.into(),
serde_json::to_value(document_time.json_field)
.unwrap()
Expand Down
8 changes: 4 additions & 4 deletions examples/sqlx_any/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ async fn main() {

let (sql, values) = Query::insert()
.into_table(Character::Table)
.columns(vec![
.columns([
Character::FontSize,
Character::Character,
Character::Created,
])
.values_panic(vec![
.values_panic([
12.into(),
"A".into(),
NaiveDate::from_ymd(2020, 8, 20).and_hms(0, 0, 0).into(),
Expand All @@ -95,7 +95,7 @@ async fn main() {
// Read

let (sql, values) = Query::select()
.columns(vec![
.columns([
Character::Id,
Character::Character,
Character::FontSize,
Expand All @@ -120,7 +120,7 @@ async fn main() {

let (sql, values) = Query::update()
.table(Character::Table)
.values(vec![(Character::FontSize, 24.into())])
.values([(Character::FontSize, 24.into())])
.and_where(Expr::col(Character::Id).eq(id))
.build_any_sqlx(query_builder);

Expand Down
10 changes: 5 additions & 5 deletions examples/sqlx_mysql/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn main() {
Character::BigDecimal,
Character::Created,
])
.values_panic(vec![
.values_panic([
Uuid::new_v4().into(),
12.into(),
"A".into(),
Expand All @@ -71,7 +71,7 @@ async fn main() {
.into(),
NaiveDate::from_ymd(2020, 8, 20).and_hms(0, 0, 0).into(),
])
.values_panic(vec![
.values_panic([
Uuid::new_v4().into(),
12.into(),
"A".into(),
Expand Down Expand Up @@ -134,7 +134,7 @@ async fn main() {

let (sql, values) = Query::update()
.table(Character::Table)
.values(vec![(Character::FontSize, 24.into())])
.values([(Character::FontSize, 24.into())])
.and_where(Expr::col(Character::Id).eq(id))
.build_sqlx(MysqlQueryBuilder);

Expand Down Expand Up @@ -184,8 +184,8 @@ async fn main() {
let (sql, values) = Query::insert()
.into_table(Character::Table)
.columns([Character::Id, Character::FontSize, Character::Character])
.values_panic(vec![1.into(), 16.into(), "B".into()])
.values_panic(vec![2.into(), 24.into(), "C".into()])
.values_panic([1.into(), 16.into(), "B".into()])
.values_panic([2.into(), 24.into(), "C".into()])
.on_conflict(
OnConflict::new()
.update_columns([Character::FontSize, Character::Character])
Expand Down
10 changes: 5 additions & 5 deletions examples/sqlx_postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn main() {
Character::Inet,
Character::MacAddress,
])
.values_panic(vec![
.values_panic([
Uuid::new_v4().into(),
12.into(),
"A".into(),
Expand All @@ -84,7 +84,7 @@ async fn main() {
.into(),
get_mac_address().unwrap().unwrap().into(),
])
.values_panic(vec![
.values_panic([
Uuid::new_v4().into(),
12.into(),
"A".into(),
Expand Down Expand Up @@ -157,7 +157,7 @@ async fn main() {

let (sql, values) = Query::update()
.table(Character::Table)
.values(vec![(Character::FontSize, 24.into())])
.values([(Character::FontSize, 24.into())])
.and_where(Expr::col(Character::Id).eq(id))
.build_sqlx(PostgresQueryBuilder);

Expand Down Expand Up @@ -225,8 +225,8 @@ async fn main() {
let (sql, values) = Query::insert()
.into_table(Character::Table)
.columns([Character::Id, Character::FontSize, Character::Character])
.values_panic(vec![1.into(), 16.into(), "B".into()])
.values_panic(vec![2.into(), 24.into(), "C".into()])
.values_panic([1.into(), 16.into(), "B".into()])
.values_panic([2.into(), 24.into(), "C".into()])
.on_conflict(
OnConflict::column(Character::Id)
.update_columns([Character::FontSize, Character::Character])
Expand Down
10 changes: 5 additions & 5 deletions examples/sqlx_sqlite/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn main() {
Character::Meta,
Character::Created,
])
.values_panic(vec![
.values_panic([
Uuid::new_v4().into(),
12.into(),
"A".into(),
Expand All @@ -56,7 +56,7 @@ async fn main() {
.into(),
NaiveDate::from_ymd(2020, 8, 20).and_hms(0, 0, 0).into(),
])
.values_panic(vec![
.values_panic([
Uuid::new_v4().into(),
12.into(),
"A".into(),
Expand Down Expand Up @@ -113,7 +113,7 @@ async fn main() {
// Update
let (sql, values) = Query::update()
.table(Character::Table)
.values(vec![(Character::FontSize, 24.into())])
.values([(Character::FontSize, 24.into())])
.and_where(Expr::col(Character::Id).eq(id))
.build_sqlx(SqliteQueryBuilder);

Expand Down Expand Up @@ -173,8 +173,8 @@ async fn main() {
let (sql, values) = Query::insert()
.into_table(Character::Table)
.columns([Character::Id, Character::FontSize, Character::Character])
.values_panic(vec![1.into(), 16.into(), "B".into()])
.values_panic(vec![2.into(), 24.into(), "C".into()])
.values_panic([1.into(), 16.into(), "B".into()])
.values_panic([2.into(), 24.into(), "C".into()])
.on_conflict(
OnConflict::column(Character::Id)
.update_columns([Character::FontSize, Character::Character])
Expand Down
28 changes: 14 additions & 14 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ impl Expr {
/// let query = Query::select()
/// .columns([Char::Character, Char::SizeW, Char::SizeH])
/// .from(Char::Table)
/// .and_where(Expr::value(1).into())
/// .and_where(Expr::value(2.5).into())
/// .and_where(Expr::value("3").into())
/// .and_where(Expr::value(1))
/// .and_where(Expr::value(2.5))
/// .and_where(Expr::value("3"))
/// .to_owned();
///
/// assert_eq!(
Expand Down Expand Up @@ -401,7 +401,7 @@ impl Expr {
/// let query = Query::select()
/// .columns([Char::Character, Char::SizeW, Char::SizeH])
/// .from(Char::Table)
/// .and_where(Expr::cust("1 = 1").into())
/// .and_where(Expr::cust("1 = 1"))
/// .to_owned();
///
/// assert_eq!(
Expand Down Expand Up @@ -432,7 +432,7 @@ impl Expr {
/// .columns([Char::Character, Char::SizeW, Char::SizeH])
/// .from(Char::Table)
/// .and_where(Expr::col(Char::Id).eq(1))
/// .and_where(Expr::cust_with_values("6 = ? * ?", vec![2, 3]).into())
/// .and_where(Expr::cust_with_values("6 = ? * ?", [2, 3]))
/// .to_owned();
///
/// assert_eq!(
Expand All @@ -451,7 +451,7 @@ impl Expr {
/// .columns([Char::Character, Char::SizeW, Char::SizeH])
/// .from(Char::Table)
/// .and_where(Expr::col(Char::Id).eq(1))
/// .and_where(Expr::cust_with_values("6 = $2 * $1", vec![3, 2]).into())
/// .and_where(Expr::cust_with_values("6 = $2 * $1", [3, 2]))
/// .to_owned();
///
/// assert_eq!(
Expand All @@ -463,7 +463,7 @@ impl Expr {
/// use sea_query::{tests_cfg::*, *};
///
/// let query = Query::select()
/// .expr(Expr::cust_with_values("6 = ? * ?", vec![2, 3]))
/// .expr(Expr::cust_with_values("6 = ? * ?", [2, 3]))
/// .to_owned();
///
/// assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT 6 = 2 * 3"#);
Expand All @@ -474,7 +474,7 @@ impl Expr {
/// use sea_query::{tests_cfg::*, *};
///
/// let query = Query::select()
/// .expr(Expr::cust_with_values("$1 $$ $2", vec!["a", "b"]))
/// .expr(Expr::cust_with_values("$1 $$ $2", ["a", "b"]))
/// .to_owned();
///
/// assert_eq!(query.to_string(PostgresQueryBuilder), r#"SELECT 'a' $ 'b'"#);
Expand All @@ -485,7 +485,7 @@ impl Expr {
/// let query = Query::select()
/// .expr(Expr::cust_with_values(
/// "data @? ($1::JSONPATH)",
/// vec!["hello"],
/// ["hello"],
/// ))
/// .to_owned();
///
Expand Down Expand Up @@ -1233,7 +1233,7 @@ impl Expr {
/// use sea_query::{*, tests_cfg::*};
///
/// let query = Query::select()
/// .columns(vec![Char::Character, Char::SizeW, Char::SizeH])
/// .columns([Char::Character, Char::SizeW, Char::SizeH])
/// .from(Char::Table)
/// .and_where(Expr::tbl(Char::Table, Char::Character).like(LikeExpr::str(r"|_Our|_").escape('|')))
/// .to_owned();
Expand Down Expand Up @@ -1633,7 +1633,7 @@ impl Expr {
/// let query = Query::select()
/// .columns([Char::Id])
/// .from(Char::Table)
/// .and_where(Expr::tbl(Char::Table, Char::SizeW).is_in(vec![1, 2, 3]))
/// .and_where(Expr::tbl(Char::Table, Char::SizeW).is_in([1, 2, 3]))
/// .to_owned();
///
/// assert_eq!(
Expand Down Expand Up @@ -1744,7 +1744,7 @@ impl Expr {
/// let query = Query::select()
/// .columns([Char::Id])
/// .from(Char::Table)
/// .and_where(Expr::tbl(Char::Table, Char::SizeW).is_not_in(vec![1, 2, 3]))
/// .and_where(Expr::tbl(Char::Table, Char::SizeW).is_not_in([1, 2, 3]))
/// .to_owned();
///
/// assert_eq!(
Expand Down Expand Up @@ -2156,7 +2156,7 @@ impl Expr {
/// let query = Query::insert()
/// .into_table(Char::Table)
/// .columns([Char::FontSize])
/// .exprs_panic(vec![Expr::val("large").as_enum(Alias::new("FontSizeEnum"))])
/// .exprs_panic([Expr::val("large").as_enum(Alias::new("FontSizeEnum"))])
/// .to_owned();
///
/// assert_eq!(
Expand Down Expand Up @@ -2212,7 +2212,7 @@ impl Expr {
/// let query = Query::select()
/// .expr_as(
/// Expr::case(
/// Expr::tbl(Glyph::Table, Glyph::Aspect).is_in(vec![2, 4]),
/// Expr::tbl(Glyph::Table, Glyph::Aspect).is_in([2, 4]),
/// Expr::val(true)
/// )
/// .finally(Expr::val(false)),
Expand Down
16 changes: 7 additions & 9 deletions src/extension/postgres/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ impl PgFunc {
match regconfig {
Some(config) => {
let config = SimpleExpr::Value(config.into());
Expr::func(Function::PgFunction(PgFunction::ToTsquery))
.args(vec![config, expr.into()])
Expr::func(Function::PgFunction(PgFunction::ToTsquery)).args([config, expr.into()])
}
None => Expr::func(Function::PgFunction(PgFunction::ToTsquery)).arg(expr),
}
Expand Down Expand Up @@ -84,8 +83,7 @@ impl PgFunc {
match regconfig {
Some(config) => {
let config = SimpleExpr::Value(config.into());
Expr::func(Function::PgFunction(PgFunction::ToTsvector))
.args(vec![config, expr.into()])
Expr::func(Function::PgFunction(PgFunction::ToTsvector)).args([config, expr.into()])
}
None => Expr::func(Function::PgFunction(PgFunction::ToTsvector)).arg(expr),
}
Expand Down Expand Up @@ -118,7 +116,7 @@ impl PgFunc {
Some(config) => {
let config = SimpleExpr::Value(config.into());
Expr::func(Function::PgFunction(PgFunction::PhrasetoTsquery))
.args(vec![config, expr.into()])
.args([config, expr.into()])
}
None => Expr::func(Function::PgFunction(PgFunction::PhrasetoTsquery)).arg(expr),
}
Expand Down Expand Up @@ -151,7 +149,7 @@ impl PgFunc {
Some(config) => {
let config = SimpleExpr::Value(config.into());
Expr::func(Function::PgFunction(PgFunction::PlaintoTsquery))
.args(vec![config, expr.into()])
.args([config, expr.into()])
}
None => Expr::func(Function::PgFunction(PgFunction::PlaintoTsquery)).arg(expr),
}
Expand Down Expand Up @@ -184,7 +182,7 @@ impl PgFunc {
Some(config) => {
let config = SimpleExpr::Value(config.into());
Expr::func(Function::PgFunction(PgFunction::WebsearchToTsquery))
.args(vec![config, expr.into()])
.args([config, expr.into()])
}
None => Expr::func(Function::PgFunction(PgFunction::WebsearchToTsquery)).arg(expr),
}
Expand All @@ -210,7 +208,7 @@ impl PgFunc {
where
T: Into<SimpleExpr>,
{
Expr::func(Function::PgFunction(PgFunction::TsRank)).args(vec![vector, query])
Expr::func(Function::PgFunction(PgFunction::TsRank)).args([vector, query])
}

/// Call `TS_RANK_CD` function. Postgres only.
Expand All @@ -233,7 +231,7 @@ impl PgFunc {
where
T: Into<SimpleExpr>,
{
Expr::func(Function::PgFunction(PgFunction::TsRankCd)).args(vec![vector, query])
Expr::func(Function::PgFunction(PgFunction::TsRankCd)).args([vector, query])
}

/// Call `ANY` function. Postgres only.
Expand Down
2 changes: 1 addition & 1 deletion src/extension/postgres/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl TypeCreateStatement {
/// assert_eq!(
/// Type::create()
/// .as_enum(FontFamily::Type)
/// .values(vec![
/// .values([
/// FontFamily::Serif,
/// FontFamily::Sans,
/// FontFamily::Monospace
Expand Down
Loading

0 comments on commit 99fd103

Please sign in to comment.