<commit_before>package gomodel

import (
	"database/sql"
	"log"
)

type (
	// cacheItem keeps the sql and prepared statement of it
	cacheItem struct {
		sql  string
		stmt *sql.Stmt
	}

	// Cacher store all the sql, statement by sql type and id
	// typically, the sql id of predefied sql type is
	// fields << numField( of Model) | whereFields,
	// it's used for a single model
	//
	// if custom is necessary, call cache.ExtendType(cache.Types()+1) to make
	// a new type, the sql id is bring your owns, also you can still use the standard
	// FieldIdentity(fields, whereFields) if possible
	Cacher struct {
		cache []map[uint]cacheItem // [type]map[id]{sql, stmt}
		db    *DB
	}
)

const (
	// These are five predefined sql types
	INSERT uint = iota
	DELETE
	UPDATE
	SELECT_LIMIT
	SELECT_ONE
	defaultTypeEnd
)

var (
	// Types defines the default sql types count, it's default applied to all
	// models.
	// Change it before register any models.
	Types    = defaultTypeEnd
	printSQL = func(_ bool, _ string) {}
)

// SQLPrint enable sql print for each operation
func SQLPrint(enable bool, formatter func(formart string, v ...interface{})) {
	if enable {
		if formatter == nil {
			formatter = log.Printf
		}
		printSQL = func(fromcache bool, sql string) {
			formatter("[SQL]CachedSQL:%t, sql:%s\n", fromcache, sql)
		}
	}
}

// NewCacher create a common sql and statement cacher with given types count
// this will make no parameter checks
//
// the DB instance and each TypeInfo already embed a Cacher, typically, it's not
// necessary to call this
func NewCacher(types uint, db *DB) *Cacher {
	c := &Cacher{
		cache: make([]map[uint]cacheItem, types),
		db:    db,
	}
	for i := uint(0); i < types; i++ {
		c.cache[i] = make(map[uint]cacheItem)
	}
	return c<commit_msg>add a ID help for generate sql id<commit_after>package gomodel

import (
	"database/sql"
	"log"
	"sync/atomic"
)

type (
	// ID help for generate sql id
	ID int32

	// cacheItem keeps the sql and prepared statement of it
	cacheItem struct {
		sql  string
		stmt *sql.Stmt
	}

	// Cacher store all the sql, statement by sql type and id
	// typically, the sql id of predefied sql type is
	// fields << numField( of Model) | whereFields,
	// it's used for a single model
	//
	// if custom is necessary, call cache.ExtendType(cache.Types()+1) to make
	// a new type, the sql id is bring your owns, also you can still use the standard
	// FieldIdentity(fields, whereFields) if possible
	Cacher struct {
		cache []map[uint]cacheItem // [type]map[id]{sql, stmt}
		db    *DB
	}
)

const (
	// These are five predefined sql types
	INSERT uint = iota
	DELETE
	UPDATE
	SELECT_LIMIT
	SELECT_ONE
	defaultTypeEnd
)

var (
	// Types defines the default sql types count, it's default applied to all
	// models.
	// Change it before register any models.
	Types    = defaultTypeEnd
	printSQL = func(_ bool, _ string) {}
)

// SQLPrint enable sql print for each operation
func SQLPrint(enable bool, formatter func(formart string, v ...interface{})) {
	if enable {
		if formatter == nil {
			formatter = log.Printf
		}
		printSQL = func(fromcache bool, sql string) {
			formatter("[SQL]CachedSQL:%t, sql:%s\n", fromcache, sql)
		}
	}
}

// NewID create a id generator used for StmtById, normally, one ID is enough,
// it's safety used for all models
//
// Example:
// sqlid := gomodel.NewID
//
// sqlidUserUpdate := slqid.New()
// sqlidUserDelete := sqlid.New()
// sqlidBookUpdate := sqlid.New()
// sqlidBookDelete := sqlid.New()
//
func NewID() *ID {
	var i int32 = 0
	return (*ID)(&i)
}

// New generate a new sql id
func (i *ID) New() uint {
	return uint(atomic.AddInt32((*int32)(i), 1))
}

// NewCacher create a common sql and statement cacher with given types count
// this will make no parameter checks
//
// the DB instance and each TypeInfo already embed a Cacher, typically, it's not
// necessary to call this
func NewCacher(types uint, db *DB) *Cacher {
	c := &Cacher{
		cache: make([]map[uint]cacheItem, types),
		db:    db,
	}
	for i := uint(0); i < types; i++ {
		c.cache[i] = make(map[uint]cacheItem)
	}
	return c
{'fraction_non_alphanumeric': 0.11595979406717333, 'fraction_numerical': 0.003432213777886737, 'mean_word_length': 3.299262381454162, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1228576', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1355, 'n_words': 506}