DEV Community

Daniel Coturel
Daniel Coturel

Posted on

2 1

CopyMaker

Hi people,
I wanted to show you a little utility I made and decided to publish on GitHub.

I work mainly with a legacy ERP with it's own database, and many times I need to create new records in tables. But in much cases, having to choose between map a 40+ fields table into one of my objects, with their own CRUD behaviour, or make raw SQL statements.
In the second case, one of my favourite strategies is to choose a model element of the table and build a SQL query like this one:

insert into TABLE
select Field1, Field2, Field3 from TABLE where Field1 = :Value

Enter fullscreen mode Exit fullscreen mode

Having this SQL modified, replacing field names in the select with values:

insert into TABLE
select :NewId, 'New Value', Field3 from TABLE where Field1 = :Value

Enter fullscreen mode Exit fullscreen mode

So here come this class, CopyMaker, wich allows you to:
1) Add String or Integer values informing wich field they override
2) Generate SQL for a specified table and a specified condition

I'm open to advice, improvements and anything on this.

Saludos,

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay