sqlite

package
v1.0.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader implements the readers.Reader interface for SQLite databases

func NewReader

func NewReader(options *readers.ReaderOptions) *Reader

NewReader creates a new SQLite reader

func (*Reader) ReadDatabase

func (r *Reader) ReadDatabase() (*models.Database, error)

ReadDatabase reads the entire database schema from SQLite

func (*Reader) ReadSchema

func (r *Reader) ReadSchema() (*models.Schema, error)

ReadSchema reads a single schema (returns the main schema from the database)

func (*Reader) ReadTable

func (r *Reader) ReadTable() (*models.Table, error)

ReadTable reads a single table (returns the first table from the schema)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL