12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273openPpxlibletfun_name=function"t"->"of_cols"|t->t^"_of_cols"letcol_attr=Attribute.declare"sqlgg.col"Attribute.Context.label_declarationAst_pattern.(single_expr_payload(estring__))Fun.idletcol_nameld=Option.value(Attribute.getcol_attrld)~default:ld.pld_name.txtletbuild~loctnamefirstrest=letfields=first::restinlet(moduleB)=Ast_builder.makelocinletopenBinletlid=Located.lidentinletrecord_ty=ptyp_constr(lidtname)[]inletcol_tyt=[%type:([%tt],'sqlgg__brand,'sqlgg__row,'sqlgg__params)Sqlgg_scope.col]inletcols_ty=ptyp_object(List.map(funld->otag(Located.mk(col_nameld))(col_tyld.pld_type))fields)Openinletrecord=pexp_record(List.map(funld->lidld.pld_name.txt,evarld.pld_name.txt)fields)Noneinletbindopld={pbop_op=Located.mkop;pbop_pat=pvarld.pld_name.txt;pbop_exp=pexp_send[%exprsqlgg__cols](Located.mk(col_nameld));pbop_loc=loc}inletletop=pexp_letop{let_=bind"let+"first;ands=List.map(bind"and+")rest;body=[%expr([%erecord]:[%trecord_ty])]}in[%strlet[%ppvar(fun_nametname)]=fun(sqlgg__cols:[%tcols_ty]):[%tcol_tyrecord_ty]->letopenSqlgg_scopein[%eletop]]letexpand~ctxt(_rec_flag,tds)=letloc=Expansion_context.Deriver.derived_item_locctxtinleterrormsg=[Ast_builder.Default.pstr_extension~loc(Location.error_extensionf~loc"deriving sqlgg: %s"msg)[]]inletexpand_tdtd=matchtd.ptype_paramswith|_::_->error"type parameters are not supported"|[]->matchtd.ptype_kindwith|Ptype_record(first::rest)->build~loctd.ptype_name.txtfirstrest|_->error"only record types are supported"inList.concat_mapexpand_tdtdslet()=Deriving.add"sqlgg"~str_type_decl:(Deriving.Generator.V2.make_noarg~attributes:[Attribute.Tcol_attr]expand)|>Deriving.ignore