Embeddable DB using *zero* cgo, 100% golang only?

polaris · · 3016 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m building a project that will launch a service running on localhost. That service needs to be able to talk to a localized, embedded database. Basically I&#39;ll be submitting REST requests to that service, and that service will then do something with a local database - saved to local disk for privacy and other project reasons - and then do something else.</p> <p>Anyway, I wanted to use SQLite, but the problem is that there&#39;s CGO involved there with all the sqlite implementations I&#39;ve seen. I need to be able to cross compile this and run it on Windows as well as OS X and Linux, and with CGO being a limitation, even though I can compile it in 32-bit mode, I feel like that&#39;s just asking for trouble down the line. Not to mention, compiling it for Windows looks like one hell of a challenge.</p> <p>So two questions for my fellow gophers out there:</p> <ol> <li>Is there a SQLite or other SQL-like (with index and transaction support) embeddable golang DB out there I can use that has no CGO?</li> <li>If not, what would you recommend? I prefer to use SQL or at the very least, something ACID-compliant. Can&#39;t risk losing data or having info out of sync.</li> </ol> <p>Much appreciated, all. Thank you.</p> <p>EDIT: I should also say that if I can&#39;t find something SQL-based, I&#39;m okay with &#34;NoSQL&#34; as long as the language/DB supports ad-hoc queries like SQL does. I&#39;m also OK with building my own indexes based on what I need, kind of like you&#39;d do with Redis. (Only problem is I don&#39;t see a way to build and run Redis from within Go, nor do I see a distributable Redis for Windows.)</p> <p>EDIT 2: I&#39;ve already experimented with ledisdb, bolt and ql. I&#39;m not a fan of them and really, really want to use SQLite if I can. I&#39;m posting this in case my searching hasn&#39;t found something else that the community knows about for whatever reason. But if there just plain IS nothing else, then I guess bolt/ledis/ql it may be. Opinions on those are appreciated.</p> <hr/>**评论:**<br/><br/>NotEnoughBears: <pre><p>How about BoltDB?</p> <p>Disclaimer: K/V store, not a true database in the relational sense. Does transactions, don&#39;t think it does indexes. </p> <p><a href="https://github.com/boltdb/bolt">https://github.com/boltdb/bolt</a></p></pre>superduperdud3: <pre><p>This might be, perhaps in combination with ledisdb, my only option. Hoping there&#39;s a golang-only sqlite library out there but I might just plain be SOL. Thanks for trying to help!</p></pre>NotEnoughBears: <pre><p>Odds aren&#39;t in your favour I&#39;m afraid - there&#39;s a large difference in manhours between linking a library and rewriting it from scratch.</p> <p>Sqlite has years of effort behind it, don&#39;t know if there&#39;s a strong desire to duplicate that.</p></pre>superduperdud3: <pre><p>Yeah, and re-implementing it definitely bears with it a great deal of risk. Just because the standard is fleshed out well doesn&#39;t mean that a re-implemented codebase in another language will be &#34;bulletproof&#34; or all that solid. Agree that odds aren&#39;t in my favor!</p> <p>Are there any other SQL-based embedded DBs you know of beyond SQLite? I&#39;ve been looking lately at Firebird embedded, but I have to distribute application binaries :/</p></pre>divoxx: <pre><p>What about <a href="https://github.com/google/cayley" rel="nofollow">https://github.com/google/cayley</a> ?</p></pre>superduperdud3: <pre><p>Haven&#39;t seen this one before - I&#39;ll take a look at it, thanks!</p></pre>barakmich: <pre><p>Cayley author here. I like Bolt, as I hand a lot of the semantics off to the backend. Happy to talk at length about indices and graph data though! </p></pre>superduperdud3: <pre><p>Thanks! Truth be told I&#39;ve never used a graphing database so this is uncharted territory for me. Most of my experience is in web services with MySQL and/or PostgreSQL, but the concept of graphs and graph-based relations does sound rather intriguing (and enticing). I may ping you privately if I go this route. Much appreciated!</p></pre>peterhellberg: <pre><p>How about ql?</p> <p><a href="https://github.com/cznic/ql/">https://github.com/cznic/ql/</a></p> <p>(Or tiedot)</p></pre>superduperdud3: <pre><p>I took a quick look at ql and tiedot already, but thanks for the input!</p></pre>nowayno: <pre><blockquote> <p>I need to be able to cross compile this and run it on Windows as well as OS X and Linux, and with CGO being a limitation, even though I can compile it in 32-bit mode, I feel like that&#39;s just asking for trouble down the line. Not to mention, compiling it for Windows looks like one hell of a challenge.</p> </blockquote> <p>Can you elaborate on why it&#39;s so onerous to use CGO and compile for Windows and OS X? Perhaps it&#39;s not as much of a problem as you think, and at any rate I&#39;d be interested to know what the issues are.</p></pre>superduperdud3: <pre><p>The only example I&#39;ve seen of doing a cross-compile on Linux targeting Windows is here:</p> <p><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>I&#39;ve used this guy&#39;s method once before and it <em>did</em> compile a 32-bit version of the binary including SQLite, although there was a warning message about compiling a 64-bit version, saying that it wasn&#39;t possible. </p> <p>Now, I&#39;m not very familiar with cross-compilation, especially the limitations of doing so on one platform targeting another, and especially in C/C++. With being new to golang, I figure it&#39;s better to focus on ONE workflow/toolchain rather than spreading myself thin on learning golang and its idiosyncracies as well as that of g++/gcc and compiling golang AND that stuff together.</p> <p>Now, if there&#39;s a much simpler way to handle this that you can point me at, I&#39;m definitely interested.</p> <p>Good question here - thanks for asking it.</p></pre>nowayno: <pre><p>After further investigation it looks like it is indeed a hellishly convoluted process (though if you could simplify and automate it, you&#39;d be a hero to many). I&#39;ve found cross-compilation to be really easy with Go, and I&#39;ve been using SQLite extensively <strong>on OS X only</strong>, and for some reason it never occurred to me that these two pleasurable experiences would be nigh impossible to combine. Now I&#39;m kind of bummed…</p> <p>What was it that turned you off with ql? I&#39;ve never used it, but it seems like if you&#39;re using their database/sql driver it would be basically identical to the experience of using the database/sql driver for SQLite (albeit without having the full power of SQLite at your disposal).</p></pre>superduperdud3: <pre><p>Good question. Basically, the QL docs say (copy/pasta):</p> <blockquote> <p>QL is a SQL-like language. It is less complex and less powerful than SQL (whichever specification SQL is considered to be).</p> </blockquote> <p>The problem here, for me, is an unknown. I don&#39;t know how QL differs, specifically, from other SQL databases. I don&#39;t know what features it&#39;s lacking that I may need through the life of the project, and I really don&#39;t want to make the mistake of going with a data store that I&#39;ll have to distribute an &#34;upgrade&#34; for later on to migrate data out of one and into another.</p></pre>pollodelamuerte: <pre><p>The ngrok dude talks a lot about building cross platform tools for go. He&#39;s done some talks about it, though it mostly boils down to &#34;build on target platform for target platform&#34;. So maybe just roll with some VMs that are set up with GCC and all that business.</p> <p>You might be able to get some free Windows VMs from Microsoft that are used for browser testing. Perhaps you can use those to try it out? Though I heard they have timers in them so they shut down after a while.</p></pre>superduperdud3: <pre><p>I&#39;ve got a Windows 8.1x64 host I could build on, but I have -no idea- how to build CGO binaries on Windows. Though I&#39;m sure that&#39;s traveled territory by now so I can do the google. ;-) I appreciate the input here, though - thank you!</p></pre>anoland: <pre><p>Perhaps reconsider the embedded requirement? SQLite binaries already exist for windows. Your REST server could just connect to that as the backend data store.</p> <p>I&#39;m guessing you really want to minimize your installation steps, but that may be untenable considering your goals.</p></pre>superduperdud3: <pre><p>I&#39;ve thought through this as well, but I don&#39;t know for sure how to distribute the application and installer such that it&#39;ll have the right binaries together on Windows and register it as a service on startup, etc. However, maybe you&#39;re right - perhaps I need to get off my posterior and look that up anyway. Thanks man.</p></pre>THEHIPP0: <pre><p>The problem with SQLite is, that there isn&#39;t a protocol the driver needs to implement. Since SQLite operates only locally it would be required to reimplement everything from SQLite in Go to get a pure cgo free solution.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

3016 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传