Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
3a5e2fba
Commit
3a5e2fba
authored
Jan 04, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
5.0 lua example
parent
85940c80
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
new.mg.lua
build/test/new.mg.lua
+43
-0
No files found.
build/test/new.mg.lua
0 → 100644
View file @
3a5e2fba
mg
.
write
(
'HTTP/1.0 200 OK\r\n'
,
'Content-Type: text/plain\r\n'
,
'
\r\n
'
)
mg
.
write
(
os.date
(
"%A"
))
-- for k,v in pairs(_G) do mg.write(k, '\n') end
-- Open database
local
db
=
sqlite3
.
open
(
'requests.db'
)
-- Setup a trace callback, to show SQL statements we'll be executing.
-- db:trace(function(data, sql) mg.write('Executing: ', sql: '\n') end, nil)
-- Create a table if it is not created already
db
:
exec
(
[[
CREATE TABLE IF NOT EXISTS requests (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp NOT NULL,
method NOT NULL,
uri NOT NULL,
addr
);
]]
)
-- Add entry about this request
local
stmt
=
db
:
prepare
(
'INSERT INTO requests VALUES(NULL, datetime("now"), ?, ?, ?);'
);
stmt
:
bind_values
(
mg
.
request_info
.
request_method
,
mg
.
request_info
.
uri
,
mg
.
request_info
.
remote_port
)
stmt
:
step
()
stmt
:
finalize
()
-- Show all previous records
mg
.
write
(
'Previous requests:\n'
)
stmt
=
db
:
prepare
(
'SELECT * FROM requests ORDER BY id DESC;'
)
while
stmt
:
step
()
==
sqlite3
.
ROW
do
local
v
=
stmt
:
get_values
()
mg
.
write
(
v
[
1
]
..
' '
..
v
[
2
]
..
' '
..
v
[
3
]
..
' '
..
v
[
4
]
..
' '
..
v
[
5
]
..
'
\n
'
)
end
-- Close database
db
:
close
()
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