Sql/Add Index Before Select

1.0.0Last update Jul 26, 2024
by@Codemod

Example of using codemod that changes SQL. It detects all SELECT statements and adds an index creation statement before them. Inside SELECT statement for any fields that ends with _id it creates an index on that field.

Example

Before

select * FROM orders WHERE customer_id = 123;

After

CREATE INDEX idx_customer_id ON orders(customer_id);
SELECT * FROM orders WHERE customer_id = 123;

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now