Skip to content

Releases: belchior/sql_query_builder

2.4.1

30 Oct 13:04
d3e67e2
Compare
Choose a tag to compare

2.4.0

06 Oct 19:26
Compare
Choose a tag to compare

This release contains

New Features

Adds DropIndex builder

Builder to contruct a DropIndex command. This command is available only for the crate features postgresql and sqlite

Basic API

use sql_query_builder as sql;

let query = sql::DropIndex::new()
  .drop_index("users_name_idx")
  .as_string();

let expected = "DROP INDEX users_name_idx";
assert_eq!(expected, query);

Output

DROP INDEX users_name_idx

Adds DropTable builder

Builder to contruct a drop index command. Available only for the crate features postgresql and sqlite

Basic API

use sql_query_builder as sql;

let query = sql::DropTable::new()
  .drop_table("users")
  .as_string();

let expected = "DROP TABLE users";

assert_eq!(expected, query);

Output

DROP TABLE users

Adds CreateIndex builder

Builder to contruct a create index command. Available only for the crate features postgresql and sqlite.

Builder API

let query = sql::CreateIndex::new()
  // at least one of methods
  .create_index("users_name_idx")
  .create_index_if_not_exists("users_name_idx")
  .unique()
  .concurrently()
  // required methods
  .on("users")
  .column("name")
  // optional methods
  .only()
  .using("btree")
  .include("last_name")
  .where_clause("created_at >= $1")
  .where_and("created_at < $2")
  .where_or("status = 'active'")
  .as_string();

let expected_query = "\
  CREATE UNIQUE INDEX \
  CONCURRENTLY \
  IF NOT EXISTS users_name_idx \
  ON ONLY users \
  USING btree \
  (name) \
  INCLUDE (last_name) \
  WHERE \
    created_at >= $1 \
    AND created_at < $2 \
    OR status = 'active'\
";

assert_eq!(expected_query, query);

2.3.0

21 Jul 19:38
Compare
Choose a tag to compare

This release contains

  • 74c2848 - Adds alter table command

New features

AlterTable command

use sql_query_builder as sql;

let query = sql::AlterTable::new()
  .alter_table("users")
  .add("COLUMN id serial primary key")
  .add("COLUMN login varchar(40) not null")
  .drop("CONSTRAINT users_login_key")
  .as_string();

let expected = "\
  ALTER TABLE users \
    ADD COLUMN id serial primary key, \
    ADD COLUMN login varchar(40) not null, \
    DROP CONSTRAINT users_login_key\
";

assert_eq!(expected, query);

2.2.0

16 Apr 10:14
Compare
Choose a tag to compare

This release contains

  • fd022fc - Adds feature flags annotation
  • 07f22e6 - Adds create table command

New features

Adds the create table builder, the basic API is

use sql_query_builder as sql;

let query = sql::CreateTable::new()
  .create_table("users")
  .column("id serial primary key")
  .column("login varchar(40) not null")
  .constraint("users_login_key unique(login)")
  .as_string();

let expected = "\
  CREATE TABLE users (\
    id serial primary key, \
    login varchar(40) not null, \
    CONSTRAINT users_login_key unique(login)\
  )\
";

assert_eq!(expected, query);

2.1.0

25 Nov 14:41
fb14c80
Compare
Choose a tag to compare

This release contains

  • 9b98689 - Adds methods window and where_and and documentation improvements

New features

Added window method on Select builder

use sql_query_builder as sql;

let query = sql::Select::new()
  .window("win")
  .as_string();

Added where_and method on Select, Delete and Update Builders

use sql_query_builder as sql;

let select_query = sql::Select::new()
  .from("carts")
  .where_clause("login = $1")
  .where_and("session_id = $2")
  .where_and("created_at >= current_date")
  .as_string();

2.0.0

29 Sep 10:41
f344ada
Compare
Choose a tag to compare

This release contains

  • 47de6f5 Adds SQLite syntax
  • 648310b Rewrite of the integration tests and documentation improvements
  • b3c2672 Changes the where clause behavior
  • a46b2bf Refactors to_string and pub(crate)
  • c3f4e3b Makes the default values clause available to insert command

Breaking changes

Minimum version of Rust

This release setups the minimum Rust version to 1.62.0

The method builder.and() was removed

This release changes the behavior of the where clause to support the OR operator.
The alias builder.and("...") was removed in favor of the builder.where_clause("...").

To migrate you will have to replace all use of the builder.and("...") to builder.where_clause("...")

New Features

Adds SQLite syntax support

You can enable it using

# Cargo.toml

sql_query_builder = { version = "2.0.0", features = ["sqlite"] }

After that you can use the following commands:

  • crud operations with: select, insert, update, delete
  • transaction with: begin, savepoint, release, rollback, commit, end

Makes the default values clause available in the insert command

The method default_values() are now available in the Insert builder.

use sql_query_builder as sql;

let insert_query = sql::Insert::new()
  .insert_into("users")
  .default_values()
  .as_string();

Output

INSERT INTO users DEFAULT VALUES;

1.1.4

14 May 19:08
Compare
Choose a tag to compare

This release contains

  • 80cbd0b Adds builder to contruct a transaction block.
    let insert_foo = sql::Insert::new()
      .insert_into("users (login, name)")
      .values("('foo', 'Foo')");
    
    let query = sql::Transaction::new()
      .start_transaction("")
      .insert(insert_foo)
      .commit("")
      .as_string();
  • e51acc3 Adds postgres syntax: begin command
    let query = sql::Transaction::new()
      .begin("")
      .commit("")
      .as_string();

1.0.4

04 May 10:31
1e6f7c1
Compare
Choose a tag to compare

This release contains

  • 9431a7c moves limit and offset methods to postgres syntax

    This changes is conceptually a breaking change but in practice it's not because client that is only SQL Standard these methods are not valid and will emit a SQL Syntax Error.

    This changes can be a breaking change in non supported scenarios like:

    • Uses the library with only standard syntax with a Postgres client
    • Uses the library with only standard syntax with a client that support limit and offset

    If you are in those scenarios the fix can be

    • Enable the postgres syntax like
    # Cargo.toml
    
     sql_query_builder = { version = "1.x.x", features = ["postgresql"] }
    • Converting the methods to raw like
     // before
     let select = new sql::Select::new()
       .select("*")
       .where_clause("login = $1")
       .limit("100");
    
     // after
     let select = new sql::Select::new()
       .select("*")
       .where_clause("login = $1")
       .raw_after(sql::SelectClause::Where, "LIMITE 100");

1.0.3

01 May 21:24
Compare
Choose a tag to compare

This release contains

  • b320abd removed unnecessary lifetimes - by @pdiffley
  • 9c1e7c5 refactor's to make the code base more scalable to receive more feature flags
  • 7711289 improved documentation
  • c8dba3c improved project setup

1.0.2

11 Sep 13:13
Compare
Choose a tag to compare

This release contains

  • Documentation improvements - f717250