Search
Varnish Cache Plus

SQLite3

Description

SQLite is a library allowing users to use in-memory or single-file relational databases. vmod_sqlite3 integrates this library to use it from inside your VCL.

Example VCL

import sqlite3;

sub vcl_init {
	# open the database
	sqlite3.open("file:mysqlitedb.db?mode=ro", "\|;");
}

sub vcl_recv {
	# generate a synthetic response for this particular URL
	if (req.url == "/ask_db") {
		return (synth(200));
	}
}

sub vcl_deliver {
	# fill the response body with the output of the query
	if (req.url == "/ask_db") {
		synthetic(sqlite3.exec("SELECT foo FROM bar"));
		return(deliver);
	}
}

API

open

VOID open(STRING path, STRING delimiters)

Opens a database and keeps it open until sqlite3.close() is called or the VCL is discarded.

Argument

  • STRING path - location of the database file.

  • STRING delimiters - a STRING of two charaters: the field delimiter, then the row delimiter.

Returns

Nothing

close

VOID close()

Close the currently opened database.

Argument

None

Returns

Nothing

exec

STRING exec(STRING statement)

Runs an SQL statement against the opened database.

Argument

  • STRING statement - The SQL statement to run.

Returns

The result, or the error string if one occurred.

escape

STRING escape(STRING s)

Escape s by doubling single-quotes so it can be used in a statement.

Argument

  • STRING s - The string to escape.

Returns

The escaped string.