jbochi / lua-resty-cassandra

Pure Lua Cassandra client using CQL binary protocol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support binding by name (key/value table)

thibaultcha opened this issue · comments

Currently binding is only possible with ordered values:

local ok, err = session:execute([[
  INSERT INTO users (name, age, user_id)
  VALUES (?, ?, ?)
]], {"John O'Reilly", 42, cassandra.uuid("1144bada-852c-11e3-89fb-e0b9a54a6d11")})

If I want to bind a query from a table representing my entity, such as:

local user = {
  name = "John O'Reilly",
  age = 42,
  user_id = cassandra.uuid("1144bada-852c-11e3-89fb-e0b9a54a6d11")
}

local ok, err = session:execute([[
  INSERT INTO users (name, age, user_id)
  VALUES (?, ?, ?)
]], user)

It won't be possible because user is not an ordered list corresponding to the order of the ? placeholders.

A very handy feature, proposed by the sqlite driver would be to bind values by name, such as:

local user = {
  name = "John O'Reilly",
  age = 42,
  user_id = cassandra.uuid("1144bada-852c-11e3-89fb-e0b9a54a6d11")
}

local ok, err = session:execute([[
  INSERT INTO users (name, age, user_id)
  VALUES (:name, :age, :user_id)
]], user)

Would such a feature be considered? Is it a limitation from Cassandra itself and if so, could simple string manipulation be considered?

That would be a great feature. The protocol allows this without string
manipulation by the client, but only in v3. We would need to support it
first (#22).

QUERY, EXECUTE and BATCH messages can now optionally provide the names

for the values of the query. As this feature is optionally enabled by
clients, implementing it is at the discretion of the client.
On Feb 2, 2015 9:56 PM, "thibaultCha" notifications@github.com wrote:

Currently binding is only possible with ordered values:

local ok, err = session:execute([[ INSERT INTO users (name, age, user_id) VALUES (?, ?, ?)]], {"John O'Reilly", 42, cassandra.uuid("1144bada-852c-11e3-89fb-e0b9a54a6d11")})

If I want to bind a query from a table representing my entity, such as:

local user = {
name = "John O'Reilly",
age = 42,
user_id = cassandra.uuid("1144bada-852c-11e3-89fb-e0b9a54a6d11")
}
local ok, err = session:execute([[ INSERT INTO users (name, age, user_id) VALUES (?, ?, ?)]], user)

It won't be possible because user is not an ordered list corresponding to
the order of the ? placeholders.

A very handy feature, proposed by the sqlite driver
http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki#stmt_bind_names
would be to bind values by name, such as:

local user = {
name = "John O'Reilly",
age = 42,
user_id = cassandra.uuid("1144bada-852c-11e3-89fb-e0b9a54a6d11")
}
local ok, err = session:execute([[ INSERT INTO users (name, age, user_id) VALUES (:name, :age, :user_id)]], user)

Would such a feature be considered? Is it a limitation from Cassandra
itself and if so, could simple string manipulation be considered?


Reply to this email directly or view it on GitHub
#28.