Convert Sqlite to Postgresql

can i use PostgreSQL instead of SQLite?. i tried to change that but not sure how to proceed. first, i found all backed operations in the Anki Deck is handled by Rust. so i tried to create a Postgresql DB connection in rust (failed due to the Postgres repo missing in bazel). after that i found, to use any library in rust in Anki Deck i need to add that in the build process (added a library in cargo file and also mentioned it in lib.rs file). even after that Bazel can’t build the file successfully. so my question are

  1. it’s possible to convert SQLite to PostgreSQL?
  2. if possible, can we change a bazel build process to add a rust library

Your question is a bit weird because you just ask if it is possible to use PostgreSQL instead of SQLite and, even though Anki will never use PostgreSQL instead SQLite (because it would make no sense), it is perfectly possible for you to fork Anki to create a postgresql version for your own use (or share it, if you want to), just as it is possible to add new dependencies in a bazel build. If you couldn’t use PostgreSQL, or could not add dependencies to bazel, that would somehow defeat their purpose, wouldn’t it?

So, I assume your actual question is something else. I can only guess it might be either:

  • “will it ever happen in Anki?”, or
  • “how can I do it?”

In the first case, the answer is no. PostgreSQL is though for much bigger databases than Anki’s. Typically, you would install a single PostgreSQL server system-wide, and each application would have its own account, with its databases. This is waaaaaay overkill for Anki, and it’s quite unreasonable to require every Anki user to setup its own PostgreSQL server.

In the second case, would you mind adding some more details about what you did exactly? If I understand correctly what you’ve done, you have already worked out everything in the source code, you are just troubled by the build system, isn’t it?

If I did not understand what your question was about, please add more details.

Also, I am somehow curious about why you would require changing the backend database.

2 Likes

I want to change the backend DB to PostgreSQL, instead of SQLite in Anki. so i can perform some analytical operations with it. i am not familiar with Rust and Bazel, but have some basic knowledge in python. The actucal problam i am facing is in Bazel build process, i don’t know how to add a rust library in Bazel build. first, i tried to add the rust-postgres library. but it hades some dependency. after that, i found that i need to add the dependency for rust-postgres library in bazel. i need some help with adding a rust library in bazel build process.

if the rust library is successfully built, i can handle it after that.

PostgreSQL may well offer some advantage; but it seems doubtful that the massive effort required to retool the Anki backend would be worth the effort compared to the effort required to extract the required analytical data from the sqlite3 database.

3 Likes

If your goal is to run SQL on Anki’s database, wouldn’t SQLite Studio do it?
Just connect to the base and run SQLs

I found that cargo, bazel, etc, files need to be changed (by adding rust Postgres library)
can anyone tell me the steps that need to be followed, to change the Rust backend DB(SQLite to PostgreSQL)?

You are probably not getting any answer here because your question is mainly about how to use Bazel to do something probably no other Anki user ever dreamed of doing. As Bazel is quite complex on its own, I would recommend trying to learn a bit about it, and maybe asking on a specialized forum, you’re more likely to get some help there.

2 Likes

Besides that, I don’t want to discourage you but Anki’s build system is legendary hard. Literally. Among the packagers of my distribution, the Anki package is known for being extremely hard to package, and only the most experienced try (and fail) to package it. If you really have never used Bazel before, I realistically think you’re going to take some time before achieving substituting SQLite with PostgreSQL. Maybe it would be worth learning how to achieve your end goal through SQLite instead?

1 Like

You’re overstating things somewhat. The difficulties they face are partly because it’s not something they have previous experience with, and partly because they’re trying to swap out all the dependencies Anki is pinned to with different ones.

In any case, Anki was designed to work with SQLite, and switching the DB backend will not be trivial.

3 Likes

Actually, in the case of the packagers I’ve spoken to, the major issue was neither that they didn’t have experience with Bazel (as my distribution provides tools to automatically package Bazel stuff) nor that they would swap out the version of the dependencies (on the contrary, with Nix — the package manager in question — you can pin any version of any package pretty much like in Bazel, so it’s likely that they kept the same versions).

The real issue were, apparently, the assumptions the build system made about the overall system, and the fact that it’s hard to make Bazel understand these assumptions are not true, or, in case it’s just impossible, it’s hard to “wrap” the build system with something that makes it work anyways, even if these assumptions are not true.

I don’t think I’ve overstate the current situation, but maybe it was poor wording. It’s not necessarily Anki’s build system that is legendary hard, it’s more it’s packaging. People really have a hard time wrapping their head around it.