<- Back to Blog

Tool Update - CSV Template Merge

Ben Maddox ยท Thursday, November 30, 2023

Affiliate Link

Lenovo Ideapad Newest 14 inch FHD Laptop Computer - 8GB RAM 256GB NVMe SSD Intel Core i3-1115G4

The exact budget friendly laptop I got my dad. It has been working well for him.

I have a new tool that has been rolling around in my head for a while. CSV Template Merge. There are many times when I've had to take a list of data and output repetitive code/data. There are many ways to do this, but it felt more challenging to set up than I wanted. With this tool, it should be much easier. You can set up what each item will output using a JavaScript template that is edited inline. You don't have to write the code and can see updates quickly. And because of how you set up the templates, it can use the full power of JavaScript.

One area where this would provide a lot of day-to-day use is formatting data for SQL scripting. As a simplified example, I have the CSV input.


name,dob,active
John,1/1/2000,true
Jane,1/1/2001,false
Bob,1/1/2002,true

and the template


insert into users (name, dob, active)
values ('${name}', '${dob}', ${active === 'true' ? 1 : 0});

Once merged, you'll get insert statements like this.


insert into users (name, dob, active)
values ('John', '1/1/2000', 1);

insert into users (name, dob, active)
values ('Jane', '1/1/2001', 0);

insert into users (name, dob, active)
values ('Bob', '1/1/2002', 1);

I like it this way because you're not dealing with a lot of manual replacement, excel string concatenation, or regex manipulation. I hope others also find this to be useful.

Have a great day!
Ben Maddox