<commit_before>package dba

import (
	"database/sql"
	"fmt"
	"go/format"
	"strings"
)

func Generate(db *sql.DB, tableName, pkgName, structName string, tags bool) ([]byte, error) {
	columns, err := columnInformation(db, tableName)
	if err != nil {
		return []byte{}, err
	}

	src := fmt.Sprintf("package %s\ntype %s %s\n}",
		pkgName,
		structName,
		generateFields(columns, tags))
	formatted, err := format.Source([]byte(src))
	if err != nil {
		err = fmt.Errorf("error formatting: %s, was formatting\n%s", err, src)
	}
	return formatted, err
}

type column struct {
	Name string
	Type string
}

func columnInformation(db *sql.DB, table string) ([]column, error) {
	columns := []column{}
	rows, err := db.Query(`
		select column_name, data_type from information_schema.columns 
		where table_name = $1 order by column_name`, table)
	if err != nil {
		return columns, err
	}
	defer rows.Close()
	for rows.Next() {
		var c column
		err := rows.Scan(&c.Name, &c.Type)
		if err != nil {
			return columns, err
		}
		columns = append(columns, c)
	}
	return columns, rows.Err()
}

var postgresDataTypes = map[string]string{
	"boolean":           "bool",
	"string":            "string",
	"double precision":  "float64",
	"integer":           "int",
	"character varying": "string",
	"text":              "string",
	"timestamp with time zone":    "time.Time",
	"timestamp":                   "time.Time",
	"timestamp without time zone": "time.Time",
}

// commonInitialisms is a set of common initialisms.
// Only add entries that are highly unlikely to be non-initialisms.
// For instance, "ID" is fine (Freudian code is rare), but "AND" is not.
var commonInitialisms = map[string]bool{
	"API":   true,
	"ASCII": true,
	"CPU":   true,
	"CSS":   true,
	"DNS":   true,
	"EOF":   true,
	"GUID":  true,
	"HTML":  true,
	"HTTP":  true,
	"HTTPS": true,
	"ID":    true,
	"IP":    true,
	"JSON":  true,<commit_msg>Add support for mapping to dates<commit_after>package dba

import (
	"database/sql"
	"fmt"
	"go/format"
	"strings"
)

func Generate(db *sql.DB, tableName, pkgName, structName string, tags bool) ([]byte, error) {
	columns, err := columnInformation(db, tableName)
	if err != nil {
		return []byte{}, err
	}

	src := fmt.Sprintf("package %s\ntype %s %s\n}",
		pkgName,
		structName,
		generateFields(columns, tags))
	formatted, err := format.Source([]byte(src))
	if err != nil {
		err = fmt.Errorf("error formatting: %s, was formatting\n%s", err, src)
	}
	return formatted, err
}

type column struct {
	Name string
	Type string
}

func columnInformation(db *sql.DB, table string) ([]column, error) {
	columns := []column{}
	rows, err := db.Query(`
		select column_name, data_type from information_schema.columns 
		where table_name = $1 order by column_name`, table)
	if err != nil {
		return columns, err
	}
	defer rows.Close()
	for rows.Next() {
		var c column
		err := rows.Scan(&c.Name, &c.Type)
		if err != nil {
			return columns, err
		}
		columns = append(columns, c)
	}
	return columns, rows.Err()
}

var postgresDataTypes = map[string]string{
	"boolean":           "bool",
	"string":            "string",
	"double precision":  "float64",
	"integer":           "int",
	"character varying": "string",
	"text":              "string",
	"date":              "time.Time",
	"timestamp with time zone":    "time.Time",
	"timestamp":                   "time.Time",
	"timestamp without time zone": "time.Time",
}

// commonInitialisms is a set of common initialisms.
// Only add entries that are highly unlikely to be non-initialisms.
// For instance, "ID" is fine (Freudian code is rare), but "AND" is not.
var commonInitialisms = map[string]bool{
	"API":   true,
	"ASCII": true,
	"CPU":   true,
	"CSS":   true,
	"DNS":   true,
	"EOF":   true,
	"GUID":  true,
	"HTML":  true,
	"HTTP":  true,
	"HTTPS": true,
	"ID":    true,
	"IP":    true,
	"JSON":  true,
{'fraction_non_alphanumeric': 0.15602284527518173, 'fraction_numerical': 0.001557632398753894, 'mean_word_length': 3.3146696528555433, 'pattern_counts': {'":': 45, '<': 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': '3979323', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1346, 'n_words': 408}