go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Calling "icu_load_collation" and connections and concurrency

Open gerricom opened this issue 2 months ago • 1 comments

I need to apologize upfront: This is going to be kind of a noob question, because I'm not yet understanding all bits and pieces. I'll really appreciate it, if someone could give me some insights.

I'm currently building a little web application with a sqlite3 database. I'm living in Germany and some of the later users are used to some sorting conventions for strings here. So I build my app with sqlite_icu and then I can call SELECT icu_load_collation('de_DE', 'german_ai_ci', 'PRIMARY') to register my collation and use it later for sorting.

This works as planned as long as I do this in a little CLI script. When using my web app setup with GORM, this won't work reliable and some queries fail with no such collation sequence: german_ai_ci- but not all of them. So I learned that I can have multiple connections and my SELECT runs only in one of them. That brings me to some questions:

  • It seems to be a stupid idea to limit the open connections via db.SetMaxOpenConns(1)... or am I wrong?
  • What other options do I have? I guess it is not that wise to run icu_load_collation before every SELECT statement...?
  • Are there any "after open connection" events/hooks/younameit I can use to issue that load function?

gerricom avatar Oct 06 '25 16:10 gerricom