sqlite3

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2025 License: AGPL-3.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

xk6-sql-driver-sqlite3

Database driver extension for xk6-sql k6 extension to support SQLite v3 database.

Example

import sql from "k6/x/sql";
import driver from "k6/x/sql/driver/sqlite3";

const db = sql.open(driver, "./test.db");

export function setup() {
  db.exec(`
    CREATE TABLE IF NOT EXISTS roster
      (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        given_name VARCHAR NOT NULL,
        family_name VARCHAR NOT NULL
      );
  `);
}

export function teardown() {
  db.close();
}

export default function () {
  let result = db.exec(`
    INSERT INTO roster
      (given_name, family_name)
    VALUES
      ('Peter', 'Pan'),
      ('Wendy', 'Darling'),
      ('Tinker', 'Bell'),
      ('James', 'Hook');
  `);
  console.log(`${result.rowsAffected()} rows inserted`);

  let rows = db.query("SELECT * FROM roster WHERE given_name = $1;", "Peter");
  for (const row of rows) {
    console.log(`${row.family_name}, ${row.given_name}`);
  }
}

Usage

Check the xk6-sql documentation on how to use this database driver.

Build

Since the sqlite3 driver uses a native shared library, the build requirements are slightly different from other drivers.

Prerequisites

  • Go toolchain
  • A build toolchain for your system that includes gcc or another C compiler. On Debian and derivatives install the build-essential package. On Windows you can use tdm-gcc. Make sure that gcc is in your PATH.
  • Git
  • Set CGO_ENABLED=1 in the environment

Linux

CGO_ENABLED=1 xk6 build --with github.com/grafana/xk6-sql-driver-sqlite3@latest --with github.com/grafana/xk6-sql@latest

Windows

set CGO_ENABLED=1
xk6 build --with github.com/grafana/xk6-sql-driver-sqlite3@latest --with github.com/grafana/xk6-sql@latest

Documentation

Overview

Package sqlite3 contains SQLite3 driver registration for xk6-sql.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址