[ref] move sql context to adaper pkg
Signed-off-by: Anton Nesterov <anton@demiurg.io>
This commit is contained in:
parent
fde44ce343
commit
b72e67badc
|
@ -1,4 +1,4 @@
|
||||||
package filters
|
package adapter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
11
pkg/adapter/go.mod
Normal file
11
pkg/adapter/go.mod
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
module l12.xyz/dal/adapter
|
||||||
|
|
||||||
|
go 1.22.6
|
||||||
|
|
||||||
|
replace l12.xyz/dal/utils v0.0.0 => ../utils
|
||||||
|
|
||||||
|
replace l12.xyz/dal/filters v0.0.0 => ../filters
|
||||||
|
|
||||||
|
require l12.xyz/dal/utils v0.0.0
|
||||||
|
|
||||||
|
require github.com/pkg/errors v0.9.1 // indirect
|
2
pkg/adapter/go.sum
Normal file
2
pkg/adapter/go.sum
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
10
pkg/adapter/types.go
Normal file
10
pkg/adapter/types.go
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package adapter
|
||||||
|
|
||||||
|
type CtxOpts map[string]string
|
||||||
|
|
||||||
|
type Context interface {
|
||||||
|
New(opts CtxOpts) Context
|
||||||
|
GetTableName() string
|
||||||
|
GetFieldName() string
|
||||||
|
NormalizeValue(interface{}) interface{}
|
||||||
|
}
|
|
@ -2,12 +2,10 @@ package dal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
filters "l12.xyz/dal/filters"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConvertFieldsBool(t *testing.T) {
|
func TestConvertFieldsBool(t *testing.T) {
|
||||||
ctx := filters.SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
FieldName: "test",
|
FieldName: "test",
|
||||||
}
|
}
|
||||||
|
@ -24,7 +22,7 @@ func TestConvertFieldsBool(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertFieldsInt(t *testing.T) {
|
func TestConvertFieldsInt(t *testing.T) {
|
||||||
ctx := filters.SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
FieldName: "test",
|
FieldName: "test",
|
||||||
}
|
}
|
||||||
|
@ -41,7 +39,7 @@ func TestConvertFieldsInt(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertFieldsStr(t *testing.T) {
|
func TestConvertFieldsStr(t *testing.T) {
|
||||||
ctx := filters.SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
FieldName: "test",
|
FieldName: "test",
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@ package dal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
f "l12.xyz/dal/filters"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConvertFind(t *testing.T) {
|
func TestConvertFind(t *testing.T) {
|
||||||
|
@ -13,7 +11,7 @@ func TestConvertFind(t *testing.T) {
|
||||||
"$gt": 1,
|
"$gt": 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := f.SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
}
|
}
|
||||||
result := CovertFind(ctx, find)
|
result := CovertFind(ctx, find)
|
||||||
|
@ -37,7 +35,7 @@ func TestConvertFindAnd(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := f.SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
}
|
}
|
||||||
result := CovertFind(ctx, find)
|
result := CovertFind(ctx, find)
|
||||||
|
@ -61,7 +59,7 @@ func TestConvertFindOr(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := f.SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
}
|
}
|
||||||
result := CovertFind(ctx, find)
|
result := CovertFind(ctx, find)
|
||||||
|
|
|
@ -3,12 +3,10 @@ package dal
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
filters "l12.xyz/dal/filters"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConvertInsert(t *testing.T) {
|
func TestConvertInsert(t *testing.T) {
|
||||||
ctx := filters.SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableName: "test",
|
TableName: "test",
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,11 @@ package dal
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
f "l12.xyz/dal/filters"
|
adapter "l12.xyz/dal/adapter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SQLiteContext = adapter.SQLiteContext
|
||||||
|
|
||||||
func TestJoin(t *testing.T) {
|
func TestJoin(t *testing.T) {
|
||||||
j := Join{
|
j := Join{
|
||||||
For: "artist a",
|
For: "artist a",
|
||||||
|
@ -14,7 +16,7 @@ func TestJoin(t *testing.T) {
|
||||||
},
|
},
|
||||||
As: "LEFT",
|
As: "LEFT",
|
||||||
}
|
}
|
||||||
ctx := f.SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
}
|
}
|
||||||
result := j.Convert(ctx)
|
result := j.Convert(ctx)
|
||||||
|
@ -34,7 +36,7 @@ func TestConvertJoin(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := f.SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
}
|
}
|
||||||
result := ConvertJoin(ctx, joins...)
|
result := ConvertJoin(ctx, joins...)
|
||||||
|
@ -51,7 +53,7 @@ func TestConvertMap(t *testing.T) {
|
||||||
joins := []interface{}{
|
joins := []interface{}{
|
||||||
Map{"$for": "artist a", "$do": Map{"a.impl": "t.impl"}, "$as": "LEFT"},
|
Map{"$for": "artist a", "$do": Map{"a.impl": "t.impl"}, "$as": "LEFT"},
|
||||||
}
|
}
|
||||||
ctx := f.SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
}
|
}
|
||||||
result := ConvertJoin(ctx, joins...)
|
result := ConvertJoin(ctx, joins...)
|
||||||
|
|
|
@ -11,3 +11,7 @@ require l12.xyz/dal/filters v0.0.0
|
||||||
require github.com/pkg/errors v0.9.1 // indirect
|
require github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
|
||||||
replace l12.xyz/dal/filters v0.0.0 => ../filters
|
replace l12.xyz/dal/filters v0.0.0 => ../filters
|
||||||
|
|
||||||
|
require l12.xyz/dal/adapter v0.0.0
|
||||||
|
|
||||||
|
replace l12.xyz/dal/adapter v0.0.0 => ../adapter
|
|
@ -1,6 +1,7 @@
|
||||||
package dal
|
package dal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
adapter "l12.xyz/dal/adapter"
|
||||||
filters "l12.xyz/dal/filters"
|
filters "l12.xyz/dal/filters"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,5 +11,5 @@ type Find = filters.Find
|
||||||
type Query = filters.Find
|
type Query = filters.Find
|
||||||
type Filter = filters.Filter
|
type Filter = filters.Filter
|
||||||
type Is = filters.Filter
|
type Is = filters.Filter
|
||||||
type Context = filters.Context
|
type Context = adapter.Context
|
||||||
type CtxOpts = filters.CtxOpts
|
type CtxOpts = adapter.CtxOpts
|
||||||
|
|
|
@ -7,3 +7,7 @@ require github.com/pkg/errors v0.9.1 // indirect
|
||||||
require l12.xyz/dal/utils v0.0.0
|
require l12.xyz/dal/utils v0.0.0
|
||||||
|
|
||||||
replace l12.xyz/dal/utils v0.0.0 => ../utils
|
replace l12.xyz/dal/utils v0.0.0 => ../utils
|
||||||
|
|
||||||
|
require l12.xyz/dal/adapter v0.0.0
|
||||||
|
|
||||||
|
replace l12.xyz/dal/adapter v0.0.0 => ../adapter
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
package filters
|
package filters
|
||||||
|
|
||||||
type CtxOpts map[string]string
|
import "l12.xyz/dal/adapter"
|
||||||
type Context interface {
|
|
||||||
New(opts CtxOpts) Context
|
type CtxOpts = adapter.CtxOpts
|
||||||
GetTableName() string
|
type Context = adapter.Context
|
||||||
GetFieldName() string
|
|
||||||
NormalizeValue(interface{}) interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type IFilter interface {
|
type IFilter interface {
|
||||||
ToSQLPart(ctx Context) string
|
ToSQLPart(ctx Context) string
|
||||||
|
|
|
@ -2,8 +2,12 @@ package filters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
adapter "l12.xyz/dal/adapter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SQLiteContext = adapter.SQLiteContext
|
||||||
|
|
||||||
func TestEq(t *testing.T) {
|
func TestEq(t *testing.T) {
|
||||||
ctx := SQLiteContext{
|
ctx := SQLiteContext{
|
||||||
TableAlias: "t",
|
TableAlias: "t",
|
||||||
|
|
Loading…
Reference in a new issue