Learning project #3: database metadata

Having already learned a lot after chess and my lemming-game (soon on github) I would like to create a third project which I already programmed in c# and I am actually using for my job: like database conversions, documentation generator, sql-scripting, etc.
It is for ms sql-server only, so planning to use Tiberius for this project.
There are two main area's in here. I only will ask about #1 for now.

I get the metadata from a database and make a structure of that like here:

Metadata
    all_tables (list)
    all_fields (list)
    all_foreignkeys (list)
    all_indexes (list)
    all_constraints (list)
Table
    owner_metadata
    fields
    indexes
    // more
Field
    owner_table
    data_type
    max_length
    primarykey
    used_in_indexes
Index
    owner_table
    fields
// etc...

We can imagine how that happens in c#. lots of owner / parent hierarchies and object references all over the place. The Metadata object holds a flat list of all entities like tables, fields. etc.
So question 1 is: what would be a nice Rusty way to accomplish this without the object reference spaghetti?

The typical options with Rust tend to be

  1. Restructure the data to avoid the spaghetti. This is of course not always possible, but dodges the problem.
  2. Use Rc or Arc and their weak variants and avoid strong reference cycles. This also requires some cell type for mutability.
  3. Replace the reference spaghetti with an index spaghetti. This is essentially like having weak references everywhere and crates like slotmap help a lot.

Which one you choose depends on how you need to process the data, so it may be easier to give more suggestions with more details. A tip is also to use free functions a lot to avoid borrowing self of various objects more than necessary.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.