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:
qrv3w: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
Thanks! I just followed your link and ported the Python implementation for go-sqlite3: https://github.com/schollz/sqlite3dump.
