展示HN:GEDB – 一个纯Go语言的嵌入式数据库
你好,HN!<p>在过去的几个月里,我一直在致力于我的第一个开源项目:一个用纯 Go 编写的嵌入式数据库。这花了我几个月的时间,因为我需要学习如何处理如此庞大的包。在此之前,我制作的所有包都相对较小,并不需要太多的关注。直到这个项目,我通常不需要担心像内存分配优化和实例池这样的事情。<p>这个项目的起始点是我想将一个工具移植到 TUI 环境。实际上,我习惯于在 Go 语言中使用 TUI,因此这是我选择的语言。我想要移植的工具是用 TypeScript 编写的,并使用 NeDB(用 JavaScript 编写)作为数据库。由于我更喜欢使用编译语言,所以我决定创建自己的数据库,确保它与 NeDB 兼容,这就是我在过去几个月所做的。<p>这就是 GEDB 的诞生。它是一个类似于 MongoDB 的嵌入式数据库,使用纯 Go 编写。它支持 MongoDB 的一部分有用查询选项(如 $lt、$exists、$in、$where 等关键字)。默认情况下,它使用仅内存存储,但可以轻松初始化为数据文件。<p>我包中的所有内容都可以进行依赖注入,因为一切都由接口控制。序列化、查询语法、文档结构、索引等等,都可以通过实现接口来替换。<p>我还考虑采用一种新的文档模型,通过创建一种二进制类型(类似 BSON)来大幅降低创建、维护和复制文档的成本(目前它们是 map[string]any)。<p>该项目目前处于早期阶段,版本为 0.1.0,因此我暂时可以对 API 进行更改,直到我准备好发布 1.x.x 版本。<p>如果你们能查看一下并给出反馈,我将非常高兴。任何问题、建议或星标都非常欢迎。<p>我的代码库可以在我的 GitHub 上找到:<a href="https://github.com/vinicius-lino-figueiredo/gedb" rel="nofollow">https://github.com/vinicius-lino-figueiredo/gedb</a>
查看原文
Hello HN!<p>These last few months I've been working on my first open source project: an embedded database written in pure-go. That took me some months, as I had to learn how to deal with such large packages. Until then, all packages I had made were quite small an did not require much. I usually did not have to worry about things like allocation optimization and instance pools until This project.<p>It started when I wanted to make a port of a tool to a TUI environment. I'm actually used to working with TUIs in golang, so that was my language of choice. The tool I wanted to port is written in TypeScript and uses NeDB (written in JavaScript) as database. Since I feel more comfortable working with compiled languages, I decided to create my own database, making sure it was compatible with NeDB, and that's what I did for the last few months.<p>And that's how GEDB was created. It's a mongodb-like embedded database, written in pure-go. It supports a subset of useful querying options of MongoDB (keywords like $lt, $exists, $in, $where, etc.). By default, it uses a in-memory-only storage, but can easily initialized with a data file.<p>Everything in my package can be dependency injected, as everything is controlled interfaces. Serialization, querying syntax, document structure, indexing and more, all can be replaced by implementing an interface.<p>I've also been considering adopting a new document model, by creating a binary type (like BSON) to reduce drastically the cost of creating, maintaining and copying documents (they currently are map[string]any).<p>The project is currently in an early stage, version 0.1.0, so I'm okay with making changes to the API for now, until I'm ready to release version 1.x.x<p>I would be really glad if you guys could check it out and give some feedback. An issue, suggestion or a star are very welcome.<p>My repository can be found on my github: <a href="https://github.com/vinicius-lino-figueiredo/gedb" rel="nofollow">https://github.com/vinicius-lino-figueiredo/gedb</a>