drizzle

package
v1.0.12 Latest Latest
Warning

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

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

README

Drizzle Reader

Reads TypeScript/JavaScript files containing Drizzle ORM schema definitions and extracts database schema information.

Overview

The Drizzle Reader parses Drizzle ORM schema files (TypeScript/JavaScript) that define database tables using Drizzle's schema builder and converts them into RelSpec's internal database model representation.

Features

  • Parses Drizzle schema definitions
  • Extracts table, column, and relationship information
  • Supports various Drizzle column types
  • Handles constraints and indexes

Usage

Basic Example
package main

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

func main() {
    options := &readers.ReaderOptions{
        FilePath: "/path/to/schema.ts",
    }

    reader := drizzle.NewReader(options)
    db, err := reader.ReadDatabase()
    if err != nil {
        panic(err)
    }

    fmt.Printf("Found %d schemas\n", len(db.Schemas))
}
CLI Example
# Read Drizzle schema and convert to JSON
relspec --input drizzle --in-file schema.ts --output json --out-file schema.json

# Convert Drizzle to GORM models
relspec --input drizzle --in-file schema/ --output gorm --out-file models.go

Example Drizzle Schema

import { pgTable, serial, varchar, text, timestamp, integer } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';

export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  username: varchar('username', { length: 50 }).notNull().unique(),
  email: varchar('email', { length: 100 }).notNull(),
  createdAt: timestamp('created_at').notNull().defaultNow(),
});

export const posts = pgTable('posts', {
  id: serial('id').primaryKey(),
  userId: integer('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
  title: varchar('title', { length: 200 }).notNull(),
  content: text('content'),
});

export const usersRelations = relations(users, ({ many }) => ({
  posts: many(posts),
}));

export const postsRelations = relations(posts, ({ one }) => ({
  user: one(users, {
    fields: [posts.userId],
    references: [users.id],
  }),
}));

Notes

  • Supports both PostgreSQL and MySQL Drizzle schemas
  • Extracts relationship information from relations definitions
  • Schema defaults to public for PostgreSQL

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 Drizzle schema format

func NewReader

func NewReader(options *readers.ReaderOptions) *Reader

NewReader creates a new Drizzle reader with the given options

func (*Reader) ReadDatabase

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

ReadDatabase reads and parses Drizzle schema input, returning a Database model

func (*Reader) ReadSchema

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

ReadSchema reads and parses Drizzle schema input, returning a Schema model

func (*Reader) ReadTable

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

ReadTable reads and parses Drizzle schema input, returning a Table model

Jump to

Keyboard shortcuts

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