Files
relspecgo/pkg/readers/sqlite
Hein aba22cb574
Some checks failed
CI / Test (1.25) (push) Failing after -23m58s
CI / Test (1.24) (push) Successful in -23m22s
CI / Lint (push) Successful in -25m3s
CI / Build (push) Successful in -25m15s
Integration Tests / Integration Tests (push) Successful in -25m52s
feat(ui): add relationship management features in schema editor
- Implement functionality to create, update, delete, and view relationships between tables.
- Introduce new UI screens for managing relationships, including forms for adding and editing relationships.
- Enhance table editor with navigation to relationship management.
- Ensure relationships are displayed in a structured table format for better usability.
2026-02-07 09:49:24 +02:00
..
2026-02-07 09:30:45 +02:00
2026-02-07 09:30:45 +02:00

SQLite Reader

Reads database schema from SQLite database files.

Usage

import (
    "git.warky.dev/wdevs/relspecgo/pkg/readers"
    "git.warky.dev/wdevs/relspecgo/pkg/readers/sqlite"
)

// Using file path
options := &readers.ReaderOptions{
    FilePath: "path/to/database.db",
}

reader := sqlite.NewReader(options)
db, err := reader.ReadDatabase()

// Or using connection string
options := &readers.ReaderOptions{
    ConnectionString: "path/to/database.db",
}

Features

  • Reads tables with columns and data types
  • Reads views with definitions
  • Reads primary keys
  • Reads foreign keys with CASCADE actions
  • Reads indexes (non-auto-generated)
  • Maps SQLite types to canonical types
  • Derives relationships from foreign keys

SQLite Specifics

  • SQLite doesn't support schemas, creates single "main" schema
  • Uses pure Go driver (modernc.org/sqlite) - no CGo required
  • Supports both file path and connection string
  • Auto-increment detection for INTEGER PRIMARY KEY columns
  • Foreign keys require PRAGMA foreign_keys = ON to be set

Example Schema

PRAGMA foreign_keys = ON;

CREATE TABLE users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username VARCHAR(50) NOT NULL UNIQUE,
    email VARCHAR(100) NOT NULL
);

CREATE TABLE posts (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id INTEGER NOT NULL,
    title VARCHAR(200) NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);

Type Mappings

SQLite Type Canonical Type
INTEGER, INT int
BIGINT int64
REAL, DOUBLE float64
TEXT, VARCHAR string
BLOB bytea
BOOLEAN bool
DATE date
DATETIME, TIMESTAMP timestamp