Comments (3)
the main challenge is map requires a column name and two value, so we will have two ?
in query instead of just one ...
Although AppendStringSlice has values, it used for binding as value, not in query, only col is used in query
func (c *Context) AppendStringSlice(col StringSliceColumn, values ...string) SetValueStep {
appendList(c, col, values)
return c
}
SetStringStringMapValue(col StringStringMapColumn, key string, value string) SetValueStep
setFragments[i] = fmt.Sprintf("%s [?] = ?", col)
from cqlc.
it seems multiple ?
is already handled in binding due to WHERE fo IN (?,?,?)
func (c *Context) Prepare(s *gocql.Session) (*gocql.Query, error) {
// The reason why this is so dynamic is because of WHERE foo IN (?,?,?) clauses
// The factoring for an IN clause is bad, since we are storing an array into the value
// and using reflection to dig it out again
// This should be more strongly typed
placeHolders := make([]interface{}, 0)
for _, cond := range c.Conditions {
v := cond.Binding.Value
switch reflect.TypeOf(v).Kind() {
case reflect.Slice:
{
s := reflect.ValueOf(v)
for i := 0; i < s.Len(); i++ {
placeHolders = append(placeHolders, s.Index(i).Interface())
}
}
case reflect.Array:
{
// Not really happy about having to special case UUIDs
// but this works for now
if val, ok := v.(gocql.UUID); ok {
placeHolders = append(placeHolders, val.Bytes())
} else {
return nil, bindingErrorf("Cannot bind component: %+v (type: %s)", v, reflect.TypeOf(v))
}
}
default:
{
placeHolders = append(placeHolders, &v)
}
}
}
}
from cqlc.
summarize what need to be done in order to get this work (previous commit already works, need to tweak the test and clean up code)
Actually it's all just runtime ....
- in
tmpl/columns.tmpl
- in
SetStepValue
interface, addSet{{Type1}}{{Type2}}MapValue(col, key {{type1}}, value {{type2}}
- in
Context
methods, add the impl method with same name and callsetMap
- in
- run
make cqlc/columns.go
to generate usingcolumn_generator.go
- add
setMap
and use[]interface{}{key, value}
asValue
for binding, set type to MapType and op toSetByKey
- in
renderUpdate
, use%s[?] = ?
where%s
is from col
BuildStatement
, flatten binding, (copy from Prepare), former is used by Exec (update & insert) and latter is used by Fetch (select)
- NOTE: we added new struct
KeyValue
to avoid flatten slice value that should be kept as slice - in old code, they were using
&v
for placeholder, it's pointer to interface, I don't know why it didn't trigger error, because gocql traverse ptr until it's a value?
from cqlc.
Related Issues (10)
- [dep] Lock version of dependencies HOT 1
- [test] Enable Travis and local test
- [gen] Remove go-bindata
- [test] Can not connect to Cassandra container from host on Mac
- [gen] Does not work with C*3
- [gen] Remove log.Fatal and return error in generated code
- [dep] Init support with go mod
- [dep] Make logrus optional by making it an interface
- [runtime] Support if in delete statement HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cqlc.