Skip to content

Instantly share code, notes, and snippets.

@crazymonkyyy
Created December 10, 2025 11:00
Show Gist options
  • Select an option

  • Save crazymonkyyy/8a62427cb98e733ab95b1d178a79a545 to your computer and use it in GitHub Desktop.

Select an option

Save crazymonkyyy/8a62427cb98e733ab95b1d178a79a545 to your computer and use it in GitHub Desktop.

tranactional api

adr said sometin about db trasactions not thinking it was possible

I thought this was the goal:

with(db.transaction){
  foo(1);//transaction.foo(1) but doesnt do it yet
  bar(3);//transaction.bar(3) but does it cause spooky
}

this is possible:

import std;

enum counter=cast(immutable(void)*)[0].ptr;
auto getcount()=>(*(cast(int*)counter));
auto count()=>(*(cast(int*)counter))++;
int rtcount()=>getcount;


struct transaction_{
    template opDispatch(string s) {
        auto opDispatch(int line = __LINE__,T...)(T t) {
            enum C=count;
            writeln(s, line, " ", t," ",rtcount," ",C," ",rtcount==C+1);
}}}
auto maketransaction()=>transaction_();
void main(){
    with(maketransaction()){
        foo(1);
        bar(3);
        foobar("hello world");
    }
}

I dont know if anyone cares but in thoery you could make something like a template maketranactionalapi(alias F,int line) where the user calls alias foo(int line=__LINE__)=maketranactionalapi!(F,line); where F is a template that accepts the call of F!(["foo","bar","foobar"],line/*,T...*/)(1,void,3,void,"hello world")

rough steps:

  1. abstract counter to be owned by trasaction
  2. store ct strings, accessed by counter
  3. appendable ct type list
  4. innate but redesigned for the appendable type list, indexed by int and grabbing a count

I dont really care about db's tho and the dependence on bugs probaly makes this a nonestarter for poeple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment