<commit_before>package sqlkungfu

import (
	"crypto/md5"
	"database/sql"
	"database/sql/driver"
	"fmt"

	"time"
)

type Migration struct {
	Checksum  string
	CreatedAt time.Time
}

type Date time.Time

func (d *Date) Scan(value interface{}) (err error) {
	*d = Date(value.(time.Time))
	return
}

func (d Date) Value() (v driver.Value, err error) {
	v = time.Time(d).Format("2006-01-02")
	return
}

func (d Date) String() string {
	return time.Time(d).Format("2006-01-02")
}

func InitMigration(db *sql.DB) (err error) {
	_, err = db.Exec(`
		CREATE TABLE IF NOT EXISTS sqlkungfu_migrations (
			checksum  varchar(255) NOT NULL Primary Key,
			createdat date
		);
	`)

	return
}

func Exec(db *sql.DB, query string, args ...interface{}) (s Migration, r sql.Result, err error) {
	sum := fmt.Sprintf("%x", md5.Sum([]byte(query)))
	row := db.QueryRow("select * from sqlkungfu_migrations where checksum = ?", sum)
	if err = row.Scan(&s.Checksum, &s.CreatedAt); err == nil {
		return
	} else if err != sql.ErrNoRows {
		return
	}

	if r, err = db.Exec(query, args...); err != nil {
		return
	}

	s.Checksum = sum
	// d := Date(time.Now().Truncate(time.Hour * 24))
	s.CreatedAt = time.Now()
	_, _, err = Insert(db, s, TableName("sqlkungfu_migrations"))

	return
}
<commit_msg>migration: add MustExec<commit_after>package sqlkungfu

import (
	"crypto/md5"
	"database/sql"
	"database/sql/driver"
	"fmt"

	"time"
)

type Migration struct {
	Checksum  string
	CreatedAt time.Time
}

type Date time.Time

func (d *Date) Scan(value interface{}) (err error) {
	*d = Date(value.(time.Time))
	return
}

func (d Date) Value() (v driver.Value, err error) {
	v = time.Time(d).Format("2006-01-02")
	return
}

func (d Date) String() string {
	return time.Time(d).Format("2006-01-02")
}

func InitMigration(db *sql.DB) (err error) {
	_, err = db.Exec(`
		CREATE TABLE IF NOT EXISTS sqlkungfu_migrations (
			checksum  varchar(255) NOT NULL Primary Key,
			createdat date
		);
	`)

	return
}

func Exec(db *sql.DB, query string, args ...interface{}) (m Migration, r sql.Result, err error) {
	sum := fmt.Sprintf("%x", md5.Sum([]byte(query)))
	row := db.QueryRow("select * from sqlkungfu_migrations where checksum = ?", sum)
	if err = row.Scan(&m.Checksum, &m.CreatedAt); err == nil {
		return
	} else if err != sql.ErrNoRows {
		return
	}

	if r, err = db.Exec(query, args...); err != nil {
		return
	}

	m.Checksum = sum
	// d := Date(time.Now().Truncate(time.Hour * 24))
	m.CreatedAt = time.Now()
	_, _, err = Insert(db, m, TableName("sqlkungfu_migrations"))

	return
}

func MustExec(db *sql.DB, query string, args ...interface{}) (m Migration, r sql.Result) {
	m, r, err := Exec(db, query, args...)
	if err != nil {
		panic(err)
	}
	return
}

{'fraction_non_alphanumeric': 0.1671565025716385, 'fraction_numerical': 0.01689933872152829, 'mean_word_length': 3.662671232876712, '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': '2699775', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1049, 'n_words': 270}