<commit_before>package qb

import (
	"fmt"
	"strings"
)

// NewTable generates a new table pointer given table name, column and table constraints
func NewTable(driver string, name string, columns []Column, constraints []Constraint) *Table {
	return &Table{
		name:        name,
		columns:     columns,
		constraints: constraints,
		primaryCols: []string{},
		refs:        []ref{},
		builder:     NewBuilder(driver),
	}
}

// Table is the base abstraction for any sql table
type Table struct {
	name        string
	columns     []Column
	constraints []Constraint
	primaryCols []string
	refs        []ref
	builder     *Builder
}

// Name returns the table name
func (t *Table) Name() string {
	return t.name
}

// SQL generates create table syntax of table
func (t *Table) SQL() string {

	cols := []string{}
	for _, v := range t.columns {
		cols = append(cols, v.SQL(t.builder.Dialect().Driver()))
	}

	constraints := []string{}

	// build primary key constraints using primaryCols
	if len(t.primaryCols) > 0 {
		for k, col := range t.primaryCols {
			t.primaryCols[k] = t.builder.Dialect().Escape(col)
		}
		constraints = append(constraints, fmt.Sprintf("PRIMARY KEY (%s)", strings.Join(t.primaryCols, ", ")))
	}

	// build foreign key constraints using refCols
	for _, ref := range t.refs {
		for k, _ := range ref.cols {
			ref.cols[k] = t.builder.Dialect().Escape(ref.cols[k])
			ref.refCols[k] = t.builder.Dialect().Escape(ref.refCols[k])
		}
		constraints = append(constraints, fmt.Sprintf("FOREIGN KEY (%s) REFERENCES %s(%s)", strings.Join(ref.cols, ", "), t.builder.Dialect().Escape(ref.refTable), strings.Join(ref.refCols, ", ")))
	}

	for _, v := range t.constraints {
		constraints = append(constraints, v.Name)
	}

	query := t.builder.CreateTable(t.name, cols, constraints).Query()

	return query.SQL()
}

// AddColumn appends a new column to current table
func (t *Table) AddColumn(column Column) {
	t.columns = append(t.columns, column)
}

// AddConstraint appends a new constraint to current table
func (t *Table) AddConstraint(c Constraint) {
	t.constraints = append(t.constraints, c)
}

// AddPrimary appends a primary column that will be lazily built as a primary key constraint
func (t *Table) AddPrimary(col string) {
	t.primaryCols = append(t.primaryCols, col)
}

// PrimaryKey returns the primaryCols as a string array
//func (t *Table) PrimaryKey() []string {
//	return t.primaryCols
//}
<commit_msg>cleanup PrimaryKey() function<commit_after>package qb

import (
	"fmt"
	"strings"
)

// NewTable generates a new table pointer given table name, column and table constraints
func NewTable(driver string, name string, columns []Column, constraints []Constraint) *Table {
	return &Table{
		name:        name,
		columns:     columns,
		constraints: constraints,
		primaryCols: []string{},
		refs:        []ref{},
		builder:     NewBuilder(driver),
	}
}

// Table is the base abstraction for any sql table
type Table struct {
	name        string
	columns     []Column
	constraints []Constraint
	primaryCols []string
	refs        []ref
	builder     *Builder
}

// Name returns the table name
func (t *Table) Name() string {
	return t.name
}

// SQL generates create table syntax of table
func (t *Table) SQL() string {

	cols := []string{}
	for _, v := range t.columns {
		cols = append(cols, v.SQL(t.builder.Dialect().Driver()))
	}

	constraints := []string{}

	// build primary key constraints using primaryCols
	if len(t.primaryCols) > 0 {
		for k, col := range t.primaryCols {
			t.primaryCols[k] = t.builder.Dialect().Escape(col)
		}
		constraints = append(constraints, fmt.Sprintf("PRIMARY KEY (%s)", strings.Join(t.primaryCols, ", ")))
	}

	// build foreign key constraints using refCols
	for _, ref := range t.refs {
		for k, _ := range ref.cols {
			ref.cols[k] = t.builder.Dialect().Escape(ref.cols[k])
			ref.refCols[k] = t.builder.Dialect().Escape(ref.refCols[k])
		}
		constraints = append(constraints, fmt.Sprintf("FOREIGN KEY (%s) REFERENCES %s(%s)", strings.Join(ref.cols, ", "), t.builder.Dialect().Escape(ref.refTable), strings.Join(ref.refCols, ", ")))
	}

	for _, v := range t.constraints {
		constraints = append(constraints, v.Name)
	}

	query := t.builder.CreateTable(t.name, cols, constraints).Query()

	return query.SQL()
}

// AddColumn appends a new column to current table
func (t *Table) AddColumn(column Column) {
	t.columns = append(t.columns, column)
}

// AddConstraint appends a new constraint to current table
func (t *Table) AddConstraint(c Constraint) {
	t.constraints = append(t.constraints, c)
}

// AddPrimary appends a primary column that will be lazily built as a primary key constraint
func (t *Table) AddPrimary(col string) {
	t.primaryCols = append(t.primaryCols, col)
}

{'fraction_non_alphanumeric': 0.13739167195096175, 'fraction_numerical': 0.0004227436060029592, 'mean_word_length': 3.7991886409736306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1282040', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1550, 'n_words': 455}