Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support binding by name (key/value table) #28

Open
thibaultcha opened this issue Feb 2, 2015 · 1 comment
Open

Support binding by name (key/value table) #28

thibaultcha opened this issue Feb 2, 2015 · 1 comment

Comments

@thibaultcha
Copy link
Contributor

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?

@jbochi
Copy link
Owner

jbochi commented Feb 3, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants