-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple read-only SQLite databases embedded in Go executables #1188
Conversation
It is unclear to me whether this could run afoul of the rules of cgo. So it might be good to explicitly pin the memory first. Once you do that, it means this new method is not specific to embedded databases per se, but rather can be used as long as you guarantee that the byte slice in question will not be modified. You will, however, need to determine when we can safely unpin the memory. |
I'm relying on go GC never collecting a global since it is always reachable and I'm probably naive in believing it won't move it either. It seems it wouldn't so long as their value doesn't alter, but I will need to research that. It has been a while since I've written go code. You can tell as I mention in the test I don't make the byte array const (you can't in go!). I am certain you can only have a global for |
The Go authors have reserved the right to implement a moving garbage collector in the future, which theoretically could affect global variables. Probably for the best to account for that now to avoid issues down the line. |
I don't think this PR is worth bumping I am fine just patching my go-sqlite for the project I intend to use this feature with for now, and it can be revisited when |
You should be able to use built in build tags to only support the new method in 1.21 instead of updating go.mod. |
I'll update to do that. Looks like the tag is for the whole file so I have some refactoring as well as retesting. Thank you for your suggestion! |
Sorry about the delay in refactor, I'm in the middle of moving. Ready for you to take a look now. |
The deserialize support that was added for #1089 doesn't quite address issue #968. But it comes very close. With this code you can basically follow along with a SO from gizlu. He even provided a working C example.
There is a limit due to SQLite only accepting one "mode=" in the DSN string. The C library would have to provide a Read-only memory option to have a named schema. Right now only "main" can be used, therefore only one embedded DB at a time can be used.