I want to implements simple columnar-storage database engine using Odin just for learning purposes. Odin has SoA types, seems like a good match for this purpose, but i have a problem, i can represent table headers as struct, and table as dynamic SoA types, but i cannot generate a struct with dynamic members from the parser since Odin doesn’t support metaprogramming.
the commands CREATE TABLE mytable (id INT, username TEXT, email TEXT)
should be generate like this:
myheaders :: struct {
id: i32,
username: string,
email: string,
}
mytables: #soa[dynamic]myheaders
and then, that can be stored in-memory or using disk.
is there a way to implement this without metaprogramming?
So there are a few things here which might sound weird but bear with:
- Generating a struct from another language (in this case SQL), is honestly BEST solved with a metaprogram in the first place. Make a program to convert them across. Especially when that table is probably not going to change that much in practice.
- However, it is probably a BAD idea to do this directly because the layout of the struct might not even be similar to that of that database, and you might want more or less fields in comparison.
#soa
might not be needed for you whatsoever and I’d only use it IFF you can prove it is needed.
#soa
might not even be the memory layout of the SQL database or how the driver for the database works, so converting between the layouts might be unhelpful.
3 Likes