-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,39 @@ | ||
import sql from "k6/x/sql"; | ||
|
||
// ramsql is hypothetical, the actual driver name should be used instead. | ||
// the actual database driver should be used instead of ramsql | ||
import driver from "k6/x/sql/driver/ramsql"; | ||
|
||
const db = sql.open(driver, "test_db"); | ||
const db = sql.open(driver, "roster_db"); | ||
|
||
export function setup() { | ||
db.exec(`CREATE TABLE IF NOT EXISTS namevalue ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name VARCHAR NOT NULL, | ||
value VARCHAR | ||
);`); | ||
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 () { | ||
db.exec("INSERT INTO namevalue (name, value) VALUES('extension-name', 'xk6-foo');"); | ||
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 results = sql.query(db, "SELECT * FROM namevalue WHERE name = $1;", "extension-name"); | ||
for (const row of results) { | ||
console.log(`name: ${row.name}, value: ${row.value}`); | ||
let rows = sql.query(db, "SELECT * FROM roster WHERE given_name = $1;", "Peter"); | ||
for (const row of rows) { | ||
console.log(`${row.family_name}, ${row.given_name}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters