A simple way of reading/writing structs from/to a sqlite database

zstructDB


Hi!
I currently was working on a project where i needed to a lot of different structs to be stored in a database (e.g. address book). So I thought about a way to dont have to write the boilerplate code of the SQL queries every time. So i came up with ztructDB. It will take any struct, does some comptime validation, transforms it into a database, and lets you access the data easily without writing an SQL query even once. (Im not sure if anybody else can make use of it)

Here is the link to the repository: ztructDB

Feedback is welcome. But since i am a beginner in zig and overall a not very experienced programmer, im not so sure about the code quality- so im sorry if my code will hurt your eyes.

During development i learned a lot about comptime, meta programming, comptime and runtime boundaries (there is a lot more to learn).
Also i got more used to the syntax and basics of zig. Like whats possible - what does the compiler complain about, how to understand compiler errors and fix them fast.

Supported Zig versions

0.16.0

12 Likes

In other words, an ORM

1 Like

No need to put it so dismissively, OP mentioned they were a beginner and might not be familiar.

4 Likes

I didn’t mean it dismissively. Sorry for the brevity. Just bringing in a relevant term of art.

4 Likes

No problem. I didnt feel offended. Thanks for naming the correct technical term.
Actually there are already implementations in zig like Tony-ArtZ/zorm: A Zig ORM with custom schema support or aeronavery/zig-orm: A database ORM

1 Like