-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
klarysz
committed
Aug 15, 2022
1 parent
6243935
commit e4c7859
Showing
9 changed files
with
234 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
parameters: | ||
- assumed: false | ||
datatype: int | ||
id: ID | ||
kind: query | ||
name: id | ||
required: false | ||
- assumed: false | ||
datatype: string | ||
id: quantity | ||
kind: path | ||
name: quantity | ||
required: true | ||
- datatype: int | ||
id: ID | ||
kind: query | ||
name: id | ||
required: false | ||
- datatype: string | ||
id: quantity | ||
kind: path | ||
name: quantity | ||
required: true | ||
source: |- | ||
SELECT *, ( | ||
SELECT abc | ||
FROM T2 | ||
WHERE 1=2 | ||
) as abc FROM T1 | ||
WHERE 1=1 | ||
#if($Has.ID) | ||
AND ID = $ID | ||
#end | ||
#if($Has.quantity) | ||
AND quantity = $quantity | ||
#end | ||
SELECT *, ( | ||
SELECT abc | ||
FROM T2 | ||
WHERE 1=2 | ||
) as abc FROM T1 | ||
WHERE 1=1 | ||
#if($Has.ID) | ||
AND ID = $ID | ||
#end | ||
#if($Has.quantity) | ||
AND quantity = $quantity | ||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
parameters: | ||
- assumed: false | ||
datatype: int | ||
id: ID | ||
kind: query | ||
name: id | ||
required: false | ||
- assumed: true | ||
datatype: string | ||
id: quantity | ||
kind: query | ||
name: quantity | ||
required: false | ||
typer: | ||
columnname: quantity | ||
- datatype: int | ||
id: ID | ||
kind: query | ||
name: id | ||
required: false | ||
- assumed: true | ||
datatype: string | ||
id: quantity | ||
kind: query | ||
name: quantity | ||
required: false | ||
typer: | ||
columnname: quantity | ||
source: | | ||
SELECT *, ( | ||
SELECT abc | ||
FROM T2 | ||
WHERE 1=2 | ||
) as abc FROM T1 | ||
WHERE 1=1 | ||
#if($Has.ID) | ||
AND ID = $ID | ||
#end | ||
#if($Has.quantity) | ||
AND quantity = $quantity | ||
AND quantity = $Unsafe.quantity | ||
#end | ||
SELECT *, ( | ||
SELECT abc | ||
FROM T2 | ||
WHERE 1=2 | ||
) as abc FROM T1 | ||
WHERE 1=1 | ||
#if($Has.ID) | ||
AND ID = $ID | ||
#end | ||
#if($Has.quantity) | ||
AND quantity = $quantity | ||
AND quantity = $Unsafe.quantity | ||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,42 @@ | ||
parameters: | ||
- assumed: false | ||
datatype: int | ||
id: ID | ||
kind: query | ||
name: id | ||
required: false | ||
- assumed: true | ||
datatype: string | ||
id: quantity | ||
kind: query | ||
name: quantity | ||
required: false | ||
typer: | ||
columnname: quantity | ||
- datatype: int | ||
id: ID | ||
kind: query | ||
name: id | ||
required: false | ||
- assumed: true | ||
cardinality: Many | ||
datatype: string | ||
id: Columns | ||
kind: query | ||
multi: true | ||
name: Columns | ||
required: false | ||
- assumed: true | ||
datatype: string | ||
id: quantity | ||
kind: query | ||
name: quantity | ||
required: false | ||
typer: | ||
columnname: quantity | ||
source: | | ||
SELECT *, ( | ||
SELECT abc | ||
FROM T2 | ||
WHERE 1=2 | ||
) as abc FROM T1 | ||
WHERE 1=1 | ||
#set($valueSet = 123) | ||
#if($Has.ID) | ||
AND ID = $ID | ||
#end | ||
#foreach($column in $Columns) | ||
$column.Id | ||
#end | ||
#if($Has.quantity) | ||
AND quantity = $quantity | ||
AND quantity = $Unsafe.quantity | ||
#end | ||
SELECT *, ( | ||
SELECT abc | ||
FROM T2 | ||
WHERE 1=2 | ||
) as abc FROM T1 | ||
WHERE 1=1 | ||
#set($valueSet = 123) | ||
#if($Has.ID) | ||
AND ID = $ID | ||
#end | ||
#foreach($column in $Columns) | ||
$column.Id | ||
#end | ||
#if($Has.quantity) | ||
AND quantity = $quantity | ||
AND quantity = $Unsafe.quantity | ||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
parameters: | ||
- assumed: true | ||
datatype: string | ||
id: ID | ||
kind: query | ||
name: ID | ||
required: false | ||
- assumed: true | ||
datatype: string | ||
id: quantity | ||
kind: query | ||
name: quantity | ||
required: false | ||
typer: | ||
columnname: quantity | ||
- assumed: true | ||
datatype: string | ||
id: ID | ||
kind: query | ||
name: ID | ||
required: false | ||
- assumed: true | ||
cardinality: Many | ||
datatype: string | ||
id: Columns | ||
kind: query | ||
multi: true | ||
name: Columns | ||
required: false | ||
- assumed: true | ||
datatype: string | ||
id: quantity | ||
kind: query | ||
name: quantity | ||
required: false | ||
typer: | ||
columnname: quantity | ||
source: | | ||
SELECT *, ( | ||
SELECT abc | ||
FROM T2 | ||
WHERE 1=2 | ||
) as abc FROM T1 | ||
WHERE 1=1 | ||
#set($valueSet = 123) | ||
#if($Has.ID) | ||
AND ID = 10 | ||
#end | ||
#foreach($column in $Columns) | ||
$column.Id | ||
#end | ||
#if($Has.quantity) | ||
AND quantity = $quantity | ||
AND quantity = $Unsafe.quantity | ||
#end | ||
SELECT *, ( | ||
SELECT abc | ||
FROM T2 | ||
WHERE 1=2 | ||
) as abc FROM T1 | ||
WHERE 1=1 | ||
#set($valueSet = 123) | ||
#if($Has.ID) | ||
AND ID = 10 | ||
#end | ||
#foreach($column in $Columns) | ||
$column.Id | ||
#end | ||
#if($Has.quantity) | ||
AND quantity = $quantity | ||
AND quantity = $Unsafe.quantity | ||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,40 @@ | ||
parameters: | ||
- assumed: true | ||
datatype: string | ||
id: ID | ||
kind: query | ||
name: ID | ||
required: false | ||
- assumed: false | ||
datatype: time.Time | ||
id: quantity | ||
kind: query | ||
name: quantity | ||
required: false | ||
- assumed: true | ||
datatype: string | ||
id: ID | ||
kind: query | ||
name: ID | ||
required: false | ||
- assumed: true | ||
cardinality: Many | ||
datatype: string | ||
id: Columns | ||
kind: query | ||
multi: true | ||
name: Columns | ||
required: false | ||
- datatype: time.Time | ||
id: quantity | ||
kind: query | ||
name: quantity | ||
required: false | ||
source: | | ||
SELECT *, ( | ||
SELECT abc | ||
FROM T2 | ||
WHERE 1=2 | ||
) as abc FROM T1 | ||
WHERE 1=1 | ||
#set($valueSet = 123) | ||
#if($Has.ID) | ||
AND ID = 10 | ||
#end | ||
#foreach($column in $Columns) | ||
$column.Id | ||
#end | ||
#if($Has.quantity) | ||
AND quantity = $quantity /* {"DataType": "time.Time"} */ | ||
AND quantity = $Unsafe.quantity | ||
#end | ||
SELECT *, ( | ||
SELECT abc | ||
FROM T2 | ||
WHERE 1=2 | ||
) as abc FROM T1 | ||
WHERE 1=1 | ||
#set($valueSet = 123) | ||
#if($Has.ID) | ||
AND ID = 10 | ||
#end | ||
#foreach($column in $Columns) | ||
$column.Id | ||
#end | ||
#if($Has.quantity) | ||
AND quantity = $quantity /* {"DataType": "time.Time"} */ | ||
AND quantity = $Unsafe.quantity | ||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package logger | ||
|
||
import ( | ||
"fmt" | ||
"github.com/viant/velty/est" | ||
"github.com/viant/velty/est/op" | ||
"github.com/viant/xunsafe" | ||
"reflect" | ||
) | ||
|
||
var stringType = reflect.TypeOf("") | ||
|
||
type Printer struct { | ||
} | ||
|
||
func (p Printer) Discover(aFunc interface{}) (func(operands []*op.Operand, state *est.State) (interface{}, error), reflect.Type, bool) { | ||
switch actual := aFunc.(type) { | ||
case func(_ Printer, args ...interface{}) string: | ||
return func(operands []*op.Operand, state *est.State) (interface{}, error) { | ||
return actual(p, p.asInterfaces(operands, state)), nil | ||
}, stringType, true | ||
|
||
case func(_ Printer, message string, args ...interface{}) string: | ||
return func(operands []*op.Operand, state *est.State) (interface{}, error) { | ||
if len(operands) < 1 { | ||
return nil, fmt.Errorf("expected to get 1 or more arguments but got %v", len(operands)) | ||
} | ||
|
||
format := *(*string)(operands[0].Exec(state)) | ||
args := p.asInterfaces(operands[1:], state) | ||
|
||
return actual(p, format, args...), nil | ||
}, stringType, true | ||
|
||
} | ||
|
||
return nil, nil, false | ||
} | ||
|
||
func (p Printer) asInterfaces(operands []*op.Operand, state *est.State) []interface{} { | ||
args := make([]interface{}, len(operands)) | ||
|
||
for i, operand := range operands { | ||
value := reflect.New(operand.Type).Elem().Interface() | ||
xunsafe.Copy(xunsafe.AsPointer(value), operand.Exec(state), int(operand.Type.Size())) | ||
args[i] = value | ||
} | ||
|
||
return args | ||
} | ||
|
||
func (p Printer) Println(args ...interface{}) string { | ||
fmt.Println(args...) | ||
return "" | ||
} | ||
|
||
func (p Printer) Printf(format string, args ...interface{}) string { | ||
fmt.Printf(format, args...) | ||
return "" | ||
} |
Oops, something went wrong.