Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions drivers/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ import (
"github.com/pseudomuto/where"
)

var supportsFeatures = []string{
"ARRAY",
"FINAL",
"GLOBAL",
"ILIKE",
"JSON",
"PREWHERE",
"SAMPLE",
"TUPLE",
"WITH",
}
var (
supportedFeatures = []string{
"ARRAY",
"FINAL",
"GLOBAL",
"ILIKE",
"JSON",
"PREWHERE",
"SAMPLE",
"TUPLE",
"WITH",
}

supportedOperations = []string{
"=", "!=", "<>", "<", ">", "<=", ">=",
"LIKE", "NOT LIKE", "ILIKE", "NOT ILIKE",
"IN", "NOT IN",
"IS NULL", "IS NOT NULL",
"BETWEEN", "NOT BETWEEN",
}
)

type (
// ClickHouseDriver implements the where.Driver interface for ClickHouse databases.
Expand Down Expand Up @@ -87,24 +97,15 @@ func (d *ClickHouseDriver) Keywords() []string {

func (d *ClickHouseDriver) TranslateOperator(op string) (string, bool) {
upperOp := strings.ToUpper(op)
switch upperOp {
case "=", "!=", "<>", "<", ">", "<=", ">=":
return op, true
case "LIKE", "NOT LIKE", "ILIKE", "NOT ILIKE":
if slices.Contains(supportedOperations, upperOp) {
return upperOp, true
case "IN", "NOT IN":
return upperOp, true
case "IS NULL", "IS NOT NULL":
return upperOp, true
case "BETWEEN", "NOT BETWEEN":
return upperOp, true
default:
return "", false
}

return "", false
}

func (d *ClickHouseDriver) SupportsFeature(feature string) bool {
return slices.Contains(supportsFeatures, strings.ToUpper(feature))
return slices.Contains(supportedFeatures, strings.ToUpper(feature))
}

func init() {
Expand Down
47 changes: 24 additions & 23 deletions drivers/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ import (
"github.com/pseudomuto/where"
)

var supportedFeatures = []string{
"CTE",
"FULLTEXT",
"JSON",
"PARTITION",
"SPATIAL",
}
var (
supportedFeatures = []string{
"CTE",
"FULLTEXT",
"JSON",
"PARTITION",
"SPATIAL",
}

supportedOperations = []string{
"=", "!=", "<>", "<", ">", "<=", ">=",
"LIKE", "NOT LIKE",
"IN", "NOT IN",
"IS NULL", "IS NOT NULL",
"BETWEEN", "NOT BETWEEN",
}
)

type (
// MySQLDriver implements the where.Driver interface for MySQL and MariaDB databases.
Expand Down Expand Up @@ -83,24 +93,15 @@ func (d *MySQLDriver) Keywords() []string {

func (d *MySQLDriver) TranslateOperator(op string) (string, bool) {
upperOp := strings.ToUpper(op)
switch upperOp {
case "=", "!=", "<>", "<", ">", "<=", ">=":
return op, true
case "LIKE", "NOT LIKE":
return upperOp, true
case "ILIKE":
return "LIKE", true
case "NOT ILIKE":
return "NOT LIKE", true
case "IN", "NOT IN":
if slices.Contains(supportedOperations, upperOp) {
return upperOp, true
case "IS NULL", "IS NOT NULL":
return upperOp, true
case "BETWEEN", "NOT BETWEEN":
return upperOp, true
default:
return "", false
}

if upperOp == "ILIKE" || upperOp == "NOT ILIKE" {
return strings.Replace(upperOp, "ILIKE", "LIKE", 1), true
}

return "", false
}

func (d *MySQLDriver) SupportsFeature(feature string) bool {
Expand Down
43 changes: 22 additions & 21 deletions drivers/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ import (
"github.com/pseudomuto/where"
)

var supportedFeatures = []string{
"ARRAY",
"CTE",
"ILIKE",
"JSON",
"JSONB",
"RETURNING",
"WINDOW",
}
var (
supportedFeatures = []string{
"ARRAY",
"CTE",
"ILIKE",
"JSON",
"JSONB",
"RETURNING",
"WINDOW",
}

supportedOperations = []string{
"=", "!=", "<>", "<", ">", "<=", ">=",
"LIKE", "NOT LIKE", "ILIKE", "NOT ILIKE",
"IN", "NOT IN",
"IS NULL", "IS NOT NULL",
"BETWEEN", "NOT BETWEEN",
}
)

type (
// PostgreSQLDriver implements the where.Driver interface for PostgreSQL databases.
Expand Down Expand Up @@ -85,20 +95,11 @@ func (d *PostgreSQLDriver) Keywords() []string {

func (d *PostgreSQLDriver) TranslateOperator(op string) (string, bool) {
upperOp := strings.ToUpper(op)
switch upperOp {
case "=", "!=", "<>", "<", ">", "<=", ">=":
return op, true
case "LIKE", "NOT LIKE", "ILIKE", "NOT ILIKE":
if slices.Contains(supportedOperations, upperOp) {
return upperOp, true
case "IN", "NOT IN":
return upperOp, true
case "IS NULL", "IS NOT NULL":
return upperOp, true
case "BETWEEN", "NOT BETWEEN":
return upperOp, true
default:
return "", false
}

return "", false
}

func (d *PostgreSQLDriver) SupportsFeature(feature string) bool {
Expand Down
Loading