Replies: 1 comment 2 replies
-
You are remarkable. In recent days, I have been diligently seeking an ORM component for Golang, one that possesses a simplistic nature and is thoughtfully designed with separate drivers. It was not until I stumbled upon this particular project that I realized its excellence. I must express my deepest gratitude for its existence. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This release adds the concept of a modifier.
What is a KSQL Modifier?
A KSQL modifier is a special tag you can add to any of the attributes of your struct to alter the behavior of KSQL when reading or writing that attribute into the database. To use it, it is necessary to add the name of the modifier on the
ksql
tag after a comma, e.g.:Before this release, the
json
modifier was the only one available in KSQL, and it would help the user by converting the attribute to JSON before writing to the database and back from JSON when reading from the database.Adding Custom Modifiers
This release improves on this idea of modifiers by making it possible for users to add their own user-created modifiers. This release also adds 4 new built-in modifiers so users can use out of the box, namely:
timeNowUTC
: It only works if on attributes of typetime.Time
and it sets this attribute totime.Now().UTC()
every time before insertions and updates. This modifier was created to be used onUpdatedAt
timestamp fields.timeNowUTC/skipUpdates
: Does the same as the above but only on insertions. This is useful forCreatedAt
fields where you only want them to be set once onInsert()
.skipUpdates
: Will ignore fields on updates.skipInserts
: Will ignore fields on inserts.Here is an example of how a
User
struct might look like using some of these modifiers:We also have plans on releasing some modifiers for saving
time.Time
instances as UNIX timestamps on the database in the future.Registering new Modifiers
Registering new modifiers is done by instantiating a struct like the below:
This registration should be performed inside your code before making any calls to the KSQL library. I recommend doing it inside a
init()
function since then it will run beforemain()
starts.This discussion was created from the release Add the concept of attribute modifiers.
Beta Was this translation helpful? Give feedback.
All reactions