byCodemod

Sql/Add Index Before Select

/icons/calendar.svg

Last update

Jul 26, 2024

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