Show HN: A Database Written in Golang
35 comments
·February 26, 2025bob1029
If you are wanting proper SQL command support, you could copy the SQLite parser approach. Properly parsing all valid command texts is not a problem that I would find compelling unless I was being compensated for it.
https://www.sqlite.org/lemon.html
You could probably use something like participle, but you'd have to translate the grammar.
Sahil121
yes man have to work on adding the sql cmd support thanks for the links
twalla
Someone asked about resources and I ran into this while evaluating embedded db options for a golang project - it's a collection of db components implemented in golang:
tjungblut
thank you for referring, feel free to ask any questions you may have
mbreese
This looks like a good exploratory project!
One thing I’d add to the readme is an example of how you’d use the database in an example application. From the docs, it’s clear that this isn’t a sql database (yet?), so it would be good to have an example to see how to use the database.
It might also be nice to have a description of what happens when you insert or get a record, so others can learn from the code too. Or can you comment here about what your favorite part of the code is? What did you figure out that you didn’t know before? If you’re using the project to learn about databases, what have you learned so far?
voodooEntity
I didnt look into it yet but i already wanted to say - cuz of curiosity i build my own graph database in golang :) and i learned alot. so i absolutly understand why you did it and what experiences you probably made on the way :D
congratz !
pighive
Nice, did you follow a course or any resources to build it? Please share, I have a similar goal. Thank you.
rebelmackerel
I took a quick glance at the code, I believe it may build upon "Build Your Own Database From Scratch in Go" [0]. The first part of the book is available for free on the author's website, along with information on how to purchase the full book (which includes source code).
I share the same goal and am working through the material after working through Codecrafters' "Build your own SQLite" [1]. Good luck!
I apologize in advance for mistakes (formatting, et cetera). I just registered this account to point you toward resources I found helpful.
littlemerman
You might be interested in this golang db from mit’s database systems course:
https://github.com/MIT-DB-Class/go-db-2024 https://dsg.csail.mit.edu/6.5830/
faizhalde
excellent, would love to hear more about resources you used while implementing
null
eatonphil
If folks would like to see more examples of databases built to teach oneself, they get shared on the /r/databasedevelopment subreddit not infrequently.
Some recent ones:
https://www.reddit.com/r/databasedevelopment/comments/1hyig8...
https://www.reddit.com/r/databasedevelopment/comments/1ha5cc...
https://www.reddit.com/r/databasedevelopment/comments/1dqgms...
https://www.reddit.com/r/databasedevelopment/comments/1ix5dz...
https://www.reddit.com/r/databasedevelopment/comments/18knod...
https://www.reddit.com/r/databasedevelopment/comments/1h3w70...
https://www.reddit.com/r/databasedevelopment/comments/1gk18n...
https://www.reddit.com/r/databasedevelopment/comments/1bemf9...
https://www.reddit.com/r/databasedevelopment/comments/1iw6cx...
seafoamteal
Hi Phil, I thought I'd find you here! Love your blog!
danhau
Nice, thanks! I didn‘t know there was a subreddit for that.
null
whalesalad
How do you connect to it and actually use it? Does it behave like a SQL database? Row-based? Column-based? Good for analytical workloads? Document store? Redis/memcached database? What are it's strengths or weaknesses?
Cool accomplishment in and of itself but hard for anyone here to really give you any criticism or feedback without understanding where it excels and how to work with it.
maxmcd
It does not seem to speak SQL:
$ git clone git@github.com:Sahilb315/AtomixDB.git
Cloning into 'AtomixDB'...
$ cd AtomixDB/
$ go run .
Welcome to AtomixDB
Available Commands:
CREATE - Create a new table
INSERT - Add a record to a table
DELETE - Delete a record from a table
GET - Retrieve a record from a table
UPDATE - Update a record in a table
BEGIN - Begin new transaction
COMMIT - Commit transaction
ABORT - Rollback transaction
EXIT - Exit the program
> create
Enter table name: foo
Enter column names (comma-separated): bar,baz
Enter column types (comma-separated as numbers): 1,2
Enter indexes (format: col1+col2,col3, ... or leave empty):
Table 'foo' created successfully.
> get
Enter table name: foo
Select query type:
1. Index lookup (primary/secondary key)
2. Range query
3. Column filter
Enter choice (1, 2 or 3):
It looks like records are stored in rows: https://github.com/Sahilb315/AtomixDB/blob/64c95afa8e574595c...I do find the source to be well organized and quite readable. Especially if you runs the commands in the cli and then trace how they are each implemented.
zsoltkacsandi
> Main focus was on implementing & understanding working the of database
I think this clearly describes what was the goal.
whalesalad
Yep... but there are dozens of different types of databases out there. There is no way to look at this codebase and give any kind of feedback one way or the other without that understanding, particularly with zero usage examples. Which is what the OP is asking about.
jasonlotito
> There is no way to look at this codebase and give any kind of feedback
Less than a minute and I know how to use it. It's not complicated. The source code is available and fairly easy. If you can't figure out how to use it in a trivial amount of time, you aren't going to be able to offer anything of value. When did HN go from being about interesting stuff to making bold, ignorant statements like "There is no way to look at this codebase and give any kind of feedback one way or the other without that understanding."
You should know better.
null
esafak
[flagged]
anonzzzies
"Main focus was on implementing & understanding working the of database, storage management & transaction handling."
Obviously OP wrote it to understand database theory & implementation.
null
ajsnigrutin
It's hackernews, basically every old thing has to be reinvented in the "language of the week", be it go, rust, ruby, or whatever was before that.
From a learning perspective, nice project for OP, for 'advertising' it, i'd prefer the "what's better than the alternatives" instead of focusing on the language.
pjmlp
That a database written in an AOT compiled managed language is possible, for example.
Specially relevant, because it used to be that writing database engines used to be considered systems programming, and we all know managed languages cannot be possible used for such tasks. /s
null
Recently created a minimal persistent relational database in Go. Main focus was on implementing & understanding working the of database, storage management & transaction handling. Use of B+ Tree for storage engine(support for indexing), managing a Free List (for reusing nodes), Support for transactions, Concurrent Reads. Still have many things to add & fix like query processing being one of the main & fixing some bugs
Repo link - https://github.com/Sahilb315/AtomixDB
Would love to hear your thoughts