db2

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

README

xk6-sql-driver-db2

Database driver extension for xk6-sql k6 extension to support IBM DB2 database.

Example

import sql from "k6/x/sql";
import driver from "k6/x/sql/driver/go_ibm_db";
// Required as the DB2 driver seems to return uint arrays for VARCHAR columns
import { TextDecoder } from "k6/x/encoding";

const con =
  "HOSTNAME=localhost;DATABASE=sample;PORT=50000;UID=db2inst1;PWD=password123";
const db = sql.open(driver, con);

export function setup() {
  let exist = db.query(
    "SELECT 1 FROM SYSCAT.TABLES WHERE TABSCHEMA='DB2INST1' AND TABNAME='SAMPLE';",
  );

  if (exist.length != 0) {
    db.exec("drop table SAMPLE;");
  }
  db.exec(`
     CREATE TABLE SAMPLE (
            id VARCHAR(10) NOT NULL DEFAULT '',
            f_name VARCHAR(40),
            l_name VARCHAR(40)
      );
  `);
}

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

export default function () {
  const streamDecoder = new TextDecoder();
  let result = db.exec(`
    INSERT INTO SAMPLE
      (id, f_name, l_name)
    VALUES
      ('1', 'Peter', 'Pan'),
      ('2', 'Wendy', 'Darling'),
      ('3', 'Tinker', 'Bell'),
      ('4', 'James', 'Hook');
  `);
  console.log(`${result.rowsAffected()} rows inserted`);

  let rows = db.query("SELECT * FROM SAMPLE WHERE f_name = 'Peter';");
  for (const row of rows) {
    console.log(streamDecoder.decode(new Uint8Array(row.L_NAME)));
  }
}

Building with xk6

To build a k6 binary with this DB2 driver extension:

# First, set up the IBM DB2 client libraries
curl -L https://raw.githubusercontent.com/ibmdb/go_ibm_db/refs/heads/master/installer/setup.go -o setup.go
go run setup.go
rm -f setup.go

# Then build k6 with the extension
xk6 build --with github.com/grafana/xk6-sql@latest --with github.com/whiteturtle/xk6-sql-driver-db2@latest

Or if building from the local repository:

make build

Usage

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

Documentation

Overview

Package db2 contains IBM DB2 driver registration for xk6-sql.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ModuleInstance

type ModuleInstance struct{}

ModuleInstance represents an instance of the module for each VU.

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() modules.Exports

Exports returns the exports of the module.

type RootModule

type RootModule struct{}

RootModule is the global module instance that will create instances of the module.

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(_ modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface to return a new instance for each VU.

Jump to

Keyboard shortcuts

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