Updated Modifiers (markdown)

Vinícius Garcia 2022-12-04 17:52:14 -03:00
parent 4f35935d1d
commit 88a3fc32c6

@ -9,7 +9,22 @@ A KSQL modifier is a special tag you can add to any of the attributes of your st
KSQL comes with a few built-in Modifiers and an API for creating your own modifiers if necessary. KSQL comes with a few built-in Modifiers and an API for creating your own modifiers if necessary.
These will be discussed in more detail in the next sections. These will be discussed in more detail in the next sections.
Applying a Modifier to a struct attribute will cause KSQL to use this modifier when Inserting, Updating and Querying that field. Here is an example of how a `User` struct might look like when using some of these modifiers:
```golang
type User struct {
ID uint `ksql:"id"`
Name string `ksql:"name"`
Age int `ksql:"age"`
Address Address `ksql:"address,json"`
UpdatedAt time.Time `ksql:"updated_at,timeNowUTC"`
CreatedAt time.Time `ksql:"created_at,timeNowUTC/skipUpdates"`
}
```
Applying a Modifier to a struct attribute will cause KSQL to use this modifier when Inserting, Updating, and Querying that field.
A Modifier can therefore be used for: A Modifier can therefore be used for:
@ -31,21 +46,6 @@ Modifiers improve on the `Valuer`/`Scanner` feature provided by the standard lib
- `skipUpdates`: Will ignore fields on updates. - `skipUpdates`: Will ignore fields on updates.
- `skipInserts`: Will ignore fields on inserts. - `skipInserts`: Will ignore fields on inserts.
Here is an example of how a `User` struct might look like using some of these modifiers:
```golang
type user struct {
ID uint `ksql:"id"`
Name string `ksql:"name"`
Age int `ksql:"age"`
Address Address `ksql:"address,json"`
UpdatedAt time.Time `ksql:"updated_at,timeNowUTC"`
CreatedAt time.Time `ksql:"created_at,timeNowUTC/skipUpdates"`
}
```
### Registering new Modifiers ### Registering new Modifiers
Registering a new Modifier is simple: Describe it using an instance of `ksqlmodifiers.AttrModifier` and register it on KSQL by calling the global function: `ksqlmodifiers.RegisterAttrModifier` as illustrated below: Registering a new Modifier is simple: Describe it using an instance of `ksqlmodifiers.AttrModifier` and register it on KSQL by calling the global function: `ksqlmodifiers.RegisterAttrModifier` as illustrated below: