diff --git a/internal/modifiers/attr_wrapper.go b/internal/modifiers/attr_wrapper.go index a6d277b..44fdae8 100644 --- a/internal/modifiers/attr_wrapper.go +++ b/internal/modifiers/attr_wrapper.go @@ -4,7 +4,7 @@ import ( "context" "database/sql/driver" - "github.com/vingarcia/ksql/kmodifiers" + "github.com/vingarcia/ksql/ksqlmodifiers" ) // AttrScanWrapper is the wrapper that allow us to intercept the Scan process @@ -17,8 +17,8 @@ type AttrScanWrapper struct { AttrPtr interface{} - ScanFn kmodifiers.AttrScanner - OpInfo kmodifiers.OpInfo + ScanFn ksqlmodifiers.AttrScanner + OpInfo ksqlmodifiers.OpInfo } // Scan implements the sql.Scanner interface @@ -36,8 +36,8 @@ type AttrValueWrapper struct { Attr interface{} - ValueFn kmodifiers.AttrValuer - OpInfo kmodifiers.OpInfo + ValueFn ksqlmodifiers.AttrValuer + OpInfo ksqlmodifiers.OpInfo } // Value implements the sql.Valuer interface diff --git a/internal/modifiers/attr_wrapper_test.go b/internal/modifiers/attr_wrapper_test.go index d712288..161820d 100644 --- a/internal/modifiers/attr_wrapper_test.go +++ b/internal/modifiers/attr_wrapper_test.go @@ -6,7 +6,7 @@ import ( "testing" tt "github.com/vingarcia/ksql/internal/testtools" - "github.com/vingarcia/ksql/kmodifiers" + "github.com/vingarcia/ksql/ksqlmodifiers" ) func TestAttrScanWrapper(t *testing.T) { @@ -16,7 +16,7 @@ func TestAttrScanWrapper(t *testing.T) { wrapper := AttrScanWrapper{ Ctx: ctx, AttrPtr: "fakeAttrPtr", - ScanFn: func(ctx context.Context, opInfo kmodifiers.OpInfo, attrPtr interface{}, dbValue interface{}) error { + ScanFn: func(ctx context.Context, opInfo ksqlmodifiers.OpInfo, attrPtr interface{}, dbValue interface{}) error { scanArgs = map[string]interface{}{ "opInfo": opInfo, "attrPtr": attrPtr, @@ -24,7 +24,7 @@ func TestAttrScanWrapper(t *testing.T) { } return errors.New("fakeScanErrMsg") }, - OpInfo: kmodifiers.OpInfo{ + OpInfo: ksqlmodifiers.OpInfo{ Method: "fakeMethod", DriverName: "fakeDriverName", }, @@ -33,7 +33,7 @@ func TestAttrScanWrapper(t *testing.T) { err := wrapper.Scan("fakeDbValue") tt.AssertErrContains(t, err, "fakeScanErrMsg") tt.AssertEqual(t, scanArgs, map[string]interface{}{ - "opInfo": kmodifiers.OpInfo{ + "opInfo": ksqlmodifiers.OpInfo{ Method: "fakeMethod", DriverName: "fakeDriverName", }, @@ -49,14 +49,14 @@ func TestAttrWrapper(t *testing.T) { wrapper := AttrValueWrapper{ Ctx: ctx, Attr: "fakeAttr", - ValueFn: func(ctx context.Context, opInfo kmodifiers.OpInfo, inputValue interface{}) (outputValue interface{}, _ error) { + ValueFn: func(ctx context.Context, opInfo ksqlmodifiers.OpInfo, inputValue interface{}) (outputValue interface{}, _ error) { valueArgs = map[string]interface{}{ "opInfo": opInfo, "inputValue": inputValue, } return "fakeOutputValue", errors.New("fakeValueErrMsg") }, - OpInfo: kmodifiers.OpInfo{ + OpInfo: ksqlmodifiers.OpInfo{ Method: "fakeMethod", DriverName: "fakeDriverName", }, @@ -65,7 +65,7 @@ func TestAttrWrapper(t *testing.T) { value, err := wrapper.Value() tt.AssertErrContains(t, err, "fakeValueErrMsg") tt.AssertEqual(t, valueArgs, map[string]interface{}{ - "opInfo": kmodifiers.OpInfo{ + "opInfo": ksqlmodifiers.OpInfo{ Method: "fakeMethod", DriverName: "fakeDriverName", }, diff --git a/internal/modifiers/global_modifiers.go b/internal/modifiers/global_modifiers.go index b77d986..0b04d62 100644 --- a/internal/modifiers/global_modifiers.go +++ b/internal/modifiers/global_modifiers.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/vingarcia/ksql/kmodifiers" + "github.com/vingarcia/ksql/ksqlmodifiers" ) // Here we keep all the registered modifiers @@ -13,7 +13,7 @@ var modifiers sync.Map func init() { // Here we expose the registration function in a public package, // so users can use it: - kmodifiers.RegisterAttrModifier = RegisterAttrModifier + ksqlmodifiers.RegisterAttrModifier = RegisterAttrModifier // These are the builtin modifiers: @@ -33,7 +33,7 @@ func init() { // RegisterAttrModifier allow users to add custom modifiers on startup // it is recommended to do this inside an init() function. -func RegisterAttrModifier(key string, modifier kmodifiers.AttrModifier) { +func RegisterAttrModifier(key string, modifier ksqlmodifiers.AttrModifier) { _, found := modifiers.Load(key) if found { panic(fmt.Errorf("KSQL: cannot register modifier '%s' name is already in use", key)) @@ -44,11 +44,11 @@ func RegisterAttrModifier(key string, modifier kmodifiers.AttrModifier) { // LoadGlobalModifier is used internally by KSQL to load // modifiers during runtime. -func LoadGlobalModifier(key string) (kmodifiers.AttrModifier, error) { +func LoadGlobalModifier(key string) (ksqlmodifiers.AttrModifier, error) { rawModifier, _ := modifiers.Load(key) - modifier, ok := rawModifier.(kmodifiers.AttrModifier) + modifier, ok := rawModifier.(ksqlmodifiers.AttrModifier) if !ok { - return kmodifiers.AttrModifier{}, fmt.Errorf("no modifier found with name '%s'", key) + return ksqlmodifiers.AttrModifier{}, fmt.Errorf("no modifier found with name '%s'", key) } return modifier, nil diff --git a/internal/modifiers/global_modifiers_test.go b/internal/modifiers/global_modifiers_test.go index 9f68368..0a367fb 100644 --- a/internal/modifiers/global_modifiers_test.go +++ b/internal/modifiers/global_modifiers_test.go @@ -4,15 +4,15 @@ import ( "testing" tt "github.com/vingarcia/ksql/internal/testtools" - "github.com/vingarcia/ksql/kmodifiers" + "github.com/vingarcia/ksql/ksqlmodifiers" ) func TestRegisterAttrModifier(t *testing.T) { t.Run("should register new modifiers correctly", func(t *testing.T) { - modifier1 := kmodifiers.AttrModifier{ + modifier1 := ksqlmodifiers.AttrModifier{ SkipOnUpdate: true, } - modifier2 := kmodifiers.AttrModifier{ + modifier2 := ksqlmodifiers.AttrModifier{ SkipOnInsert: true, } @@ -29,10 +29,10 @@ func TestRegisterAttrModifier(t *testing.T) { }) t.Run("should panic registering a modifier and the name already exists", func(t *testing.T) { - modifier1 := kmodifiers.AttrModifier{ + modifier1 := ksqlmodifiers.AttrModifier{ SkipOnUpdate: true, } - modifier2 := kmodifiers.AttrModifier{ + modifier2 := ksqlmodifiers.AttrModifier{ SkipOnInsert: true, } @@ -49,6 +49,6 @@ func TestRegisterAttrModifier(t *testing.T) { t.Run("should return an error when loading an inexistent modifier", func(t *testing.T) { mod, err := LoadGlobalModifier("nonExistentModifier") tt.AssertErrContains(t, err, "nonExistentModifier") - tt.AssertEqual(t, mod, kmodifiers.AttrModifier{}) + tt.AssertEqual(t, mod, ksqlmodifiers.AttrModifier{}) }) } diff --git a/internal/modifiers/json_modifier.go b/internal/modifiers/json_modifier.go index 0574bb7..ac5cc48 100644 --- a/internal/modifiers/json_modifier.go +++ b/internal/modifiers/json_modifier.go @@ -5,14 +5,14 @@ import ( "encoding/json" "fmt" - "github.com/vingarcia/ksql/kmodifiers" + "github.com/vingarcia/ksql/ksqlmodifiers" ) // This modifier serializes objects as JSON when // sending it to the database and decodes // them when receiving. -var jsonModifier = kmodifiers.AttrModifier{ - Scan: func(ctx context.Context, opInfo kmodifiers.OpInfo, attrPtr interface{}, dbValue interface{}) error { +var jsonModifier = ksqlmodifiers.AttrModifier{ + Scan: func(ctx context.Context, opInfo ksqlmodifiers.OpInfo, attrPtr interface{}, dbValue interface{}) error { if dbValue == nil { return nil } @@ -29,7 +29,7 @@ var jsonModifier = kmodifiers.AttrModifier{ return json.Unmarshal(rawJSON, attrPtr) }, - Value: func(ctx context.Context, opInfo kmodifiers.OpInfo, inputValue interface{}) (outputValue interface{}, _ error) { + Value: func(ctx context.Context, opInfo ksqlmodifiers.OpInfo, inputValue interface{}) (outputValue interface{}, _ error) { b, err := json.Marshal(inputValue) // SQL server uses the NVARCHAR type to store JSON and // it expects to receive strings not []byte, thus: diff --git a/internal/modifiers/json_modifier_test.go b/internal/modifiers/json_modifier_test.go index 110f440..fec35ee 100644 --- a/internal/modifiers/json_modifier_test.go +++ b/internal/modifiers/json_modifier_test.go @@ -5,7 +5,7 @@ import ( "testing" tt "github.com/vingarcia/ksql/internal/testtools" - "github.com/vingarcia/ksql/kmodifiers" + "github.com/vingarcia/ksql/ksqlmodifiers" ) func TestAttrScan(t *testing.T) { @@ -54,7 +54,7 @@ func TestAttrScan(t *testing.T) { fakeAttr := FakeAttr{ Foo: "notZeroValue", } - err := jsonModifier.Scan(ctx, kmodifiers.OpInfo{}, &fakeAttr, test.dbInput) + err := jsonModifier.Scan(ctx, ksqlmodifiers.OpInfo{}, &fakeAttr, test.dbInput) if test.expectErrToContain != nil { tt.AssertErrContains(t, err, test.expectErrToContain...) t.Skip() @@ -76,7 +76,7 @@ func TestAttrValue(t *testing.T) { tests := []struct { desc string dbInput interface{} - opInfoInput kmodifiers.OpInfo + opInfoInput ksqlmodifiers.OpInfo attrValue interface{} expectedOutput interface{} @@ -85,7 +85,7 @@ func TestAttrValue(t *testing.T) { { desc: "should return a byte array when the driver is not sqlserver", dbInput: []byte(`{"foo":"bar"}`), - opInfoInput: kmodifiers.OpInfo{ + opInfoInput: ksqlmodifiers.OpInfo{ DriverName: "notSQLServer", }, attrValue: FakeAttr{ @@ -98,7 +98,7 @@ func TestAttrValue(t *testing.T) { { desc: "should return a string when the driver is sqlserver", dbInput: []byte(`{"foo":"bar"}`), - opInfoInput: kmodifiers.OpInfo{ + opInfoInput: ksqlmodifiers.OpInfo{ DriverName: "sqlserver", }, attrValue: FakeAttr{ diff --git a/internal/modifiers/skip_modifiers.go b/internal/modifiers/skip_modifiers.go index 89d8ce7..27d3080 100644 --- a/internal/modifiers/skip_modifiers.go +++ b/internal/modifiers/skip_modifiers.go @@ -1,11 +1,11 @@ package modifiers -import "github.com/vingarcia/ksql/kmodifiers" +import "github.com/vingarcia/ksql/ksqlmodifiers" -var skipInsertsModifier = kmodifiers.AttrModifier{ +var skipInsertsModifier = ksqlmodifiers.AttrModifier{ SkipOnInsert: true, } -var skipUpdatesModifier = kmodifiers.AttrModifier{ +var skipUpdatesModifier = ksqlmodifiers.AttrModifier{ SkipOnUpdate: true, } diff --git a/internal/modifiers/time_modifiers.go b/internal/modifiers/time_modifiers.go index abbbc62..29774eb 100644 --- a/internal/modifiers/time_modifiers.go +++ b/internal/modifiers/time_modifiers.go @@ -4,21 +4,21 @@ import ( "context" "time" - "github.com/vingarcia/ksql/kmodifiers" + "github.com/vingarcia/ksql/ksqlmodifiers" ) // This one is useful for updatedAt timestamps -var timeNowUTCModifier = kmodifiers.AttrModifier{ - Value: func(ctx context.Context, opInfo kmodifiers.OpInfo, inputValue interface{}) (outputValue interface{}, _ error) { +var timeNowUTCModifier = ksqlmodifiers.AttrModifier{ + Value: func(ctx context.Context, opInfo ksqlmodifiers.OpInfo, inputValue interface{}) (outputValue interface{}, _ error) { return time.Now().UTC(), nil }, } // This one is useful for createdAt timestamps -var timeNowUTCSkipUpdatesModifier = kmodifiers.AttrModifier{ +var timeNowUTCSkipUpdatesModifier = ksqlmodifiers.AttrModifier{ SkipOnUpdate: true, - Value: func(ctx context.Context, opInfo kmodifiers.OpInfo, inputValue interface{}) (outputValue interface{}, _ error) { + Value: func(ctx context.Context, opInfo ksqlmodifiers.OpInfo, inputValue interface{}) (outputValue interface{}, _ error) { return time.Now().UTC(), nil }, } diff --git a/internal/structs/structs.go b/internal/structs/structs.go index b7ecdc0..fe62adb 100644 --- a/internal/structs/structs.go +++ b/internal/structs/structs.go @@ -7,7 +7,7 @@ import ( "sync" "github.com/vingarcia/ksql/internal/modifiers" - "github.com/vingarcia/ksql/kmodifiers" + "github.com/vingarcia/ksql/ksqlmodifiers" ) // StructInfo stores metainformation of the struct @@ -26,7 +26,7 @@ type FieldInfo struct { Name string Index int Valid bool - Modifier kmodifiers.AttrModifier + Modifier ksqlmodifiers.AttrModifier } // ByIndex returns either the *FieldInfo of a valid @@ -252,7 +252,7 @@ func getTagNames(t reflect.Type) (_ StructInfo, err error) { } tags := strings.Split(name, ",") - var modifier kmodifiers.AttrModifier + var modifier ksqlmodifiers.AttrModifier if len(tags) > 1 { name = tags[0] modifier, err = modifiers.LoadGlobalModifier(tags[1]) diff --git a/ksql.go b/ksql.go index e1f7555..114357b 100644 --- a/ksql.go +++ b/ksql.go @@ -12,7 +12,7 @@ import ( "github.com/vingarcia/ksql/internal/modifiers" "github.com/vingarcia/ksql/internal/structs" - "github.com/vingarcia/ksql/kmodifiers" + "github.com/vingarcia/ksql/ksqlmodifiers" "github.com/vingarcia/ksql/ksqltest" ) @@ -729,7 +729,7 @@ func buildInsertQuery( Ctx: ctx, Attr: recordValue, ValueFn: valueFn, - OpInfo: kmodifiers.OpInfo{ + OpInfo: ksqlmodifiers.OpInfo{ DriverName: dialect.DriverName(), Method: "Insert", }, @@ -858,7 +858,7 @@ func buildUpdateQuery( Ctx: ctx, Attr: recordValue, ValueFn: valueFn, - OpInfo: kmodifiers.OpInfo{ + OpInfo: ksqlmodifiers.OpInfo{ DriverName: dialect.DriverName(), Method: "Update", }, @@ -1064,7 +1064,7 @@ func getScanArgsForNestedStructs( Ctx: ctx, AttrPtr: valueScanner, ScanFn: fieldInfo.Modifier.Scan, - OpInfo: kmodifiers.OpInfo{ + OpInfo: ksqlmodifiers.OpInfo{ DriverName: dialect.DriverName(), // We will not differentiate between Query, QueryOne and QueryChunks // if we did this could lead users to make very strange modifiers @@ -1094,7 +1094,7 @@ func getScanArgsFromNames(ctx context.Context, dialect Dialect, names []string, Ctx: ctx, AttrPtr: valueScanner, ScanFn: fieldInfo.Modifier.Scan, - OpInfo: kmodifiers.OpInfo{ + OpInfo: ksqlmodifiers.OpInfo{ DriverName: dialect.DriverName(), // We will not differentiate between Query, QueryOne and QueryChunks // if we did this could lead users to make very strange modifiers diff --git a/kmodifiers/attr_modifier.go b/ksqlmodifiers/attr_modifier.go similarity index 98% rename from kmodifiers/attr_modifier.go rename to ksqlmodifiers/attr_modifier.go index 0f07838..ae18aee 100644 --- a/kmodifiers/attr_modifier.go +++ b/ksqlmodifiers/attr_modifier.go @@ -1,4 +1,4 @@ -package kmodifiers +package ksqlmodifiers import "context" diff --git a/kmodifiers/godoc.go b/ksqlmodifiers/godoc.go similarity index 90% rename from kmodifiers/godoc.go rename to ksqlmodifiers/godoc.go index 4d5366a..e591f53 100644 --- a/kmodifiers/godoc.go +++ b/ksqlmodifiers/godoc.go @@ -3,4 +3,4 @@ // // For understanding internal details of the code // please read the `internal/modifiers` package. -package kmodifiers +package ksqlmodifiers diff --git a/kmodifiers/register_new_modifier.go b/ksqlmodifiers/register_new_modifier.go similarity index 94% rename from kmodifiers/register_new_modifier.go rename to ksqlmodifiers/register_new_modifier.go index b909903..3f867f5 100644 --- a/kmodifiers/register_new_modifier.go +++ b/ksqlmodifiers/register_new_modifier.go @@ -1,4 +1,4 @@ -package kmodifiers +package ksqlmodifiers // RegisterAttrModifier allow users to add custom modifiers on startup // it is recommended to do this inside an init() function. diff --git a/test_adapters.go b/test_adapters.go index 7e485d3..331f03f 100644 --- a/test_adapters.go +++ b/test_adapters.go @@ -11,7 +11,7 @@ import ( "github.com/vingarcia/ksql/internal/modifiers" tt "github.com/vingarcia/ksql/internal/testtools" - "github.com/vingarcia/ksql/kmodifiers" + "github.com/vingarcia/ksql/ksqlmodifiers" "github.com/vingarcia/ksql/nullable" ) @@ -3336,7 +3336,7 @@ func getUserByID(db DBAdapter, dialect Dialect, result *user, id uint) error { Ctx: context.TODO(), AttrPtr: &result.Address, ScanFn: modifier.Scan, - OpInfo: kmodifiers.OpInfo{ + OpInfo: ksqlmodifiers.OpInfo{ DriverName: dialect.DriverName(), // We will not differentiate between Query, QueryOne and QueryChunks // if we did this could lead users to make very strange modifiers