cosmopolitan/tool/net/demo/.init.lua
Justine Tunney 88806b79b1 Tune SQLite build for redbean (#97)
redbean lua handlers that perform sql queries can do 400k qps.

We now use a separate compile-time options for SQLite, when building the
SQLite shell versus building the production web serving code. It doesn't
seem appropriate for something like redbean to include backups, progress
callbacks, query completion, profiling, EXPLAIN, ALTER, ANALYZE, VACUUM,
etc. since those tasks are better left to the sqlite3.com shell program.

Lua SQLite pointer APIs have been removed since we're not using threads.
The Lua APIs for installing update / commit / rollback hooks are removed
due to a general sense of disagreement and an overall lack of comfort.

Full-Text Search and R*Tree are as large as the rest of SQLite combined.
Turning those off keeps redbean under 1mb when built for MODE=tiny which
is nice for marketing purposes.

If you need something that was removed, file an issue, and we'll add it.
2021-06-10 08:00:08 -07:00

35 lines
1,022 B
Lua

mymodule = require "mymodule"
sqlite3 = require "lsqlite3"
-- /.init.lua is loaded at startup in redbean's main process
HidePath('/usr/share/zoneinfo/')
-- open a browser tab using explorer/open/xdg-open
-- LaunchBrowser('/tool/net/demo/index.html')
-- sql database (see sql.lua)
db = sqlite3.open_memory()
db:exec[[
CREATE TABLE test (
id INTEGER PRIMARY KEY,
content TEXT
);
INSERT INTO test (content) VALUES ('Hello World');
INSERT INTO test (content) VALUES ('Hello Lua');
INSERT INTO test (content) VALUES ('Hello Sqlite3');
]]
-- this intercepts all requests if it's defined
function OnHttpRequest()
if HasParam('magic') then
Write('<p>\r\n')
Write('OnHttpRequest() has intercepted your request<br>\r\n')
Write('because you specified the magic parameter\r\n')
Write('<pre>\r\n')
Write(EscapeHtml(LoadAsset('/.init.lua')))
Write('</pre>\r\n')
else
Route() -- this asks redbean to do the default thing
end
SetHeader('Server', 'redbean!')
end