Search
Varnish Enterprise

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

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, STRING)

Open the SQLite database specified by the 1st argument and set the field and row delimiters to be used in exec() to the 1st and 2nd character, respectively, of the 2nd argument.

sqlite3.open("file:mysqlitedb.db?mode=ro", "\|;");

Arguments: None

Type: Function

Returns: None

exec

STRING exec(STRING)

Run an SQL statements and return any result rows coming out of their evaluation. If an error occurs return the error text instead.

set req.http.results = sqlite3.exec("SELECT foo FROM bar");

Arguments: None

Type: Function

Returns: String

escape

STRING escape(STRING)

Escape the input string by doubling any single-quote (’) character and return the result.

set req.http.url = sqlite3.escape(req.url);

Arguments: None

Type: Function

Returns: String

close

VOID close()

Close a previously opened SQLite database.

sqlite3.close()

Arguments: None

Type: Function

Returns: None

Availability

The sqlite3 VMOD is available in Varnish Enterprise version 6.0.6r3 and later.