Dllb.Schema (Dllb v0.1.0)

Copy Markdown View Source

Bootstraps the dllb database schema for code intelligence use.

Provides functions that generate all DEFINE TABLE, DEFINE FIELD, and DEFINE INDEX statements needed for the ast_node table and its indexes. The bootstrap/1 function accepts a query execution function, decoupling schema definition from the connection pool.

Summary

Functions

Returns all schema statements (table definitions + index definitions) in order.

Returns the list of query strings to define all indexes on the ast_node table.

Returns the list of query strings to define the ast_node table and its 11 fields.

Executes all schema DEFINE statements through the given query function.

Functions

all_statements()

@spec all_statements() :: [String.t()]

Returns all schema statements (table definitions + index definitions) in order.

ast_node_indexes()

@spec ast_node_indexes() :: [String.t()]

Returns the list of query strings to define all indexes on the ast_node table.

Indexes:

  • idx_kind - btree on kind
  • idx_language - btree on language
  • idx_file_path - btree on file_path
  • idx_source_embedding - HNSW 768-dim COSINE on source_embedding
  • idx_structure_embedding - HNSW 384-dim COSINE on structure_embedding
  • idx_source_text - fulltext on source_text
  • idx_docstring - fulltext on docstring

ast_node_table()

@spec ast_node_table() :: [String.t()]

Returns the list of query strings to define the ast_node table and its 11 fields.

Fields:

  • kind (string, required) - the Metastatic node type
  • name (string) - symbol/identifier name
  • language (string, required) - source language
  • file_path (string, required) - absolute file path
  • line_start (int) - starting line number
  • line_end (int) - ending line number
  • source_text (string) - raw source text
  • signature (string) - function/method signature
  • docstring (string) - documentation string
  • source_embedding (array) - 768-dim source code embedding
  • structure_embedding (array) - 384-dim structural embedding

bootstrap(query_fn)

@spec bootstrap((String.t() -> {:ok, any()} | {:error, any()})) ::
  {:ok, :bootstrapped} | {:error, any()}

Executes all schema DEFINE statements through the given query function.

The query_fn must have the signature (String.t() -> {:ok, any()} | {:error, any()}). Returns {:ok, :bootstrapped} on success or {:error, reason} on the first failure.

Examples

iex> Dllb.Schema.bootstrap(fn query -> send(self(), {:query, query}); {:ok, %{}} end)
{:ok, :bootstrapped}