sql+ provides some convenience functions for using structs with go's database/sql package
it is fully based on kisielks package. I am using it for experimenting with orm-concepts and am using it for some private projects. Simple stuff, no external dependencies.
Stuff changes and breaks fast atm. Testing is limited.
- Use generics instead of
interface{}
: In my opinion, using generics improves readability and allows for additional functionality. - Keep Language Injections intact: Intellij IDEs offer language injections that, in this case, provide support for sql-queries if literals match sql
query patterns. This was previously not possible, because for injecting columns dynamically with sqlp, a pattern
like
fmt.Sprintf("SELECT %s FROM ...", sqlstruct.Columns(mystruct{}))
had to be used. - Improved the package for my use-cases: While I would love for someone else to find use in this package, one of its main goals is to allow for the
removal of boilerplate and redundant code in my private project by integrating patterns I often deploy. For example, some limited support
for
IN(*)
-Select queries andINSERT
s were added.
This package allows linking a struct and its database-counterpart, which means that SELECT
-queries automatically reflect changes made to the
datastructure by injecting the required columns into the query.
This works by extracting the exported fields of a struct, converting their names and inserting them into the given query. Just write the queries as normal using the autocomplete language injections provide and let your struct-definitions and sqlp take care of the columns.