I am curious how does `db get ` know
I am curious, how does
db.get()
know which table to look in? What's the science behind it? Or are all docs just saved in the same table, so to speak, on your servers? I was imagining you use something similar to a shard key or sumething maybe? Or a seeded random generator for the IDs?3 Replies
Looking at this https://github.com/get-convex/convex-js/blob/468847c797229d88c24435ffca2f1e3c6bf6aeae/src/server/impl/database_impl.ts#L28-L40
But not sure what "1.0/db/normalizeId" does.
I believe the IDs encode the table name in them!
IDs encoding the table name is a good way to think of it, although it's not exactly a table name. This level of indirection allows ids to be roughly the same length, and also allows table deletions. If you delete a table and create a new one with the same name, ids from the old table are separate from ids in the new table. The downside is that you can only get the table name from an ID when you have a
db
, which is what db.normalizeId
does