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

blov · 2018-02-26 02:30:02 · 596 次点击    
这是一个分享于 2018-02-26 02:30:02 的资源,其中的信息可能已经有所发展或是发生改变。

I have a SQLite database that I would like to export as SQL text. This can be done from the command line with sqlite3 existing_db.db .dump. However, this requires sqlite3 on the system to work. I'd rather do this operation from my Go code directly.

I've been using mattn's go-sqlite3 and have found no solution using that library (I posted an issue about it in case I was mistaken).

In Python, this is very easy to do, you can just use sqlite3's .iterdump(). Is there any equivalent in Go?


评论:

SSoreil:

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.

EDIT: I assumed wrong, it's some sugar implemented in Python, here is the implementation. It makes sense this is not present in the Go version.

https://github.com/python/cpython/blob/3.6/Lib/sqlite3/dump.py

qrv3w:

Thanks! I just followed your link and ported the Python implementation for go-sqlite3: https://github.com/schollz/sqlite3dump.


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

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