Is there a Golang equivalent of Python's sqlite3 .iterdump() for dumping a SQLite database to SQL text?

blov · · 338 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have a SQLite database that I would like to export as SQL text. This can be done from the command line with <code>sqlite3 existing_db.db .dump</code>. However, this requires <code>sqlite3</code> on the system to work. I&#39;d rather do this operation from my Go code directly.</p> <p>I&#39;ve been using mattn&#39;s <a href="https://github.com/mattn/go-sqlite3">go-sqlite3</a> and have found no solution using that library (<a href="https://github.com/mattn/go-sqlite3/issues/535">I posted an issue about it in case I was mistaken</a>).</p> <p>In Python, this is very easy to do, you can just use <a href="https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.iterdump">sqlite3&#39;s .iterdump()</a>. Is there any equivalent in Go? </p> <hr/>**评论:**<br/><br/>SSoreil: <pre><p>It sounds like there simply is no Go binding for that call. Depending on how tricky it is to implement you can write the Go to C binding yourself for this one. That is of course assuming the Python function is backed by the C implementation.</p> <p>EDIT: I assumed wrong, it&#39;s some sugar implemented in Python, here is the implementation. It makes sense this is not present in the Go version.</p> <p><a href="https://github.com/python/cpython/blob/3.6/Lib/sqlite3/dump.py" rel="nofollow">https://github.com/python/cpython/blob/3.6/Lib/sqlite3/dump.py</a></p></pre>qrv3w: <pre><p>Thanks! I just followed your link and ported the Python implementation for <a href="https://github.com/mattn/go-sqlite3">go-sqlite3</a>: <a href="https://github.com/schollz/sqlite3dump">https://github.com/schollz/sqlite3dump</a>.</p></pre>

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

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