Skip to content

Adds MySQL syntax to Transaction builder#52

Merged
belchior merged 1 commit intomysqlfrom
mysql-transaction
Apr 27, 2025
Merged

Adds MySQL syntax to Transaction builder#52
belchior merged 1 commit intomysqlfrom
mysql-transaction

Conversation

@belchior
Copy link
Owner

@belchior belchior commented Apr 21, 2025

Builder API

use sql_query_builder as sql;

let query = sql::Transaction::new()
  // one of methods
  .begin("")
  .start_transaction("")
  // optional methods
  .set_transaction("")
  // at least one of methods
  .alter_table(sql::AlterTable::new().alter_table("users"))
  .create_index(sql::CreateIndex::new().create_index("users_idx"))
  .create_table(sql::CreateTable::new().create_table("users"))
  .delete(sql::Delete::new().delete_from("users"))
  .drop_index(sql::DropIndex::new().drop_index("users_idx"))
  .drop_table(sql::DropTable::new().drop_table("users"))
  .insert(sql::Insert::new().insert_into("users"))
  .select(sql::Select::new().select("login"))
  .update(sql::Update::new().update("users"))
  // one of methods
  .rollback("")
  .commit("")
  .as_string();

let expected_query = "\
  BEGIN; \
  START TRANSACTION; \
  SET TRANSACTION; \
  ALTER TABLE users; \
  CREATE INDEX users_idx; \
  CREATE TABLE users; \
  DELETE FROM users; \
  DROP INDEX users_idx; \
  DROP TABLE users; \
  INSERT INTO users; \
  SELECT login; \
  UPDATE users; \
  ROLLBACK; \
  COMMIT;\
";

assert_eq!(expected_query, query);

Reference

@belchior belchior self-assigned this Apr 21, 2025
@belchior belchior added the enhancement New feature or request label Apr 21, 2025
@belchior belchior moved this to In Progress in SQL Query Builder Roadmap Apr 21, 2025
@belchior belchior merged commit bb92d38 into mysql Apr 27, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in SQL Query Builder Roadmap Apr 27, 2025
@belchior belchior deleted the mysql-transaction branch July 17, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

1 participant

Comments