SQL DDL から Golang GORM 構造体モデル生成ツール
SQLのCREATE TABLEスキーマからGORMタグ、JSONタグ、適切なGo型マッピングを備えたGolang構造体(struct)モデルを瞬時に自動生成します。
// Code generated by ToolsAA SQL to Golang GORM Generator. DO NOT EDIT.
package models
import (
"github.com/google/uuid"
"gorm.io/datatypes"
"gorm.io/gorm"
"time"
)
// ============================================================================
// Custom Enum Definitions
// ============================================================================
type UserRole string
const (
UserRoleOwner UserRole = "OWNER"
UserRoleAdmin UserRole = "ADMIN"
UserRoleMember UserRole = "MEMBER"
UserRoleGuest UserRole = "GUEST"
)
type SubscriptionTier string
const (
SubscriptionTierFree SubscriptionTier = "FREE"
SubscriptionTierPro SubscriptionTier = "PRO"
SubscriptionTierEnterprise SubscriptionTier = "ENTERPRISE"
)
// Organization maps to database table "organizations"
type Organization struct {
ID *uuid.UUID `gorm:"column:id;primaryKey;type:uuid;default:gen_random_uuid()" json:"id,omitempty"`
Slug string `gorm:"column:slug;type:varchar(80);not null;uniqueIndex:idx_organizations_slug" json:"slug"`
Name string `gorm:"column:name;type:varchar(120);not null" json:"name"`
Tier SubscriptionTier `gorm:"column:tier;type:varchar(64);not null;default:FREE" json:"tier"`
MaxSeats int `gorm:"column:max_seats;not null;default:5" json:"max_seats"`
IsActive bool `gorm:"column:is_active;type:boolean;not null;default:true" json:"is_active"`
Settings *datatypes.JSON `gorm:"column:settings;type:jsonb" json:"settings,omitempty"`
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"deleted_at,omitempty"`
}
// TableName specifies the database table name for Organization
func (Organization) TableName() string {
return "organizations"
}
// User maps to database table "users"
type User struct {
ID *uuid.UUID `gorm:"column:id;primaryKey;type:uuid;default:gen_random_uuid()" json:"id,omitempty"`
OrganizationID uuid.UUID `gorm:"column:organization_id;type:uuid;not null;index:idx_users_org" json:"organization_id"`
Email string `gorm:"column:email;type:varchar(255);not null;uniqueIndex:idx_users_email" json:"email"`
FullName *string `gorm:"column:full_name;type:varchar(120)" json:"full_name,omitempty"`
Role UserRole `gorm:"column:role;type:varchar(64);not null;default:MEMBER" json:"role"`
AvatarURL *string `gorm:"column:avatar_url;type:varchar(500)" json:"avatar_url,omitempty"`
IsVerified bool `gorm:"column:is_verified;type:boolean;not null;default:false" json:"is_verified"`
Preferences *datatypes.JSON `gorm:"column:preferences;type:jsonb" json:"preferences,omitempty"`
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"deleted_at,omitempty"`
Organization *Organization `gorm:"foreignKey:OrganizationID;references:ID;constraint:OnDelete:CASCADE" json:"organizations,omitempty"`
}
// TableName specifies the database table name for User
func (User) TableName() string {
return "users"
}
// AuditLog maps to database table "audit_logs"
type AuditLog struct {
ID *int64 `gorm:"column:id;primaryKey;autoIncrement;type:bigint" json:"id,omitempty"`
OrganizationID uuid.UUID `gorm:"column:organization_id;type:uuid;not null" json:"organization_id"`
UserID *uuid.UUID `gorm:"column:user_id;type:uuid" json:"user_id,omitempty"`
Action string `gorm:"column:action;type:varchar(100);not null;index:idx_audit_logs_action" json:"action"`
IPAddress *string `gorm:"column:ip_address;type:varchar(45)" json:"ip_address,omitempty"`
UserAgent *string `gorm:"column:user_agent;type:text" json:"user_agent,omitempty"`
Payload *datatypes.JSON `gorm:"column:payload;type:jsonb" json:"payload,omitempty"`
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
Organization *Organization `gorm:"foreignKey:OrganizationID;references:ID;constraint:OnDelete:CASCADE" json:"organizations,omitempty"`
User *User `gorm:"foreignKey:UserID;references:ID;constraint:OnDelete:SET NULL" json:"users,omitempty"`
}
// TableName specifies the database table name for AuditLog
func (AuditLog) TableName() string {
return "audit_logs"
}
正確なメモリ配置、プリミティブ型サイジング、慣用的なフィールドタグを備えた純粋な Go 構造体。
primaryKey、foreignKey、autoIncrement、uniqueIndex、カスタム TableName() メソッドを完全サポート。
ポインタ型または sql.Null* 型を設定可能で、nil ポインタ参照によるパニックを防止。
完全ローカルのプライバシーサンドボックス
すべての SQL AST 解析と Golang コード生成はブラウザのメモリ内で 100% 実行されます。外部への送信は一切ありません。
高精度なマルチ方言 GORM v2 対応
PostgreSQL(UUID, JSONB, TIMESTAMPTZ)、MySQL(AUTO_INCREMENT, DATETIME, Decimal)、SQLite(INTEGER PK)を網羅。
本番導入可能な Go パッケージ構成
Go の慣用略語(ID, URL, UUID)対応、GORM リポジトリ CRUD メソッド、トランザクションヘルパー、フック関数を出力。