<commit_before>package schema

// Schema is the metadata container for a schema definition
type Schema struct {
	Name   string
	Tables map[string]*Table `json:"Tables"`
	// For get ops
	TableAliases map[string]string `json:"TableAliases"`
}

// Table is the metadata container for a SQL table definition
type Table struct {
	// Should dyndao use a LastInsertID() mechanism after INSERTing (or
	// whatever the equivalent is, like with Oracle or PostgreSQL) or will
	// the calling code supply a primary key.
	CallerSuppliesPK bool

	// TODO: Rethink some of this 'MultiKey' stuff.
	MultiKey  bool   `json:"MultiKey"` // Use Primary or Primary + ForeignKeys
	Primary   string `json:"Primary"`
	Name      string `json:"Name"`
	AliasName string `json:"AliasName"` // Combined with AliasName - for set ops

	// MultiKey must be set to true if a table has
	// foreign keys.
	ForeignKeys []string `json:"ForeignKeys"`

	// Columns is the column definitions for the SQL table
	Columns       map[string]*Column `json:"Columns"`
	ColumnAliases map[string]string  `json:"ColumnAliases"`

	EssentialColumns []string `json:"EssentialColumns"`

	JSONCol      string                 // for some syntax sugar
	ParentTables []string               `json:"ParentTables"`
	Children     map[string]*ChildTable `json:"Children"`

	// YAGNI?
	// TODO: ChildrenInsertionOrder?
	// TODO: DeletionOrder?
}

// GetTableName returns either ourDefault or the override string. It is assumed
// that you'll pass in the table key (schema.Tables[key]) and the table name
// (schema.Tables[key].Name), so that this wrapper function can decide.
func GetTableName(override string, ourDefault string) string {
	if override != "" {
		return override
	}
	return ourDefault
}

// Column represents a single column in a SQL table
type Column struct {
	IsSingleTable bool `json:"IsSingleTable"` // Magic to avoid a couple of issues with our MapToString implementation.
	AllowNull     bool `json:"AllowNull"`
	IsNumber      bool `json:"IsNumber"`
	IsJSON        bool
	IsIdentity    bool   `json:"IsIdentity"`
	IsForeignKey  bool   `json:"IsForeignKey"`
	IsUnique      bool   `json:"IsUnique"`
	Length        int    `json:"Length"`
	Name          string `json:"Name"`

	// TODO: DefaultValue isn't implemented anywhere yet.
	DefaultValue string `json:"DefaultValue"` // Converts to integer if IsNumber is set
	DBType       string `json:"DBType"`

	// type-mapping hack for specifying string as destination data type when reading
	// this helps with situations where you might otherwise end up transmitting integers as floats

	MapToString bool `json:"MapToString"`
}

// ChildTable represents a relationship between a parent table
// and a child table
type ChildTable struct {
	ParentTable string

	// TODO: Can I just delete MultiKey and have only
	// LocalColumns/ForeignColumns?  At least for ChildTable, MultiKey
	// seems unnecessary.
	MultiKey      bool
	LocalColumn   string
	ForeignColumn string

	LocalColumns   []string
	ForeignColumns []string
}<commit_msg>cleanup<commit_after>package schema

// Schema is the metadata container for a schema definition
type Schema struct {
	Name   string
	Tables map[string]*Table
	// For get ops
	TableAliases map[string]string
}

// Table is the metadata container for a SQL table definition
type Table struct {
	// Should dyndao use a LastInsertID() mechanism after INSERTing (or
	// whatever the equivalent is, like with Oracle or PostgreSQL) or will
	// the calling code supply a primary key.
	CallerSuppliesPK bool

	MultiKey  bool
	Primary   string
	Name      string
	AliasName string

	ForeignKeys []string

	Columns       map[string]*Column
	ColumnAliases map[string]string

	EssentialColumns []string

	JSONCol      string
	ParentTables []string               `json:"ParentTables"`
	Children     map[string]*ChildTable `json:"Children"`

	// YAGNI?
	// TODO: ChildrenInsertionOrder?
	// TODO: DeletionOrder?
}

// GetTableName returns either ourDefault or the override string. It is assumed
// that you'll pass in the table key (schema.Tables[key]) and the table name
// (schema.Tables[key].Name), so that this wrapper function can decide.
func GetTableName(override string, ourDefault string) string {
	if override != "" {
		return override
	}
	return ourDefault
}

// Column represents a single column in a SQL table
type Column struct {
	IsSingleTable bool
	AllowNull     bool
	IsNumber      bool
	IsJSON        bool
	IsIdentity    bool
	IsForeignKey  bool
	IsUnique      bool
	Length        int
	Name          string

	DefaultValue string
	DBType       string

	MapToString bool
}

// ChildTable represents a relationship between a parent table
// and a child table
type ChildTable struct {
	ParentTable string

	MultiKey      bool
	LocalColumn   string
	ForeignColumn string

	LocalColumns   []string
	ForeignColumns []string
}
{'fraction_non_alphanumeric': 0.07719298245614035, 'fraction_numerical': 0.0, 'mean_word_length': 3.5545112781954886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5898771', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1292, 'n_words': 530}