Giter Club home page Giter Club logo

sql-builder's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sql-builder's Issues

How i can save instance sql builder for later use

Hi, how to do the following:

let value = Some("Hard".to_string());
let query = SqlBuilder::select_from("users")
    .field("name")
    .field("surname")
    .and_where("surname = ?".bind(&"John"));
if let Some(surname) = value {
    query.and_where("surname = ?".bind(&surname));
}
let res = query.sql()?;

Is it possible?

Is there any support for Postgres Array?

Hey, can we add a function for postgres array text, something similar or better than this?

use serde::Serialize;
    use sql_builder::quote;
    use std::fmt::Display;

    pub fn pg_array<T: Display + Serialize>(value: &[T]) -> String {
        quote(
            serde_json::to_string(value)
                .expect("Failed to serialize value")
                .replace("[", "{")
                .replace("]", "}"),
        )
    }

Where Clause With TO_DATE

Hi, I've been trying to find the proper input to make a query for some columns where a timestamptz field is less than today.

For the column field DATE() SQL function works properly, but for value what should be the input?

let now: DateTime<Local> = Local::now();
let generated_query = &base_select_statement
                .and_where_le("DATE(duedate)",&("TO_DATE(**?????**)"))

Anyone already took care of this scenario?

Is there UUID support?

Is there now (or in the future) UUID support or should I just convert to a string?

pub async fn find_by_id(ctx: &Context<'_>, id: Uuid) -> Result<Option<Organization>> {
    let pool = ctx.data::<PgPool>()?;

    let sql = SqlBuilder::select_from(ORGANIZATION_TABLE_NAME)
        .field("*")
        // Right now I need to convert to a string
        .and_where("id = $1".bind(&id.to_string()))
        .sql()?;

    Ok(sqlx::query_as::<_, Organization>(sql.as_str())
        .fetch_optional(pool)
        .await?)
}

Also, would you recommend using .and_where("id = $1".bind(&SqlName::new(id).safe())) to prevent sql injection since the id is passed from the client or is my understanding of SqlName incorrect?

Support statements with bound values

Hi,

first, thank you for this great crate!

It would be nice to have support for bound values, i.e. statements with ? or $1. So it would benefit from DB statement caching.

Construct query with where clause that can append `and_where` to an existing `or_where`

I want to construct a query that looks as following:

SELECT * FROM table WHERE field1 = '' OR (field2 = '' AND field3 = '');

The code below does not work for obvious reasons:

use sql_builder::{SqlBuilder, quote};

let sql = SqlBuilder::select_from("table")
    .field("*")
    .and_where_eq("field1", quote(""))
    .or_where_eq("field2", quote(""))
    .and_where_eq("field3", quote(""))
    .sql()?;

But I can't find a construct in the docs which would allow me to express this query.
It would be ideal if I would just be able to encapsulate the last two where clause statements within ()?
Note: The data for this query is being dynamically build by some dynamic filter data from user input, similar to as shown below.

enum Filter {
    Field1(StringFilter),
    Field2(StringFilter),
    Field2(StringFilter),
    And(Vec<Filter>),
    Or(Vec<Filter>),
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.