Skip to content

PantaKoda/DB_scaffold

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataBaseModels

Command-line tool for extracting database metadata and generating models in multiple programming languages.

Requirements

  • Go 1.20+ installed
  • Make (for building with Makefile)
  • SQLite database file for testing

Installation

git clone https://github.com/yourusername/DataBaseModels.git
cd DataBaseModels

make build

Usage

# Show database metadata
./bin/dbmodels -db path/to/database.db

# Export as JSON
./bin/dbmodels -db path/to/database.db -json output.json

# Generate TypeScript models
./bin/dbmodels -db path/to/database.db -target_language typescript -output_dir ./models

# Generate Go models (exclude tables)
./bin/dbmodels -db path/to/database.db -target_language go -exclude "logs,temp_data"

Options

Flag Description
-db Database file path
-json JSON output path
-exclude Tables to exclude (comma-separated)
-target_language Language for models (typescript, go, python)
-output_dir Output directory for generated files

Supported Databases

  • SQLite

Supported Languages

  • TypeScript
  • Go
  • Python

Type Mapping

Database Type TypeScript Go Python
INTEGER number int64 int
TEXT string string str
BLOB Uint8Array []byte bytes
NUMERIC number float64 float
BOOLEAN boolean bool bool
DATETIME Date time.Time datetime.datetime

Testing

# Run all tests
make test

# Unit tests only
make test-unit

# Integration tests
make test-integration

# Generate coverage report
make test-coverage
  • TestConvertToGenerationModels : Tests the conversion of database models to language-specific models for code generation. Verifies table naming, column naming, and type mapping for TypeScript and Go.
  • TestFormatTableName : Tests the function that formats table names according to language conventions (PascalCase for Go/Python, camelCase for TypeScript).
  • TestFormatColumnName : Tests the function that formats column names according to language conventions (PascalCase for Go, camelCase for TypeScript, snake_case for Python).
  • TestParseBaseType : Tests the function that extracts the base SQL data type from more complex type definitions with modifiers, e.g., "VARCHAR(255)" → "VARCHAR".
  • TestGenerateEmptyModel : Tests the code generator's ability to handle empty database models (databases with no tables) without errors.
  • TestGenerateActualModels : Tests the end-to-end code generation process with multiple tables, verifying the output files contain expected content.
  • TestStringToLanguage : Tests the string-to-language conversion function that maps language name strings to the internal Language enum values.

Future Improvements

  • Add PostgreSQL, MySQL, SQL Server support
  • Add Java, C#, Rust language support
  • More tests

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published