Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
acf-db
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ACF
acf-db
Commits
962f455c
Commit
962f455c
authored
Jun 29, 2014
by
Ted Trask
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow model functions to accept function or db reference
parent
2e9893a0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
11 deletions
+39
-11
dbmodelfunctions.lua
dbmodelfunctions.lua
+39
-11
No files found.
dbmodelfunctions.lua
View file @
962f455c
...
...
@@ -2,10 +2,14 @@ local mymodule = {}
-- Helper library for model functions for viewing and editing database entries
-- Relies heavily on the acf-lib/db.lua library (db object passed into each function)
function
mymodule
.
list_databases
(
db
,
self
,
clientdata
)
function
mymodule
.
list_databases
(
db
ase
,
self
,
clientdata
)
local
retval
=
{}
local
errtxt
local
res
,
err
=
pcall
(
function
()
local
db
=
dbase
if
type
(
dbase
)
==
"function"
then
db
=
dbase
()
end
retval
=
db
.
listdatabases
()
end
)
if
not
res
and
err
then
...
...
@@ -15,10 +19,14 @@ function mymodule.list_databases(db, self, clientdata)
return
cfe
({
type
=
"list"
,
value
=
retval
,
label
=
"List of Databases"
,
errtxt
=
errtxt
})
end
function
mymodule
.
list_tables
(
db
,
self
,
clientdata
)
function
mymodule
.
list_tables
(
db
ase
,
self
,
clientdata
)
local
retval
=
{}
local
errtxt
local
res
,
err
=
pcall
(
function
()
local
db
=
dbase
if
type
(
dbase
)
==
"function"
then
db
=
dbase
()
end
local
connected
=
db
.
databaseconnect
()
retval
=
db
.
listtables
()
if
connected
then
db
.
databasedisconnect
()
end
...
...
@@ -30,7 +38,7 @@ function mymodule.list_tables(db, self, clientdata)
return
cfe
({
type
=
"list"
,
value
=
retval
,
label
=
"List of Database Tables"
,
errtxt
=
errtxt
})
end
function
mymodule
.
list_table_entries
(
db
,
self
,
clientdata
)
function
mymodule
.
list_table_entries
(
db
ase
,
self
,
clientdata
)
local
table
=
clientdata
.
table
local
retval
=
{}
retval
.
table
=
cfe
({
value
=
table
or
""
,
label
=
"Table"
})
...
...
@@ -38,6 +46,10 @@ function mymodule.list_table_entries(db, self, clientdata)
retval
.
entries
=
cfe
({
type
=
"structure"
,
value
=
{},
label
=
"List of Database Entries"
})
local
errtxt
local
res
,
err
=
pcall
(
function
()
local
db
=
dbase
if
type
(
dbase
)
==
"function"
then
db
=
dbase
()
end
local
connected
=
db
.
databaseconnect
()
local
tables
=
db
.
listtables
()
retval
.
table
.
errtxt
=
"Table does not exist"
...
...
@@ -59,12 +71,16 @@ function mymodule.list_table_entries(db, self, clientdata)
return
cfe
({
type
=
"group"
,
value
=
retval
,
label
=
"Database Table Entries"
,
errtxt
=
errtxt
})
end
function
mymodule
.
get_new_table_entry
(
db
,
self
,
clientdata
)
function
mymodule
.
get_new_table_entry
(
db
ase
,
self
,
clientdata
)
local
retval
=
{}
retval
.
table
=
cfe
({
value
=
clientdata
.
table
or
""
,
label
=
"Table"
,
errtxt
=
"Table does not exist"
,
readonly
=
true
,
seq
=
0
})
local
errtxt
=
"Table does not exist"
if
clientdata
.
table
and
clientdata
.
table
~=
""
then
local
res
,
err
=
pcall
(
function
()
local
db
=
dbase
if
type
(
dbase
)
==
"function"
then
db
=
dbase
()
end
local
connected
=
db
.
databaseconnect
()
local
tables
=
db
.
listtables
()
for
i
,
t
in
ipairs
(
tables
)
do
...
...
@@ -93,11 +109,15 @@ function mymodule.get_new_table_entry(db, self, clientdata)
return
cfe
({
type
=
"group"
,
value
=
retval
,
label
=
"Database Table Entry"
,
errtxt
=
errtxt
})
end
function
mymodule
.
get_table_entry
(
db
,
self
,
clientdata
)
local
retval
=
mymodule
.
get_new_table_entry
(
db
,
self
,
clientdata
)
function
mymodule
.
get_table_entry
(
db
ase
,
self
,
clientdata
)
local
retval
=
mymodule
.
get_new_table_entry
(
db
ase
,
self
,
clientdata
)
if
not
retval
.
value
.
table
.
errtxt
and
retval
.
value
.
id
then
retval
.
value
.
id
.
type
=
"text"
local
res
,
err
=
pcall
(
function
()
local
db
=
dbase
if
type
(
dbase
)
==
"function"
then
db
=
dbase
()
end
local
connected
=
db
.
databaseconnect
()
retval
.
errtxt
=
"Entry does not exist"
if
retval
.
value
.
id
then
...
...
@@ -127,11 +147,11 @@ function mymodule.get_table_entry(db, self, clientdata)
return
retval
end
function
mymodule
.
create_table_entry
(
db
,
self
,
entry
,
action
)
return
mymodule
.
update_table_entry
(
db
,
self
,
entry
,
action
,
true
)
function
mymodule
.
create_table_entry
(
db
ase
,
self
,
entry
,
action
)
return
mymodule
.
update_table_entry
(
db
ase
,
self
,
entry
,
action
,
true
)
end
function
mymodule
.
update_table_entry
(
db
,
self
,
entry
,
action
,
create
)
function
mymodule
.
update_table_entry
(
db
ase
,
self
,
entry
,
action
,
create
)
local
success
=
true
local
errtxt
-- Validate the settings
...
...
@@ -150,6 +170,10 @@ function mymodule.update_table_entry(db, self, entry, action, create)
end
if
success
then
local
res
,
err
=
pcall
(
function
()
local
db
=
dbase
if
type
(
dbase
)
==
"function"
then
db
=
dbase
()
end
local
connected
=
db
.
databaseconnect
()
local
tables
=
db
.
listtables
()
success
=
false
...
...
@@ -203,14 +227,14 @@ function mymodule.update_table_entry(db, self, entry, action, create)
return
entry
end
function
mymodule
.
get_delete_table_entry
(
db
,
self
,
clientdata
)
function
mymodule
.
get_delete_table_entry
(
db
ase
,
self
,
clientdata
)
local
retval
=
{}
retval
.
table
=
cfe
({
value
=
clientdata
.
table
or
""
,
label
=
"Table"
,
seq
=
0
})
retval
.
id
=
cfe
({
value
=
clientdata
.
id
or
""
,
label
=
"ID"
,
seq
=
1
})
return
cfe
({
type
=
"group"
,
value
=
retval
,
label
=
"Delete Database Table Entry"
})
end
function
mymodule
.
delete_table_entry
(
db
,
self
,
entry
)
function
mymodule
.
delete_table_entry
(
db
ase
,
self
,
entry
)
entry
.
errtxt
=
"Failed to delete table entry"
if
entry
.
value
.
table
.
value
==
""
then
entry
.
value
.
table
.
errtxt
=
"Invalid table"
...
...
@@ -218,6 +242,10 @@ function mymodule.delete_table_entry(db, self, entry)
entry
.
value
.
id
.
errtxt
=
"Invalid entry"
else
local
res
,
err
=
pcall
(
function
()
local
db
=
dbase
if
type
(
dbase
)
==
"function"
then
db
=
dbase
()
end
local
connected
=
db
.
databaseconnect
()
entry
.
value
.
table
.
errtxt
=
"Invalid table"
local
tables
=
db
.
listtables
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment