Skip to content

Adds CreateIndex builder#32

Merged
belchior merged 4 commits into
mainfrom
create-index-builder
Oct 6, 2024
Merged

Adds CreateIndex builder#32
belchior merged 4 commits into
mainfrom
create-index-builder

Conversation

@belchior
Copy link
Copy Markdown
Owner

@belchior belchior commented Sep 28, 2024

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

@belchior belchior added documentation Improvements or additions to documentation enhancement New feature or request labels Sep 28, 2024
@belchior belchior self-assigned this Sep 28, 2024
@belchior belchior linked an issue Sep 28, 2024 that may be closed by this pull request
@belchior belchior force-pushed the create-index-builder branch from f029844 to b6f4820 Compare September 28, 2024 18:25
@belchior belchior merged commit b2bd52b into main Oct 6, 2024
@belchior belchior changed the title Create index builder Adds CreateIndex builder Oct 6, 2024
@belchior belchior deleted the create-index-builder branch November 11, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

Add builder CreateIndex

1 participant