We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I stumbled across the need to use the getcoltypes and getcolnames from luasql and thought the following function could live on dado:
-------------------------------------------------------------------------------- -- Retrieves types and order of columns -- @param self Dado Object. -- @param columns String with fields list. -- @param tabname String with table name. -- @param cond String with where-clause (and following SQL text). -- @param mode String indicating fetch mode (default == 'a'). -- @see dado.sql.select -- @return Table with the entire result set. function M.coltypes(self, columns, tabname, mode) mode = mode or "a" columns = columns or "*" local query = sql.select(columns, tabname, nil, "limit 1") local cur = self:cursor(query) local colorder = cur:getcolnames() local types = cur:getcoltypes() local t = {} if mode == "a" then for i,col in ipairs(colorder) do t[col] = types[i] end elseif mode == "n" then for i,col in ipairs(colorder) do t[i] = { col = v } end end return t end
Use case:
local rs = conn:coltypes("*", "user", "a") print(table.tostring(rs)) { id_user = "integer", admin = "bool" (...) } local rs = conn:coltypes("*", "user", "n") print(table.tostring(rs)) { [1] = { col = "id", type ="integer" }, [2] = { col = "admin", type = "bool" } (...) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I stumbled across the need to use the getcoltypes and getcolnames from luasql and thought the following function could live on dado:
Use case:
The text was updated successfully, but these errors were encountered: