rmulley/go-fast-sql

Add support for different insert queries

Closed this issue · 2 comments

I perform four different INSERT types in my program and I want to batch them. Normal usage of BatchInsert doesn't allow it (result: sql expected arguments error). I know I could create four different DB's but SQLite would not handle that.

What about restructuring your lib (without breaking API) to provide support for different INSERTs? It would be really great feature.

@dmgawel Thanks for the suggestion, it's a good idea. Thinking about it, there are two ways to solve this problem.

  1. Create a new type Batch that has a method Insert. In this scenario you would create a new Batch object anytime you wanted to perform a new batch insert. This solution has the drawback of users needing to create new objects and remember which object holds what.
  2. Use the query as a key in a map[string]Batch where Batch is a new type that contains all the necessary data related to that batch insert. Data such as insertCtr, queryPart, queryPart2.

I believe option number two to be the correct approach. It would be non-breaking and not require any new work from the developer utilizing the library. It is also a good approach for when UPDATEs and DELETEs are incorporated. They can follow the same model.

This feature has been merged into the master branch.