The experimental directory of `beancount` has some code for converting beancount data structures into SQL structures [1].
You could also take a look at the data structures used by GNU Ledger (e.g. account [2]) and transcribe them to SQL. A bit more work, but probably educational.