# HG changeset patch # User jbe # Date 1427046007 -3600 # Node ID 1fbdccf4f8e9ac6c1ac61937ea711f6f79bfda7c # Parent 0a6378afc6daa11c716c9777149599ff777ff97f Always enable SQL tracer (within framework/env/__init.lua); Record execution time of SQL statements diff -r 0a6378afc6da -r 1fbdccf4f8e9 doc/autodoc-header.htmlpart --- a/doc/autodoc-header.htmlpart Sun Mar 22 17:33:37 2015 +0100 +++ b/doc/autodoc-header.htmlpart Sun Mar 22 18:40:07 2015 +0100 @@ -153,18 +153,9 @@
_G.db = assert(mondelefant.connect(config.db)) -function mondelefant.class_prototype:get_db_conn() return db end - -if config.db_trace then - function db:sql_tracer(command) - return function(error_info) - local error_info = error_info or {} - trace.sql{ command = command, error_position = error_info.position } - end - end -end+function mondelefant.class_prototype:get_db_conn() return db end
- Overwriting the sql_tracer method of the database handle is optional, but helpful for debugging. The parameters for mondelefant.connect are directly passed to PostgreSQL's client library libpq. See PostgreSQL's documentation on PQconnect for information about supported parameters. + The parameters for mondelefant.connect are directly passed to PostgreSQL's client library libpq. See PostgreSQL's documentation on PQconnect for information about supported parameters.
To define a model to be used within a WebMCP application, create a file named with the name of the model and .lua as extension in the model/ directory of your application. The most basic definition of a model (named “movie” in this example) is: diff -r 0a6378afc6da -r 1fbdccf4f8e9 framework/env/__init.lua --- a/framework/env/__init.lua Sun Mar 22 17:33:37 2015 +0100 +++ b/framework/env/__init.lua Sun Mar 22 18:40:07 2015 +0100 @@ -41,12 +41,27 @@ extos = require 'extos' nihil = require 'nihil' mondelefant = require 'mondelefant' -mondelefant.connection_prototype.error_objects = true atom = require 'atom' json = require 'json' require 'mondelefant_atom_connector' -- NOTE: "multirand" library is loaded in mcp.lua after forking +-- setup mondelefant +mondelefant.connection_prototype.error_objects = true +function mondelefant.connection_prototype:sql_tracer(command) + if trace.is_disabled() then + return + end + local start_time = extos.monotonic_hires_time() + return function(error_info) + trace.sql{ + command = command, + execution_time = extos.monotonic_hires_time() - start_time, + error_position = error_info and error_info.position or nil + } + end +end + --[[-- config -- table to store application configuration diff -r 0a6378afc6da -r 1fbdccf4f8e9 framework/env/trace/_render_sub_tree.lua --- a/framework/env/trace/_render_sub_tree.lua Sun Mar 22 17:33:37 2015 +0100 +++ b/framework/env/trace/_render_sub_tree.lua Sun Mar 22 18:40:07 2015 +0100 @@ -1,3 +1,7 @@ +local function format_time(seconds) + return string.format("%.2f ms", seconds) +end + local function open(class) slot.put('