-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Postgres types, guarantee resolution before usage #1810
Conversation
a384267
to
c61947a
Compare
I was able to advance on this PR and the hardest part should be done. The This aspect is important: it allows to insert types in any order into the registry. When a type is added, we create a This also means that at every point in time, we know which dependencies need to be resolved: this is what drives queries to the database. I still need to implement this part, but it should be relatively simple. I also need to add more tests and improve diagnostics. Note: a previous version performed the checks when reading the type information, but the current design with generators allows to compute the check once at insertion. I expect way more reads than type insertions so this is the better trade-off. |
I started the work in my PR by focusing on types. However, by working on it, it seems that the core of issue is synchronization of the catalog between the local program and remote database. Caching and analyzing type information is only part of it. Following this, I am renaming the main struct from |
c83c1b3
to
bdd485c
Compare
bdd485c
to
2e659e4
Compare
Some updates: I also started work on integrating my changes into the rest of SQLx by replacing the fields My current challenge regarding the integration with SQLx is somewhat related to the previous one. There is a single |
@demurgos it's been a while, do you have any interest in finishing this? We can earmark it for 0.7.0 so you can make breaking changes if necessary. |
Hey 👋 |
I am sharing my progress while refactoring the Postgres types (see #1797).
The main idea is to split
PgType
as it's too general. The new model has the following hierarchy:PgBuiltinType
: Any type from the default catalog, natively known by SQLxPgType
: A fully resolved type, corresponds to builtin types + resolved custom typesPgLazyType
: A type that may not be resolved yet, corresponds to fully resolved types + DeclaredBy{Name|Oid}I also started implementing the
TypeRegistry
struct to replace the ad-hoc per-connection cache. Since it contains all resolved types, it should providePgType
known to be fully resolved (including subtypes).