Search
Varnish Enterprise

Introduction Installation Upgrading Troubleshooting Changelog Changelog for 6.0.x Changes (Varnish Cache 4.1) Changes (Varnish Cache Plus 4.1) Known Issues Features Backend SSL/TLS Client SSL/TLS termination Cluster In-Process TLS MSE 4 Basic Configuration / Getting Started Configuration Persisted caching Categories Configuration Reference MSE 3.0 Settings mkfs.mse Memory Governor MSE 2.0 NUMA Parallel ESI Backend health counter HTTP/2 Support JSON Logging TCP Only Probes Timeouts Transit Buffer Varnish scoreboard VMODs Accept Accounting ACL (aclplus) ActiveDNS Akamai Connector AWS VCL Body Access & Transformation (xbody) Brotli Cookie Plus (cookieplus) DeviceAtlas DeviceAtlas3 Digest Dynamic backends (goto) Edgestash File Format Geolocation (geoip/mmdb) Header Manipulation (headerplus) HTTP communication (http) Image JSON parsing (json) JWT Key value storage (kvstore) Least connections director (leastconn) Module to control the built-in HTTP2 transport (h2) MSE control (mse) MSE4 control (mse4) Probe Proxy ProxyV2 TLV Attribute Extraction (proxy) Pseudo Random Number Generator Purge (purge/softpurge) Real-time Status (rtstatus) Reverse DNS (resolver) Rewrite S3 VMOD Session Slicer SQLite3 Stale Standard (std) Stat (Prometheus) Strings (str) Synthetic backends (synthbackend) Tag-based invalidation (Ykey/Xkey) TCP configuration (tcp) TLS Total Encryption (crypto) Unified director object (udo) Uniform Resource Identifier (uri) Unix Socket Utilities (unix) URL Plus (urlplus) Utils Vsthrottle

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.


®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203