Documentation

DocGen4.DB

Writing the Database #

This file defines WriteDB, the interface for populating the database. Lake runs one single command per module (and genCore for Init/Std/Lake/Lean), each of which writes to the shared SQLite database through WriteDB. Later, the fromDb command reads everything back via ReadDB (defined in DocGen4.DB.Read) and generates HTML.

WriteDB and ReadDB are separate types because writers and readers have different needs. The database schema lives in DocGen4.DB.Schema.

Module Item Positions #

Within a module, each item (declaration, module doc, constructor) is assigned a sequential Int64 position starting from 0. This position serves as the item's identity within the module: the composite key (module_name, position) is the primary key for most tables. Positions are assigned in the order items appear in the module's members array, with constructors and structure fields interleaved between their parent declarations. For example, a module containing a module doc, a definition, and an inductive with two constructors might have positions:

0: module doc 1: definition 2: inductive 3: constructor 1 (of the inductive at position 2) 4: constructor 2 (of the inductive at position 2)

The position counter is a mutable Int64 in updateModuleDb. Structures consume extra positions for their constructor and fields. The read side reconstructs module members by querying name_info and module_docs_markdown ordered by position.

Changing the Schema #

When adding a new column or table:

  1. Add the DDL in DocGen4.DB.Schema (the ddl string in getDb).
  2. Add a prepared statement to WriteStmts and its prepare method below.
  3. Add a WriteStmts.saveXyz method with positional bind calls that match the SQL.
  4. Expose it through WriteDB (the structure at the top of this file) and the mutex wrapper in ensureWriteDb.
  5. Add a prepared statement and loader to ReadStmts in DocGen4.DB.Read.
  6. If the change affects serialized blob types, check that there is an update serializedCodeTypeDefs in DocGen4.DB.Schema so the type hash invalidates stale databases. Otherwise, assess the risk of users getting old databases and consider adding another invalidation.

A write-only database handle. Used during the analysis phase to populate the database.

Instances For
    Equations
    Instances For
      @[implicit_reducible]
      Equations
      • One or more equations did not get rendered due to their size.
      @[implicit_reducible]
      Equations
      • One or more equations did not get rendered due to their size.
      @[implicit_reducible]
      Equations
      • One or more equations did not get rendered due to their size.
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        Instances For
          @[reducible, inline]
          abbrev DocGen4.DB.DBM (α : Type) :
          Equations
          Instances For
            def DocGen4.DB.DBM.run {α : Type} (values : DocstringValues) (dbFile : System.FilePath) (act : DBM α) :
            IO α
            Equations
            Instances For
              def DocGen4.DB.withDB {α : Type} (f : WriteDBDBM α) :
              DBM α
              Equations
              Instances For
                def DocGen4.DB.withSQLite {α : Type} (f : SQLiteDBM α) :
                DBM α
                Equations
                Instances For

                  Open a database for reading only.

                  Read operations are protected by a Std.Mutex internally (see mkReadDB), so a single ReadDB can be shared across tasks without corrupting state. However, sharing serializes all reads through one SQLite connection. For parallel workloads, each task should call openForReading to get its own connection.

                  Equations
                  Instances For

                    DB Reading #

                    Context needed for cross-module linking, without loading full module contents.

                    Instances For

                      Load the linking context from the database.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        def DocGen4.updateModuleDb (values : DB.DocstringValues) (doc : Process.AnalyzerResult) (buildDir : System.FilePath) (dbFile : String) (sourceUrl? : Option String) :
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For