Giter Club home page Giter Club logo

Comments (3)

pingginp avatar pingginp commented on July 18, 2024

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.

pingginp avatar pingginp commented on July 18, 2024

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.

pingginp avatar pingginp commented on July 18, 2024

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, add Set{{Type1}}{{Type2}}MapValue(col, key {{type1}}, value {{type2}}
    • in Context methods, add the impl method with same name and call setMap
  • run make cqlc/columns.go to generate using column_generator.go
  • add setMap and use []interface{}{key, value} as Value for binding, set type to MapType and op to SetByKey
  • 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.