forked from h22rana/jsonlogic2sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparameterized.go
More file actions
116 lines (101 loc) · 4.69 KB
/
Copy pathparameterized.go
File metadata and controls
116 lines (101 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package jsonlogic2sql
import (
tperrors "github.com/h22rana/jsonlogic2sql/internal/errors"
"github.com/h22rana/jsonlogic2sql/internal/params"
)
// QueryParam represents a single bind parameter collected during parameterized transpilation.
// Name is the stable identifier (e.g., "p1", "p2"), and Value is the Go-native value to bind.
type QueryParam = params.QueryParam
// TranspileParameterizedCondition converts a JSON Logic string to a SQL condition
// (without the WHERE keyword) with bind parameter placeholders.
func (t *Transpiler) TranspileParameterizedCondition(jsonLogic string) (string, []QueryParam, error) {
logic, err := decodeJSONLogic(jsonLogic)
if err != nil {
return "", nil, tperrors.NewInvalidJSON(err)
}
return t.parser.ParseConditionParameterized(logic)
}
// TranspileParameterizedConditionFromMap converts a pre-parsed JSON Logic map to
// a SQL condition (without the WHERE keyword) with bind parameter placeholders.
func (t *Transpiler) TranspileParameterizedConditionFromMap(logic map[string]interface{}) (string, []QueryParam, error) {
return t.parser.ParseConditionParameterized(logic)
}
// TranspileParameterizedConditionFromInterface converts any JSON Logic interface{}
// to a SQL condition (without the WHERE keyword) with bind parameter placeholders.
func (t *Transpiler) TranspileParameterizedConditionFromInterface(logic interface{}) (string, []QueryParam, error) {
return t.parser.ParseConditionParameterized(logic)
}
// TranspileParameterizedValue converts a JSON Logic string to a parameterized
// SQL value expression.
func (t *Transpiler) TranspileParameterizedValue(jsonLogic string) (string, []QueryParam, error) {
logic, err := decodeJSONLogic(jsonLogic)
if err != nil {
return "", nil, tperrors.NewInvalidJSON(err)
}
return t.parser.ParseValueParameterized(logic)
}
// TranspileParameterizedValueFromMap converts a pre-parsed JSON Logic map to a
// parameterized SQL value expression.
func (t *Transpiler) TranspileParameterizedValueFromMap(logic map[string]interface{}) (string, []QueryParam, error) {
return t.parser.ParseValueParameterized(logic)
}
// TranspileParameterizedValueFromInterface converts any JSON Logic interface{}
// to a parameterized SQL value expression.
func (t *Transpiler) TranspileParameterizedValueFromInterface(logic interface{}) (string, []QueryParam, error) {
return t.parser.ParseValueParameterized(logic)
}
// Package-level convenience functions.
// TranspileParameterizedCondition converts a JSON Logic string to a SQL condition
// with bind parameter placeholders.
func TranspileParameterizedCondition(d Dialect, schema *Schema, jsonLogic string) (string, []QueryParam, error) {
t, err := NewTranspiler(d, schema)
if err != nil {
return "", nil, err
}
return t.TranspileParameterizedCondition(jsonLogic)
}
// TranspileParameterizedConditionFromMap converts a pre-parsed JSON Logic map to
// a SQL condition (without the WHERE keyword) with bind parameter placeholders.
func TranspileParameterizedConditionFromMap(d Dialect, schema *Schema, logic map[string]interface{}) (string, []QueryParam, error) {
t, err := NewTranspiler(d, schema)
if err != nil {
return "", nil, err
}
return t.TranspileParameterizedConditionFromMap(logic)
}
// TranspileParameterizedConditionFromInterface converts any JSON Logic interface{}
// to a SQL condition (without the WHERE keyword) with bind parameter placeholders.
func TranspileParameterizedConditionFromInterface(d Dialect, schema *Schema, logic interface{}) (string, []QueryParam, error) {
t, err := NewTranspiler(d, schema)
if err != nil {
return "", nil, err
}
return t.TranspileParameterizedConditionFromInterface(logic)
}
// TranspileParameterizedValue converts a JSON Logic string to a parameterized
// SQL value expression.
func TranspileParameterizedValue(d Dialect, schema *Schema, jsonLogic string) (string, []QueryParam, error) {
t, err := NewTranspiler(d, schema)
if err != nil {
return "", nil, err
}
return t.TranspileParameterizedValue(jsonLogic)
}
// TranspileParameterizedValueFromMap converts a pre-parsed JSON Logic map to a
// parameterized SQL value expression.
func TranspileParameterizedValueFromMap(d Dialect, schema *Schema, logic map[string]interface{}) (string, []QueryParam, error) {
t, err := NewTranspiler(d, schema)
if err != nil {
return "", nil, err
}
return t.TranspileParameterizedValueFromMap(logic)
}
// TranspileParameterizedValueFromInterface converts any JSON Logic interface{}
// to a parameterized SQL value expression.
func TranspileParameterizedValueFromInterface(d Dialect, schema *Schema, logic interface{}) (string, []QueryParam, error) {
t, err := NewTranspiler(d, schema)
if err != nil {
return "", nil, err
}
return t.TranspileParameterizedValueFromInterface(logic)
}