typeorm

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README

TypeORM Reader

Reads TypeScript files containing TypeORM entity definitions and extracts database schema information.

Overview

The TypeORM Reader parses TypeScript source files that define TypeORM entities (classes with TypeORM decorators) and converts them into RelSpec's internal database model representation.

Features

  • Parses TypeORM decorators and entity definitions
  • Extracts table, column, and relationship information
  • Supports various TypeORM column types and options
  • Handles constraints, indexes, and relationships

Usage

Basic Example
package main

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

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

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

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

# Convert TypeORM to GORM models
relspec --input typeorm --in-file User.ts --output gorm --out-file models.go

Example TypeORM Entity

import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  OneToMany,
} from 'typeorm';
import { Post } from './Post';

@Entity('users')
export class User {
  @PrimaryGeneratedColumn('increment')
  id: number;

  @Column({ type: 'varchar', length: 50, unique: true })
  username: string;

  @Column({ type: 'varchar', length: 100 })
  email: string;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;

  @OneToMany(() => Post, (post) => post.user)
  posts: Post[];
}

@Entity('posts')
export class Post {
  @PrimaryGeneratedColumn('increment')
  id: number;

  @Column({ name: 'user_id' })
  userId: number;

  @Column({ type: 'varchar', length: 200 })
  title: string;

  @Column({ type: 'text' })
  content: string;

  @ManyToOne(() => User, (user) => user.posts, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'user_id' })
  user: User;
}

Supported TypeORM Decorators

  • @Entity() - Entity/table definition
  • @PrimaryGeneratedColumn() - Auto-increment primary key
  • @PrimaryColumn() - Primary key
  • @Column() - Column definition
  • @CreateDateColumn() - Auto-set creation timestamp
  • @UpdateDateColumn() - Auto-update timestamp
  • @OneToMany() - One-to-many relationship
  • @ManyToOne() - Many-to-one relationship
  • @JoinColumn() - Foreign key column
  • @Index() - Index definition
  • @Unique() - Unique constraint

Notes

  • Schema name can be specified in @Entity() decorator
  • Supports both JavaScript and TypeScript entity files
  • Relationship metadata is extracted from decorators

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 TypeORM entity files

func NewReader

func NewReader(options *readers.ReaderOptions) *Reader

NewReader creates a new TypeORM reader with the given options

func (*Reader) ReadDatabase

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

ReadDatabase reads and parses TypeORM entity files, returning a Database model

func (*Reader) ReadSchema

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

ReadSchema reads and parses TypeORM entity files, returning a Schema model

func (*Reader) ReadTable

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

ReadTable reads and parses TypeORM entity files, returning a Table model

Jump to

Keyboard shortcuts

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