groue
groue on Hacker News
Yes. GRDB encourages Codable because the user can profit from the code generated by the compiler, and this implies that database values are accessed by column name, on top of the Codable runtime, and those layers have a high cost. When necessary it is possible to access database values by position, and in this case GRDB achieves speed of light (performance nearly identical as raw SQLite).
Thank you (GRDB author here).
It is not mentioned in the README of the repository, but SQLiteData wraps GRDB to access the database and get notified of database changes (the meat and butter).
GRDB is by itself a solid "toolkit for SQLite databases, with a focus on application development", with both high levels APIs for everyday coding, and expert SQLite features for the demanding developers. Many apps rely on GRDB alone.
I do, for JSON columns. I store UTF8 strings in SQLite, so that it is easy to see JSON values with a plain `SELECT *`). And I load blobs, because I code in Swift and the standard JSON decoder eats raw UTF8 memory buffers, not strings.
This avoids two useless conversions:
- first from a C string loaded from SQLite to a Swift Unicode string (with UTF8 validation).
- next from this Swift Unicode string to a UTF8 memory buffer (so that JSONDecoder can do its job).
SQLite is smart enough to strip the trailing \0 when you load a blob from a string stored in the database :-)
Yes. Now, many short writes look exactly as one very long write from the point of view of an enqueued write that is waiting for its turn :-) I don't quite remember how fair is SQLite scheduling, in practice.
What's cool with WAL mode is that SQLITE_BUSY won't happen for readers (except very rare scenarios:
https://www.sqlite.org/wal.html#sometimes_queries_return_sql...)
One should only expect SQLITE_BUSY for writes (if a writer is already holding the lock, and the busy timeout expires before the other writer releases the lock). So yes, prefer short writes, or adjust your timeout. Generally speaking, SQLITE_BUSY can not be 100% prevented for writes.
It is always safe, and by "safe" I mean "safe for data". You won't have to deal with data corruption. Precisely, see "How To Corrupt An SQLite Database File":
https://www.sqlite.org/howtocorrupt.htmlNow concurrent accesses from different processes/connections can lead to runtime errors (SQLITE_BUSY), because the database happens to be locked by one connection.
Those errors are greatly reduced by the WAL mode (https://sqlite.org/wal.html) which provides ultra-robust single-writer/multiple-readers semantics:
- Writes can not happen concurrently (SQLITE_BUSY).
- One can reduce the occurrences of such SQLITE_BUSY errors by using a built-in timeout (https://www.sqlite.org/c3ref/busy_timeout.html).
- Several reads can happen concurrently, including with writers.
- A writer connection can enter the "Serializable" isolation level.
- A reader connection can enter the "Snapshot Isolation" level.
For more details, see https://www.sqlite.org/isolation.html
During all the years I've been developing the GRDB library (https://github.com/groue/GRDB.swift), I could never see SQLite fail its documented guarantees. This made it possible to build one of the most concurrency-focused SQLite toolkit for Swift, and I'm pretty happy with it (https://github.com/groue/GRDB.swift/blob/master/Documentatio...).
The music is quite good! The covers of Freddie Freeloader and Flamenco Sketches are quite worth it, IMHO :-)
Posted by
groue on Wednesday December 15, 2021 @06:33AM
from the old.reddit.com dept.
You can try
https://github.com/groue/GRDB.swiftIt's a thin wrapper around SQLite, with convenience APIs for record types, robust support for concurrency, and a focus on GUI apps.
Posted by
groue on Sunday September 20, 2020 @01:59PM
from the forums.swift.org dept.
Posted by
groue on Tuesday May 05, 2020 @11:37AM
from the forums.swift.org dept.
Posted by
groue on Sunday May 03, 2020 @05:35AM
from the forums.swift.org dept.
Posted by
groue on Friday May 24, 2019 @08:36AM
from the forums.swift.org dept.
I often promise myself to have a look at SQLite virtual file system API, for this very purpose, but could not yet find the guts :-)
We start to see ORMs like Diesel (
https://diesel.rs) or GRDB (
http://github.com/groue/GRDB.swift) that radically simplify their domain by removing traditional ORM features like implicit uniquing, lazy-loading, or auto-updates. This of course gives more work to do on the client side. But this work is positive and often simpler than expected. With traditional ORMs, there is still some work to do, which often looks like fights: against misunderstandings, against leaky abstractions, against configuration levels that don't match the needs of application, and generally speaking against the framework.
ORMs are not done yet :-)
I agree. Sometimes, I explain that the feature request can be implemented, but not for free. I flag such issues with the "needs sponsoring" tag.
Posted by
groue on Saturday September 02, 2017 @11:58AM
from the github.com dept.
Unique to GRDB.swift, as far as I know, is the ability to perform database writes and then wait until snapshot isolation has been reached in another connection before releasing the writing lock. This allows to read from a known database state, while allowing other writes to be performed. The ability to read for a precisely known database state allows nice features like database observation and reactive patterns, while taking advantage from the WAL mode by not holding locks longer than necessary.
I'd also like to thank the other for his attempt at raising the general awareness of transaction isolation. Even when you deal with simpler databases like SQLite, isolation is a serious topic. When serializing accesses hinders performances, dealing with the "WAL mode" that grants SQLite with single-writer-multipler-readers abilities is everything but trivial, because of the huge amount of documentation that has to be read in order to reach the desired level of isolation. I've written an SQLite library in Swift that provides
by default the snapshot isolation level which grants most developers with both peace of mind, and non-blocking reads. Check out its "concurrency guide" if you're interested:
https://github.com/groue/GRDB.swift/blob/master/README.md#co...
> They sound similar to change data capture in SQLServer.
Yes. There is a difference, though: SQLite is embedded, and there is zero latency between an application and its database.
This means that change notifications can be emitted synchronously right after a committed transaction, allowing the application to process the change before any other change could be performed.
This makes it much easier to get a very robust solution for a whole class of database synchronization problems.
Posted by
groue on Wednesday May 03, 2017 @06:38AM
from the medium.com dept.
Sure, and French don't have a word for "entrepreneur" neither