-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export const source = ` | ||
local func, err = load([[ | ||
local function _load() | ||
local dbAdmin = {} | ||
dbAdmin.__index = dbAdmin | ||
-- Function to create a new database explorer instance | ||
function dbAdmin.new(db) | ||
local self = setmetatable({}, dbAdmin) | ||
self.db = db | ||
return self | ||
end | ||
-- Function to list all tables in the database | ||
function dbAdmin:tables() | ||
local tables = {} | ||
for row in self.db:nrows("SELECT name FROM sqlite_master WHERE type='table';") do | ||
table.insert(tables, row.name) | ||
end | ||
return tables | ||
end | ||
-- Function to get the record count of a table | ||
function dbAdmin:count(tableName) | ||
local count_query = string.format("SELECT COUNT(*) AS count FROM %s;", tableName) | ||
for row in self.db:nrows(count_query) do | ||
return row.count | ||
end | ||
end | ||
-- Function to execute a given SQL query | ||
function dbAdmin:exec(sql) | ||
local results = {} | ||
for row in self.db:nrows(sql) do | ||
table.insert(results, row) | ||
end | ||
return results | ||
end | ||
return dbAdmin | ||
end | ||
_G.package.loaded["DbAdmin"] = _load() | ||
]]) | ||
if not func then | ||
print(err) | ||
error("Error compiling load function: ") | ||
end | ||
func() | ||
print("Loaded DbAdmin module") | ||
` |