<commit_before>package qbit

import (
	"errors"
	"fmt"
	"strings"
)

func NewBuilder() *Builder {
	return &Builder{
		prettyMode: true,
		query:      NewQuery(),
		errors:     []error{},
	}
}

// builder is a subset of dialect could be used for common sql queries
// it has all the common functions except multiple statements & table crudders
type Builder struct {
	prettyMode bool
	query      *Query
	errors     []error
}

// function builds the query clauses and returns the sql and bindings
func (b *Builder) Build() (string, []interface{}, error) {

	if b.HasError() {
		errs := []string{}
		for _, err := range b.errors {
			errs = append(errs, err.Error())
		}
		err := errors.New(strings.Join(errs, "\n"))
		b.errors = []error{}
		return "", nil, err
	}

	var delimiter string

	if b.prettyMode {
		delimiter = "\n"
	} else {
		delimiter = " "
	}

	bindings := b.query.Bindings()
	sql := fmt.Sprintf("%s;", strings.Join(b.query.Clauses(), delimiter))

	b.query = NewQuery()

	return sql, bindings, nil
}

func (b *Builder) AddError(err error) {
	b.errors = append(b.errors, err)
}

func (b *Builder) HasError() bool {
	return len(b.errors) > 0
}

func (b *Builder) questionMarks(values ...interface{}) []string {
	questionMarks := make([]string, len(values))
	for k, _ := range values {
		questionMarks[k] = "?"
	}
	return questionMarks
}

// function generates an "insert into %s(%s)" statement
func (b *Builder) Insert(table string, columns ...string) *Builder {
	clause := fmt.Sprintf("INSERT INTO %s(%s)", table, strings.Join(columns, ", "))
	b.query.AddClause(clause)
	return b
}

// function generates "values(%s)" statement and add bindings for each value
func (b *Builder) Values(values ...interface{}) *Builder {
	b.query.AddBinding(values...)
	clause := fmt.Sprintf("VALUES (%s)", strings.Join(b.questionMarks(values...), ", "))
	b.query.AddClause(clause)
	return b
}

// function generates "update %s" statement
func (b *Builder) Update(table string) *Builder {
	clause := fmt.Sprintf("UPDATE %s", table)
	b.query.AddClause(clause)
	return b
}

// function generates "set a = ?" statement for each key a and add bindings for map value
func (b *Builder) Set(m map[string]interface{}) *Builder {
	updates := []string{}
	for k, v := range m {
		updates = append(updates, fmt.Sprintf("%s = ?", k))
		b.query.AddBinding(v)
	}
	clause := fmt.Sprintf("SET %s", strings.Join(updates, ", "))
	b.query.AddClause(clause)
	return b
}

// function generates "select %s" statement
func (b *Builder) Select(columns ...string) *Builder {
	clause := fmt.Sprintf("SELECT %s", strings.Join(columns, ", "))
	b.query.AddClause(clause)
	return b
}

// function generates "from %s" statement for each table name
func (b *Builder) From(tables ...string) *Builder {
	b.query.AddClause(fmt.Sprintf("FROM %s", strings.Join(tables, ", ")))
	return b
}

// function generates "inner join %s on %s" statement for each expression
func (b *Builder) InnerJoin(table string, expressions ...string) *Builder {
	b.query.AddClause(fmt.Sprintf("INNER JOIN %s ON %s", table, strings.Join(expressions, " ")))
	return b
}

// function generates "cross join %s" statement for table
func (b *Builder) CrossJoin(table string) *Builder {
	b.query.AddClause(fmt.Sprintf("CROSS JOIN %s", table))
	return b<commit_msg>add Delete() function to query builder<commit_after>package qbit

import (
	"errors"
	"fmt"
	"strings"
)

func NewBuilder() *Builder {
	return &Builder{
		prettyMode: true,
		query:      NewQuery(),
		errors:     []error{},
	}
}

// builder is a subset of dialect could be used for common sql queries
// it has all the common functions except multiple statements & table crudders
type Builder struct {
	prettyMode bool
	query      *Query
	errors     []error
}

// function builds the query clauses and returns the sql and bindings
func (b *Builder) Build() (string, []interface{}, error) {

	if b.HasError() {
		errs := []string{}
		for _, err := range b.errors {
			errs = append(errs, err.Error())
		}
		err := errors.New(strings.Join(errs, "\n"))
		b.errors = []error{}
		return "", nil, err
	}

	var delimiter string

	if b.prettyMode {
		delimiter = "\n"
	} else {
		delimiter = " "
	}

	bindings := b.query.Bindings()
	sql := fmt.Sprintf("%s;", strings.Join(b.query.Clauses(), delimiter))

	b.query = NewQuery()

	return sql, bindings, nil
}

func (b *Builder) AddError(err error) {
	b.errors = append(b.errors, err)
}

func (b *Builder) HasError() bool {
	return len(b.errors) > 0
}

func (b *Builder) questionMarks(values ...interface{}) []string {
	questionMarks := make([]string, len(values))
	for k, _ := range values {
		questionMarks[k] = "?"
	}
	return questionMarks
}

// function generates an "insert into %s(%s)" statement
func (b *Builder) Insert(table string, columns ...string) *Builder {
	clause := fmt.Sprintf("INSERT INTO %s(%s)", table, strings.Join(columns, ", "))
	b.query.AddClause(clause)
	return b
}

// function generates "values(%s)" statement and add bindings for each value
func (b *Builder) Values(values ...interface{}) *Builder {
	b.query.AddBinding(values...)
	clause := fmt.Sprintf("VALUES (%s)", strings.Join(b.questionMarks(values...), ", "))
	b.query.AddClause(clause)
	return b
}

// function generates "update %s" statement
func (b *Builder) Update(table string) *Builder {
	clause := fmt.Sprintf("UPDATE %s", table)
	b.query.AddClause(clause)
	return b
}

// function generates "set a = ?" statement for each key a and add bindings for map value
func (b *Builder) Set(m map[string]interface{}) *Builder {
	updates := []string{}
	for k, v := range m {
		updates = append(updates, fmt.Sprintf("%s = ?", k))
		b.query.AddBinding(v)
	}
	clause := fmt.Sprintf("SET %s", strings.Join(updates, ", "))
	b.query.AddClause(clause)
	return b
}

// function generates "delete" statement
func (b *Builder) Delete(table string) *Builder {
	b.query.AddClause(fmt.Sprintf("DELETE FROM %s", table))
	return b
}

// function generates "select %s" statement
func (b *Builder) Select(columns ...string) *Builder {
	clause := fmt.Sprintf("SELECT %s", strings.Join(columns, ", "))
	b.query.AddClause(clause)
	return b
}

// function generates "from %s" statement for each table name
func (b *Builder) From(tables ...string) *Builder {
	b.query.AddClause(fmt.Sprintf("FROM %s", strings.Join(tables, ", ")))
	return b
}

// function generates "inner join %s on %s" statement for each expression
func (b *Builder) InnerJoin(table string, expressions ...string) *Builder {
	b.query.AddClause(fmt.Sprintf("INNER JOIN %s ON %s", table, strings.Join(expressions, " ")))
	return b
}

// function generates "cross join %s" statement for table
func (b *Builder) CrossJoin(table string) *Builder {
	b.query.AddClause(fmt.Sprintf("CROSS JOIN %s", table))
	return b
{'fraction_non_alphanumeric': 0.15897663413191362, 'fraction_numerical': 0.0002957704821058858, 'mean_word_length': 4.073518379594899, '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': '5575467', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2245, 'n_words': 684}