sql_query_builder icon indicating copy to clipboard operation
sql_query_builder copied to clipboard

Create index builder

Open belchior opened this issue 1 year ago • 0 comments

Adds CreateIndex builder

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);

belchior avatar Sep 28 '24 18:09 belchior