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

Alter default behavior of 'cond' parameter in dado:select #3

Open
rousbound opened this issue Apr 22, 2024 · 0 comments
Open

Alter default behavior of 'cond' parameter in dado:select #3

rousbound opened this issue Apr 22, 2024 · 0 comments

Comments

@rousbound
Copy link

function M.select (self, columns, tabname, cond, extra, mode)
	if type(cond) == "table" then cond = sql.AND(cond) end -- <<<
	local stmt = sql.select (columns, tabname, cond, extra)
	local cur = self:assertexec (stmt)
	local tm = type (mode)
	local t
	local _mode = mode
	if tm == "table" then
		t = mode
		_mode = 'a'
	end
	return function ()
		-- This table must be created inside this function or it could
		-- make `selectall' to return the same row every time.
		if tm == "string" then
			t = {}
		end
		return cur:fetch (t, _mode)
	end, cur
end

Would it be desirable to have this shortcut to cut out some characters while writing dado functions?

So we could get this:

local usuario = conn:select( "*", "user", { id_user = id_user }, "order by name", "a" )

Instead of:

local usuario = conn:select( "*", "user", sql.AND{ id_user = id_user }, "order by name", "a" )
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

1 participant