4 ms·
As an aside - for anyone working with databases in Go, check out https://pkg.go.dev/modernc.org/sqlite https://pkg.go.dev/modernc.org/sqlite It allows drop in
by koeng 5y ago
As an aside - for anyone working with databases in Go, check out https://pkg.go.dev/modernc.org/sqlite https://pkg.go.dev/modernc.org/sqlite
It allows drop in replacement of SQLite that is in pure Go - no CGO or anything required for compilation, while still having everything implemented from SQLite.
Insert speed is a bit lacking (about ~6x slower in my experience compared to the CGO sqlite3 package), but its good enough for me.
- nickcw 5y agoI hadn't realized it was now ready for general use... SQLite 2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f 0 errors out of 928271 tests on 3900x Linux 64-bit little-endian Whee, I shall have to give it a go - thanks for the heads-up :-)
- pingu2 5y agoSwswsswwzzwwwwwwwwxw
- justinsaccount 5y agoIt's not really pure go, it's transpiled using https://gitlab.com/cznic/ccgo https://gitlab.com/cznic/ccgo Just about all the code looks like this: // Call this routine to record the fact that an OOM (out-of-memory) error // has happened. This routine will set db->mallocFailed, and also // temporarily disable the lookaside memory allocator and interrupt // any running VDBEs. func Xsqlite3OomFault(tls *libc.TLS, db uintptr) { /* sqlite3.c:28548:21: */ if (int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0) && (int32((*Sqlite3)(unsafe.Pointer(db)).FbBenignMalloc) == 0) { (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed = U8(1) if (*Sqlite3)(unsafe.Pointer(db)).FnVdbeExec > 0 { libc.AtomicStoreNInt32((db + 400 /* &.u1 */ /* &.isInterrupted */), int32(1), 0) } (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++ (*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(0) if (*Sqlite3)(unsafe.Pointer(db)).FpParse != 0 { (*Parse)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FpParse)).Frc = SQLITE_NOMEM } } }
- psanford 5y agoBeing translated means it doesn't have the normal cgo calling overhead. It also means you can cross compile it for every platform that the Go toolchain supports without any external compilers.
- throwaway894345 5y agoOP mentioned that the pure-Go version is ~6 times slower, so the cgo calling overhead is clearly made up for by C. Also, I've heard that sqlite is the rare piece of C software that is actually bulletproof, so I don't think the pure-Go version can make the usual boasts about correctness and security in this particular case. Not needing extra external compilers is still a nice proposition, however.
- tgv 5y agoEspecially for portability/cross compiling.
- justinsaccount 5y agoNope, note their readme says: These combinations of GOOS and GOARCH are currently supported darwin amd64, darwin arm64, freebsd amd64, linux 386, linux amd64, linux arm, linux arm64, windows amd64 and if you look at their source tree https://gitlab.com/cznic/sqlite/-/tree/master/lib https://gitlab.com/cznic/sqlite/-/tree/master/lib you can see they have sqlite_darwin_amd64.go sqlite_darwin_arm64.go sqlite_freebsd_amd64.go sqlite_linux_386.go sqlite_linux_amd64.go sqlite_linux_arm.go sqlite_linux_arm64.go sqlite_linux_s390x.go sqlite_windows_386.go sqlite_windows_amd64.go
- therein 5y agoThat's nice and impressive as far as it goes for portability however on the other side, we have C.