Générateur de Modèles Struct Golang GORM depuis SQL DDL
Convertissez vos schémas SQL CREATE TABLE en définitions de structures (struct) Golang avec balises GORM, balises JSON et typage Go précis.
// 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"
}
Structures Go pures avec agencement mémoire optimal et tags de champs idiomatiques.
Prise en charge complète de primaryKey, foreignKey, autoIncrement et TableName().
Types pointeurs ou sql.Null* configurables pour éliminer les paniques de pointeurs nuls.
Confidentialité 100% Côté Client
Toutes les analyses SQL et la génération Go s'exécutent localement en mémoire dans votre navigateur.
Précision Multi-Dialectes GORM v2
Correspondance fine des types pour PostgreSQL (UUID, JSONB), MySQL et SQLite.
Architecture Prête pour la Production
Génère des packages Go complets avec sigles idiomatiques (ID, URL, UUID), méthodes CRUD et hooks.