Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/grafana/xk6-sql-driver-mysql
xk6-sql driver extension for MySQL database support
https://github.com/grafana/xk6-sql-driver-mysql
xk6 xk6-sql-driver
Last synced: 3 days ago
JSON representation
xk6-sql driver extension for MySQL database support
- Host: GitHub
- URL: https://github.com/grafana/xk6-sql-driver-mysql
- Owner: grafana
- License: agpl-3.0
- Created: 2024-10-17T15:13:42.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-05T14:46:26.000Z (about 2 months ago)
- Last Synced: 2024-11-14T22:35:10.214Z (about 1 month ago)
- Topics: xk6, xk6-sql-driver
- Language: Go
- Homepage:
- Size: 43.9 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# xk6-sql-driver-mysql
Database driver extension for [xk6-sql](https://github.com/grafana/xk6-sql) k6 extension to support MySQL database.
## Example
```JavaScript file=examples/example.js
import sql from "k6/x/sql";
import driver from "k6/x/sql/driver/mysql";// The second argument is a MySQL connection string, e.g.
// myuser:mypass@tcp(127.0.0.1:3306)/mydb
const db = sql.open(driver, "");export function setup() {
db.exec(`
CREATE TABLE IF NOT EXISTS roster
(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
given_name VARCHAR(50) NOT NULL,
family_name VARCHAR(50) 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 = ?;", "Peter");
for (const row of rows) {
// Convert array of ASCII integers into strings. See https://github.com/grafana/xk6-sql/issues/12
console.log(`${String.fromCharCode(...row.family_name)}, ${String.fromCharCode(...row.given_name)}`);
}
}
```## Usage
Check the [xk6-sql documentation](https://github.com/grafana/xk6-sql) on how to use this database driver.
### TLS Support
> [!IMPORTANT]
>
> TLS support has been adopted more or less unchanged from xk6-sql v0.4.1.
> Refactoring is required.To enable TLS support, call `loadTLS` from the script, before calling `open`. [examples/example-tls.js](examples/example-tls.js) is an example.
`loadTLS` accepts the following options:
```javascript
loadTLS({
enableTLS: true,
insecureSkipTLSverify: true,
minVersion: sql.TLS_1_2,
// Possible values: sql.TLS_1_0, sql.TLS_1_1, sql.TLS_1_2, sql.TLS_1_3
caCertFile: '/filepath/to/ca.pem',
clientCertFile: '/filepath/to/client-cert.pem',
clientKeyFile: '/filepath/to/client-key.pem',
});
```