vrischmann / zig-sqlite

zig-sqlite is a small wrapper around sqlite's C API, making it easier to use with Zig.
MIT License
367 stars 49 forks source link

fix createAggregateFunction #91

Closed vrischmann closed 2 years ago

vrischmann commented 2 years ago

The old way of working was that we always passed the user context as first argument to both step and finalize functions and the caller had no way of getting the aggregate context from SQLite.

Now both step and finalize functions must have a first argument of type FunctionContext:

    fn step(fctx: FunctionContext, input: u32) void {
    var ctx = fctx.aggregateContext(*u32) orelse return;
        ctx.* += input;
    }
    fn finalize(ctx: *u32) u32 {
    var ctx = fctx.aggregateContext(*u32) orelse return 0;
        return ctx.sum;
    }

Fixes #89