Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

// Fork from https://github.com/ankane/setup-mysql/blob/v1/index.js#L50

// TODO: this script failed on github now, see
// https://github.com/zigcc/zig-cookbook/issues/54
const execSync = require("child_process").execSync;
const fs = require('fs');
const os = require('os');
Expand All @@ -22,9 +20,9 @@ function addToPath(newPath) {
fs.appendFileSync(process.env.GITHUB_PATH, `${newPath}\n`);
}

// install
// config
const mysqlVersion = '8.0';
const rootPass = '123';
const rootPass = 'password';
const database = 'public';

// install
Expand All @@ -41,8 +39,8 @@ run(`${bin}/mysql -e "GRANT ALL PRIVILEGES ON *.* TO '$USER'@'localhost'"`);
run(`${bin}/mysql -e "FLUSH PRIVILEGES"`);

// init
run(`${bin}/mysqladmin -proot password '${rootPass}'`);
run(`${bin}/mysqladmin create ${database}`);
run(`${bin}/mysql -uroot -e "CREATE DATABASE ${database}"`);
run(`${bin}/mysql -uroot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '${rootPass}'; FLUSH PRIVILEGES;"`)

// set path
addToPath(bin);
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ on:
pull_request:
paths:
- "**.zig"
- ".github/workflows/**"
- ".github/**"
push:
branches:
- main
paths:
- "**.zig"
- ".github/workflows/**"
- ".github/**"

jobs:
examples:
Expand All @@ -22,10 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# CI cannot run on macOS, see
# https://github.com/zigcc/zig-cookbook/issues/54
# os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest]
zig: [0.11.0, master]
steps:
- uses: actions/checkout@v4
Expand All @@ -47,7 +44,7 @@ jobs:
collation server: 'utf8_general_ci'
mysql version: '8.0'
mysql database: 'public'
mysql root password: 123
mysql root password: 'password'
mysql user: 'developer'
- name: mysql for macOS
if: matrix.os == 'macos-latest'
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: "123"
MYSQL_ROOT_PASSWORD: "password"
MYSQL_DATABASE: public
ports:
- "3306:3306"
16 changes: 4 additions & 12 deletions src/14-03.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ pub const DB = struct {

fn deinit(self: DB) void {
c.mysql_close(self.conn);
return;
}

fn execute(self: DB, query: []const u8) !void {
if (c.mysql_real_query(self.conn, query.ptr, query.len) != 0) {
print("Exec query failed: {s}\n", .{c.mysql_error(self.conn)});
return error.execError;
}

return;
}

fn queryTable(self: DB) !void {
Expand All @@ -83,7 +80,6 @@ pub const DB = struct {
while (c.mysql_fetch_row(result)) |row| {
const cat_name = row[0];
const color_name = row[1];

print("Cat: {s}, Color: {s}\n", .{ cat_name, color_name });
}
}
Expand Down Expand Up @@ -177,8 +173,6 @@ pub const DB = struct {
_ = c.mysql_stmt_reset(insert_cat_stmt);
}
}

return;
}
};

Expand All @@ -188,16 +182,14 @@ pub fn main() !void {
const allocator = gpa.allocator();

const version = c.mysql_get_client_version();
print("mysql version is {}\n", .{version});
print("MySQL client version is {}\n", .{version});

const info: DBInfo = .{
const db = try DB.init(allocator, .{
.database = "public",
.host = "127.0.0.1",
.user = "root",
.password = "123",
};

const db = try DB.init(allocator, info);
.password = "password",
});
defer db.deinit();

try db.execute(
Expand Down