✓
Passing This code compiles and runs correctly.
Code
import app/db
import std/io
app/db:open(connstr: "postgres://localhost/test")
| connected c |> app/db:tx.begin(conn: c): t |> app/db:tx.exec(tx: t, sql: "INSERT INTO users VALUES (1)"): t2 |> app/db:tx.commit(tx: t2): conn |> std/io:print.ln("committed")
| connection-failed |> _
Supporting Files
// JavaScript implementation facet. The Koru declarations live in the
// `db.kz` companion (merged at import); this file holds the `|js`
// proc bodies mirroring its `|zig` ones.
//
// The Zig facet allocates because a `*Connection` needs an address; the
// phantom `connected!` / `active!` states are compile-time obligations, so
// the JS facet returns the objects directly and drops the explicit destroys.
~proc open|js {
return { tag: "connected", connected: { handle: 42 } };
}
~proc tx.begin|js {
return { conn_handle: conn.handle };
}
~proc tx.exec|js {
console.log(`Executing: ${sql}`);
return tx;
}
~proc tx.commit|js {
console.log(`COMMIT`);
return { handle: tx.conn_handle };
}
~proc tx.rollback|js {
console.log(`ROLLBACK`);
return { rolled_back: { handle: tx.conn_handle } };
}
~proc close|js {
console.log(`Connection closed`);
}
// open/tx lifecycle API — ground truth for korulang.org phantom explorer
const std = @import("std");
const Connection = struct { handle: i32 };
const Transaction = struct { conn_handle: i32 };
~pub tor open { connstr: string }
| connected *Connection<connected!>
| connection-failed
~proc open|zig {
_ = connstr;
const c = std.heap.page_allocator.create(Connection) catch unreachable;
c.* = Connection{ .handle = 42 };
return .{ .connected = c };
}
~pub tor tx.begin { conn: *Connection<!connected|!active> } -> *Transaction<started!>
~proc tx.begin|zig {
const t = std.heap.page_allocator.create(Transaction) catch unreachable;
t.* = Transaction{ .conn_handle = conn.handle };
return t;
}
~pub tor tx.exec { tx: *Transaction<!started|!active>, sql: string } -> *Transaction<active!>
~proc tx.exec|zig {
std.debug.print("Executing: {s}\n", .{sql});
return tx;
}
~pub tor tx.commit { tx: *Transaction<!active> } -> *Connection<active!>
~proc tx.commit|zig {
std.debug.print("COMMIT\n", .{});
const c = std.heap.page_allocator.create(Connection) catch unreachable;
c.* = Connection{ .handle = tx.conn_handle };
std.heap.page_allocator.destroy(tx);
return c;
}
~pub tor tx.rollback { tx: *Transaction<!active> } -> *Connection<active!>
~proc tx.rollback|zig {
std.debug.print("ROLLBACK\n", .{});
const c = std.heap.page_allocator.create(Connection) catch unreachable;
c.* = Connection{ .handle = tx.conn_handle };
std.heap.page_allocator.destroy(tx);
return .{ .rolled_back = c };
}
~pub tor close { conn: *Connection<!active> }
~proc close|zig {
std.debug.print("Connection closed\n", .{});
std.heap.page_allocator.destroy(conn);
}
Actual
Executing: INSERT INTO users VALUES (1)
COMMIT
committed
Connection closed
Expected output
Executing: INSERT INTO users VALUES (1)
COMMIT
committed
Connection closed
Flows
flow ~open click a branch to expand · @labels scroll to their anchor
open (connstr: "postgres://localhost/test")
Test Configuration
MUST_RUN