Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ config "development", ->
database "my_database"
```

Specifying `mysql` instead of `postgres` will use the `lua-resty-mysql` driver.
To specify a socket, use `path` instead of `host`. By default,
`read_timeout_ms = 1000`, `idle_timeout_ms = 10000`, and `max_connections = 100`

`host` defaults to `127.0.0.1` and `user` defaults to `postgres`, so you can
leave those fields out if they aren't different from the defaults. If a
non-default port is required it can be appended to the `host` with colon
Expand Down
1 change: 1 addition & 0 deletions lapis-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ build = {
["lapis.lua"] = "lapis/lua.lua",
["lapis.nginx"] = "lapis/nginx.lua",
["lapis.nginx.context"] = "lapis/nginx/context.lua",
["lapis.nginx.db"] = "lapis/nginx/db.lua",
["lapis.nginx.http"] = "lapis/nginx/http.lua",
["lapis.nginx.mysql"] = "lapis/nginx/mysql.lua",
["lapis.nginx.postgres"] = "lapis/nginx/postgres.lua",
Expand Down
1 change: 1 addition & 0 deletions lapis.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return require("lapis.init")
20 changes: 16 additions & 4 deletions lapis/application.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@ local url = require("socket.url")
local session = require("lapis.session")
local lapis_config = require("lapis.config")
local Router
Router = require("lapis.router").Router
do
local _obj_0 = require("lapis.router")
Router = _obj_0.Router
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why my moonc does this.

local html_writer
html_writer = require("lapis.html").html_writer
do
local _obj_0 = require("lapis.html")
html_writer = _obj_0.html_writer
end
local increment_perf
increment_perf = require("lapis.nginx.context").increment_perf
do
local _obj_0 = require("lapis.nginx.context")
increment_perf = _obj_0.increment_perf
end
local parse_cookie_string, to_json, build_url, auto_table
do
local _obj_0 = require("lapis.util")
parse_cookie_string, to_json, build_url, auto_table = _obj_0.parse_cookie_string, _obj_0.to_json, _obj_0.build_url, _obj_0.auto_table
end
local insert
insert = table.insert
do
local _obj_0 = table
insert = _obj_0.insert
end
local json = require("cjson")
local capture_errors, capture_errors_json, respond_to
local set_and_truthy
Expand Down
5 changes: 4 additions & 1 deletion lapis/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ delete_path = function(path, dict_name)
dict_name = "page_cache"
end
local escape_pattern
escape_pattern = require("lapis.util").escape_pattern
do
local _obj_0 = require("lapis.util")
escape_pattern = _obj_0.escape_pattern
end
local dict = ngx.shared[dict_name]
local _list_0 = dict:get_keys()
for _index_0 = 1, #_list_0 do
Expand Down
31 changes: 25 additions & 6 deletions lapis/cmd/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ tasks = {
end
write_config_for(environment)
local send_hup
send_hup = require("lapis.cmd.nginx").send_hup
do
local _obj_0 = require("lapis.cmd.nginx")
send_hup = _obj_0.send_hup
end
local pid = send_hup()
if pid then
return print(colors("%{green}HUP " .. tostring(pid)))
Expand All @@ -186,7 +189,10 @@ tasks = {
help = "send HUP signal to running server",
function()
local send_hup
send_hup = require("lapis.cmd.nginx").send_hup
do
local _obj_0 = require("lapis.cmd.nginx")
send_hup = _obj_0.send_hup
end
local pid = send_hup()
if pid then
return print(colors("%{green}HUP " .. tostring(pid)))
Expand All @@ -200,7 +206,10 @@ tasks = {
help = "sends TERM signal to shut down a running server",
function()
local send_term
send_term = require("lapis.cmd.nginx").send_term
do
local _obj_0 = require("lapis.cmd.nginx")
send_term = _obj_0.send_term
end
local pid = send_term()
if pid then
return print(colors("%{green}TERM " .. tostring(pid)))
Expand All @@ -216,7 +225,10 @@ tasks = {
function(signal)
assert(signal, "Missing signal")
local send_signal
send_signal = require("lapis.cmd.nginx").send_signal
do
local _obj_0 = require("lapis.cmd.nginx")
send_signal = _obj_0.send_signal
end
local pid = send_signal(signal)
if pid then
return print(colors("%{green}Sent " .. tostring(signal) .. " to " .. tostring(pid)))
Expand All @@ -237,7 +249,10 @@ tasks = {
fail_with_message("missing lua-string: exec <lua-string>")
end
local attach_server
attach_server = require("lapis.cmd.nginx").attach_server
do
local _obj_0 = require("lapis.cmd.nginx")
attach_server = _obj_0.attach_server
end
if not (get_pid()) then
print(colors("%{green}Using temporary server..."))
end
Expand All @@ -255,10 +270,14 @@ tasks = {
environment = default_environment()
end
local attach_server
attach_server = require("lapis.cmd.nginx").attach_server
do
local _obj_0 = require("lapis.cmd.nginx")
attach_server = _obj_0.attach_server
end
if not (get_pid()) then
print(colors("%{green}Using temporary server..."))
end
write_config_for(environment)
local server = attach_server(environment)
print(server:exec([[ local migrations = require("lapis.db.migrations")
migrations.create_migrations_table()
Expand Down
1 change: 1 addition & 0 deletions lapis/cmd/actions.moon
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ tasks = {
print colors "%{green}Using temporary server..."


write_config_for environment
server = attach_server environment
print server\exec [[
local migrations = require("lapis.db.migrations")
Expand Down
5 changes: 4 additions & 1 deletion lapis/cmd/templates/config_etlua.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local config = require("lapis.cmd.templates.config")
local compile_config
compile_config = require("lapis.cmd.nginx").compile_config
do
local _obj_0 = require("lapis.cmd.nginx")
compile_config = _obj_0.compile_config
end
local env = setmetatable({ }, {
__index = function(self, key)
return "<%- " .. tostring(key:lower()) .. " %>"
Expand Down
6 changes: 6 additions & 0 deletions lapis/cmd/templates/web.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
return [[lapis = require "lapis"

lapis.serve class extends lapis.Application
"/": =>
"Welcome to Lapis #{require "lapis.version"}!"
]]
9 changes: 9 additions & 0 deletions lapis/cmd/templates/web_lua.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
return [[local lapis = require "lapis"
local app = lapis.Application()

app:get("/", function()
return "Welcome to Lapis " .. require("lapis.version")
end)

lapis.serve(app)
]]
10 changes: 8 additions & 2 deletions lapis/cmd/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ do
insert, concat = _obj_0.insert, _obj_0.concat
end
local escape_pattern
escape_pattern = require("lapis.util").escape_pattern
do
local _obj_0 = require("lapis.util")
escape_pattern = _obj_0.escape_pattern
end
local split
split = function(str, delim)
str = str .. delim
Expand Down Expand Up @@ -91,7 +94,10 @@ local random_string
do
math.randomseed(os.time())
local random
random = math.random
do
local _obj_0 = math
random = _obj_0.random
end
local random_char
random_char = function()
local _exp_0 = random(1, 3)
Expand Down
5 changes: 4 additions & 1 deletion lapis/config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local insert
insert = table.insert
do
local _obj_0 = table
insert = _obj_0.insert
end
local config_cache, configs, default_config, merge_set, set, scope_meta, config, reset, run_with_scope, get_env, get
config_cache = { }
configs = { }
Expand Down
5 changes: 4 additions & 1 deletion lapis/csrf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ end
local assert_token
assert_token = function(...)
local assert_error
assert_error = require("lapis.application").assert_error
do
local _obj_0 = require("lapis.application")
assert_error = _obj_0.assert_error
end
return assert_error(validate_token(...))
end
return {
Expand Down
2 changes: 1 addition & 1 deletion lapis/db.lua
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return require("lapis.nginx.postgres")
return require("lapis.nginx.db")
2 changes: 1 addition & 1 deletion lapis/db.moon
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require "lapis.nginx.postgres"
require "lapis.nginx.db"
10 changes: 8 additions & 2 deletions lapis/db/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ end
local build_helpers
build_helpers = function(escape_literal, escape_identifier)
local concat
concat = table.concat
do
local _obj_0 = table
concat = _obj_0.concat
end
local select
select = _G.select
do
local _obj_0 = _G
select = _obj_0.select
end
local append_all
append_all = function(t, ...)
for i = 1, select("#", ...) do
Expand Down
5 changes: 4 additions & 1 deletion lapis/db/migrations.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
local db = require("lapis.db")
local logger = require("lapis.logging")
local Model
Model = require("lapis.db.model").Model
do
local _obj_0 = require("lapis.db.model")
Model = _obj_0.Model
end
local LapisMigrations
do
local _parent_0 = Model
Expand Down
50 changes: 38 additions & 12 deletions lapis/db/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ local db = require("lapis.db")
local escape_literal
escape_literal = db.escape_literal
local concat
concat = table.concat
do
local _obj_0 = table
concat = _obj_0.concat
end
local append_all
append_all = function(t, ...)
for i = 1, select("#", ...) do
Expand Down Expand Up @@ -41,9 +44,8 @@ extract_options = function(cols)
end
local entity_exists
entity_exists = function(name)
name = db.escape_literal(name)
local res = unpack(db.select("COUNT(*) as c from pg_class where relname = " .. tostring(name)))
return res.c > 0
local res = db.select(db.get_dialect().row_if_entity_exists, name)
return #res > 0
end
local gen_index_name
gen_index_name = function(...)
Expand Down Expand Up @@ -138,19 +140,28 @@ create_index = function(tname, ...)
end
end
append_all(buffer, ")")
if options.tablespace then
if options.tablespace and db.get_dialect().tablespace then
append_all(buffer, " TABLESPACE ", options.tablespace)
end
if options.where then
if options.where and db.get_dialect().index_where then
append_all(buffer, " WHERE ", options.where)
end
append_all(buffer, ";")
return db.query(concat(buffer))
end
local drop_index
drop_index = function(...)
local index_name = gen_index_name(...)
return db.query("DROP INDEX IF EXISTS " .. tostring(db.escape_identifier(index_name)))
local index_name = db.escape_identifier(gen_index_name(...))
if db.get_dialect().drop_index_if_exists then
return db.query("DROP INDEX IF EXISTS " .. tostring(index_name))
else
db.query("LOCK TABLES bar WRITE")
if entity_exists(index_name) then
local table_name = db.escape_identifier((...))
db.query("DROP INDEX " .. tostring(index_name) .. " ON " .. tostring(table_name))
end
return db.query("UNLOCK TABLES")
end
end
local drop_table
drop_table = function(tname)
Expand All @@ -170,10 +181,19 @@ drop_column = function(tname, col_name)
end
local rename_column
rename_column = function(tname, col_from, col_to)
tname = db.escape_identifier(tname)
col_from = db.escape_identifier(col_from)
col_to = db.escape_identifier(col_to)
return db.query("ALTER TABLE " .. tostring(tname) .. " RENAME COLUMN " .. tostring(col_from) .. " TO " .. tostring(col_to))
if db.get_dialect().rename_column then
tname = db.escape_identifier(tname)
return db.query("ALTER TABLE " .. tostring(tname) .. " RENAME COLUMN " .. tostring(col_from) .. " TO " .. tostring(col_to))
else
assert(not tname:match("`", "invalid table name " .. tname))
local res = db.query("SHOW CREATE TABLE " .. tostring(tname))
assert(#res == 1, "cannot have " .. tostring(#res) .. " rows from SHOW CREATE TABLE")
local col_def = res[1]["Create Table"]:match("\n *`" .. tostring(tname) .. "` ([^\n]-),?\n")
assert(col_def, "no column definition in " .. tostring(res[1]))
return db.query("ALTER TABLE " .. tostring(tname) .. " MODIFY " .. tostring(col_from) .. " " .. tostring(col_to) .. " " .. tostring(col_def))
end
end
local rename_table
rename_table = function(tname_from, tname_to)
Expand Down Expand Up @@ -237,8 +257,14 @@ do
__tostring = ColumnType.__tostring,
__call = function(self, opts)
local base = self.base
if opts.timezone then
self.base = base .. " with time zone"
if base == "timestamp" then
if db.get_dialect().explicit_time_zone then
if opts.timezone then
self.base = base .. " with time zone"
end
else
self.base = opts.timezone and "timestamp" or "datetime"
end
end
do
local _with_0 = ColumnType.__call(self, opts)
Expand Down
Loading