<p>I'm looking for a simple embeddable database for a cross platform desktop app. Nothing fancy, but it should be able to do simple queries, sorting and pagination (is that fancy?).</p>
<p>I'm trying to avoid sqlite, for various reasons.</p>
<p>Blotdb is simple and great, I like it a lot, but it's key/value only. If I want to query and sort some entities by date added, then I have to denormalize the data, and I'm trying to avoid that complexity.</p>
<p>Using Boltdb with Bleve is another option which would bring much better query support. Unfortunately, Bleve itself only support sorting for search rank only.</p>
<p>Any other options you could suggest?</p>
<hr/>**评论:**<br/><br/>aaaqqq: <pre><p>Can you share some reasons why sqlite can't be used. The reason I'm asking this is that sqlite is usually the best choice for the use case you've mentioned.</p></pre>m3wm3wm3wm: <pre><p>These are not hard reasons, but the ones I have:</p>
<ul>
<li>Adding sqlite means distributing native libs per OS.</li>
<li>Our binary size is important, sqlite may or may not be bigger than Boltdb.</li>
<li>Migrations. We need a system to ensure up to date migrations for clients. This can be done, but with schema free solutions like Boltdb this is much more painless. You just need to check your model at unmarshalling point and decide what to do.</li>
</ul></pre>DualRearWheels: <pre><ul>
<li>no it doesn't. statically compile sqlite with you program for all platforms, cross compilation works nicely with windows/linux/mac</li>
<li>sqlite adds ~500kb on already huge Go binary (min 3mb, most likely 5-10mb) and 130ns per C call which is insignificant</li>
<li>you are trading one kind of work with other kind. if you think that key value store will keeps things simple and fast - it will, right up to when you need to extract/search/update data on some criteria. then you realize you have to build all these things in you program, and wish you have relational database which could do it all for you where you only write SQL query. same thing with migrations/db structure. but this is only my 2c after doing 10+ years of commercial software with all of these.</li>
</ul>
<p>SQLite is best, smallest, most versatile and most reliable choice in any way for this kind of job.</p></pre>itsmontoya: <pre><p>Sqlite is your best choice for a query-based db which is embedded.</p></pre>aaaqqq: <pre><p>The application will anyways have to be built for each OS separately. Using sqlite shouldn't change anything on that front especially since Go can cross compile applications. For sqlite, you'll just need to install the platform specific build tools which is quite straightforward. </p>
<p>I'm not sure I understand the second point. </p>
<p>Migrations are definitely easier with schema free solutions. However, it's not that complicated with a sql database (especially if the database isn't too big). The only problem with sqlite might be that you won't be able to drop columns. However, that shouldn't be a hard to overcome.</p></pre>m3wm3wm3wm: <pre><p>Could you elaborate how to cross compile when embedding a native library like sqlite?</p>
<blockquote>
<p>For sqlite, you'll just need to install the platform specific build tools which is quite straightforward.</p>
</blockquote>
<p>What are these tools? For example, how to cross compile when targeting Windows and building on OS X?</p></pre>aaaqqq: <pre><p>Check the FAQ section here: <a href="https://github.com/mattn/go-sqlite3#faq" rel="nofollow">https://github.com/mattn/go-sqlite3#faq</a> </p>
<p>One of the links from that section: <a href="http://www.limitlessfx.com/cross-compile-golang-app-for-windows-from-linux.html" rel="nofollow">http://www.limitlessfx.com/cross-compile-golang-app-for-windows-from-linux.html</a> </p>
<p>The link is for Linux -> Windows but the method should work for OS X -> windows too. You basically need to install mingw and then use the appropriate flags while compiling. </p>
<p>Note: I have actually done this for Ubuntu -> Windows and know it works fine.</p></pre>m3wm3wm3wm: <pre><p>Thanks. Does that mean that there is no cross compilation luck with things like gonative, gox or goxc when using sqlite?</p>
<p>I have not tried the limitlessfx way yet, but that post is a bit old.</p></pre>cs-guy: <pre><p>Maybe <a href="https://github.com/cznic/ql" rel="nofollow">https://github.com/cznic/ql</a> would work for you.</p></pre>Sphax: <pre><p>I feel your pain with sqlite, can't easily cross compile and you need a compiler on Windows if you want to build there.</p>
<p>Personnally I used boltdb in some projects and I think it fits your use case well. I'd say bite the bullet and build your own abstraction on top of bolt to do what you need; it'll probably be small enough. For sorting I'd do what you said, load all the data and sort in memory with sort.Sort.</p>
<p>This totally depends on the size of your database though. Sorting 1Gib in memory is probably not gonna end well.</p></pre>kylewolfe: <pre><p>Can you elaborate on what you mean by denormalize the data? How much data are you talking about?</p>
<p>You know that a value in a key/value store such as BoltDB can be anything, right? This would include values from any encoding library of your choosing: <a href="https://github.com/alecthomas/go_serialization_benchmarks" rel="nofollow">https://github.com/alecthomas/go_serialization_benchmarks</a></p>
<p>I'm actually building my own "abstraction" for BoltDB like this for small embedded use cases. I hope to add in some more advanced features eventually for educational purposes (maybe querying, $lookup function, indexes, etc). Have a look but I wouldn't recommend using it yet. <a href="https://github.com/kylewolfe/rumble" rel="nofollow">https://github.com/kylewolfe/rumble</a></p></pre>m3wm3wm3wm: <pre><blockquote>
<p>Can you elaborate on what you mean by denormalize the data? How much data are you talking about?</p>
</blockquote>
<p>For example, to sort by date, I need to make another collection with the date as the key, so that I can query by date.</p></pre>kylewolfe: <pre><p>You can make the key a custom UID that starts with the date created. Though, yes, if you wanted to sort by something else other than date, you'd have to create another bucket (to utilize b tree indexing), or if the data set is small enough, sort it yourself.</p></pre>
Any pure Go embeddable database for a desktop app which supports basic querying and sorting?
blov · · 696 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传