DBSlayer Commands

Once the DBSlayer is launched, applications can query the database by calling to one of several different RPC endpoints. Each call takes JSON in and returns JSON. This guide lists the supported endpoints in the slayer.

Database Endpoint - /db

http://hostname:port/db?[urlencode[JSON OBJECT]]

The JSON sent into the endpoint can have one or more of the following arguments to specify the type of query.

Arguments

NAMEVALUERESPONSECOMMENT
STAT true {"STAT" : "Uptime: 970059 Threads: 6 Questions: 44779 Slow queries: 176 Opens: 5691 Flush tables: 1 Open tables: 69 Queries per second avg: 0.046"} Returns the result of the mysql_stat command
CLIENT_INFO true {"CLIENT_INFO" : "5.0.26"} Returns the client version number from mysql_get_client_info
HOST_INFO true {"HOST_INFO" : "technews.foo.com via TCP\\/IP"} Returns the mysql host information
SERVER_VERSION true {"SERVER_VERSION" : 50037} Returns the mysql server version
CLIENT_VERSION true {"CLIENT_VERSION" : 50026} Return the mysql client version
SLAYER_DEBUG_RETURN_INPUT true {"SLAYER_DEBUG_RETURN_INPUT" : {"SLAYER_DEBUG_RETURN_INPUT" : true}} Returns the entire request in a JSON Object - this is useful for debuging purposes only
SQL "select now()" | {"RESULT" : {"TYPES" : ["MYSQL_TYPE_DATETIME"] , "HEADER" : ["now()"] , "ROWS" : [ ["2007-06-11 21:56:00"] ] } } See below

The SQL query is obviously used to query the database and returns a JSON Object in the "RESULT" field value. If the SQL is a normal select anjd returns data, the resulting reply JSON has three name/value pairs.

  • ROWS is an array of array
  • HEADER is an array of the column names.
  • TYPES is an array of MySQL type names.

Alternatively, if the sql issued doesn't return a result set (e.g., for INSERT/UPDATE/DELETE) then the response object will contain a name/value pair of {"SUCCESS" : true}. Additionally, if the SQL executed returns multiple result sets, then the RESULT key will instead contain an array of each result set.

Example

REQUEST

{"STAT" : true , "CLIENT_VERSION" : true , "SERVER_VERSION" : true , "SQL" : "select ci.Name, c.Name, ci.Population from City ci, Country c where ci.CountryCode = c.Code order by ci.Population DESC limit 10;"}

RESPONSE

{
	"CLIENT_VERSION" : 50026 , 
	"STAT" : "Uptime: 179793  Threads: 358  Questions: 132936  Slow queries: 1  Opens: 43473  Flush tables: 1  Open tables: 4  Queries
	 per second avg: 0.739", 
	"SERVER_VERSION" : 50036, 
	"RESULT" : {"TYPES" :  ["MYSQL_TYPE_STRING" , "MYSQL_TYPE_STRING" , "MYSQL_TYPE_LONG"], 
	            "HEADER" : ["Name" , "Name" , "Population"] , 
                    "ROWS" :   [["Mumbai (Bombay)" , "India" , 10500000] ,
                                ["Seoul" , "South Korea" , 9981619] ,
                                ["São Paulo" , "Brazil" , 9968485] , 
                                ["Shanghai" , "China" , 9696300] , 
                                ["Jakarta" , "Indonesia" , 9604900] , 
                                ["Karachi" , "Pakistan" , 9269265] , 
                                ["Istanbul" , "Turkey" , 8787958] , 
                                ["Ciudad de México" , "Mexico" , 8591309] , 
                                ["Moscow" , "Russian Federation" , 8389200] , 
                                ["New York" , "United States" , 8008278]
                               ]
                   }
}

For more information about using the DBSlayer, see the section Coding With The Slayer.

Shutdown Endpoint - /shutdown

http://hostname:port/shutdown

This command can be used in scripts to cleanly shut down a DBSlayer instance. It takes no arguments and currently has no authentication. For some basic security, this command can only be called from the same machine the DBSlayer is running on.

Statistics and Logging

See the section on Statistics and Logging endpoints.

Specifying Custom Endpoints

With its support for HTTP, the DBSlayer can serve more than database queries and statistical data. The -b flag for DBSlayer specifies a base directory on disk that may be used to resolve any other URL requests (provided it doesn't collide with the name for an existing endpoint). Some of the other standard web server conventions apply: if a request endpoint results in a directory, DBSlayer will return the index.html file within that directory. Currently, only static files are supported by this feature, meaning any dynamic behavior will have to be implemented with AJAX (support for a built-in scripting language is left for future releases). The htdocs directory in the Slayer distibution contains some admin/stats monitoring scripts built for your use.

At this time, the complete set of endpoints has not been set, meaning it is still theoretically possible for a new endpoint to be defined that might collide with your custom endpoint. The admin endpoint is reserved for future uses, while site and user will never be used for DBSlayer scripts.