Set up a extension database

Hello everyone. Is there a way to set up a sqlite database for a gnome extension? In that case, how? Is any reference about?

You could use libgom, which is a pretty high-levelwrapper around sqlite. There is a slightly out-of-date example for GJS that you can probably figure out.

Thank you for replying!
I didn’t know about Gom, thanks for the information! Also, I was not necessarily referring to a tool integrated with Gnome, that is a possibility I will analyse carefully. However, I would like to know about the possibility of integrating other tools from JS repositories via a module bundler, for example using Prisma ORM and Rollup. Such a tool needs an environment configuration file with database connection information.

That’s a huge, multi-faceted question, so you’ll have to narrow it down a lot to get a serviceable answer :slightly_smiling_face:

Okay, sorry for the lack of specificity. I was confident that it would be more appropriate to be less specific in order to create a topic that could serve as a reference for others. Anyway, allow me to be more specific: If an extension for gnome requires a SQLite database, where is the most appropriate place for this database to be located? Inside the extension directory itself? Is there a way to create a hook in the gnome-extension to create the database, or should the extension always check for the existence of a database and create one if necessary? Is it appropriate to use an external dependency like Prisma ORM or would that be too expensive for the shell?

1 Like

A better place would probably be ~/.local/share/myextension@domain/index.db, to avoid it being removed on an update.

If your extension is responsible for creating the database, you’d want that as part of your code, definitely. The only hooks you get in extensions are “init”, “enable” and “disable”; everything else is system and user events.

I would expect the bottle-neck is you getting Prisma ORM to actually work in an extension. It may be possible, but I wonder if you really need a sophisticated ORM if you’re goals are not more application than intended to modify the GNOME Shell UX.

As far as performance of Prisma, like most things, it’s unlikely the code will just sit their burning CPU cycles for nothing. Unless you’re calling fuunctions, or it has some scheduled functions it calls, it’s just code hiding behind an if-branch.

Thank you so much for your help. Have a wonderful day!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.