<commit_before>package pq

import (
	"database/sql/driver"
	"encoding/hex"
	"fmt"
	"time"
)

func encode(x interface{}) []byte {
	const timeFormat = "2006-01-02 15:04:05.0000-07"

	switch v := x.(type) {
	case int64:
		return []byte(fmt.Sprintf("%d", v))
	case float32, float64:
		return []byte(fmt.Sprintf("%f", v))
	case []byte:
		return []byte(fmt.Sprintf("\\x%x", v))
	case string:
		return []byte(v)
	case bool:
		return []byte(fmt.Sprintf("%t", v))
	case time.Time:
		return []byte(v.Format(timeFormat))
	default:
		errorf("encode: unknown type for %T", v)
	}

	panic("not reached")
}

func decode(s []byte, typ int) interface{} {
	switch typ {
	case t_bytea:
		s = s[2:] // trim off "\\x"
		d := make([]byte, hex.DecodedLen(len(s)))
		_, err := hex.Decode(d, s)
		if err != nil {
			errorf("%s", err)
		}
		return d
	case t_timestamptz:
		return mustParse("2006-01-02 15:04:05-07", s)
	case t_timestamp:
		return mustParse("2006-01-02 15:04:05", s)
	case t_time:
		return mustParse("15:04:05", s)
	case t_timetz:
		return mustParse("15:04:05-07", s)
	case t_date:
		return mustParse("2006-01-02", s)
	}

	return s
}

func mustParse(f string, s []byte) time.Time {
	str := string(s)
	// Special case until time.Parse bug is fixed:
	// http://code.google.com/p/go/issues/detail?id=3487
	if str[len(str)-2] == '.' {
		str += "0"
	}
	t, err := time.Parse(f, str)
	if err != nil {
		errorf("decode: %s", err)
	}
	return t
}

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

// Scan implements the Scanner interface.
func (nt *NullTime) Scan(value interface{}) error {
	nt.Time, nt.Valid = value.(time.Time)
	return nil
}<commit_msg>Return booleans as bool, not []byte.<commit_after>package pq

import (
	"database/sql/driver"
	"encoding/hex"
	"fmt"
	"time"
)

func encode(x interface{}) []byte {
	const timeFormat = "2006-01-02 15:04:05.0000-07"

	switch v := x.(type) {
	case int64:
		return []byte(fmt.Sprintf("%d", v))
	case float32, float64:
		return []byte(fmt.Sprintf("%f", v))
	case []byte:
		return []byte(fmt.Sprintf("\\x%x", v))
	case string:
		return []byte(v)
	case bool:
		return []byte(fmt.Sprintf("%t", v))
	case time.Time:
		return []byte(v.Format(timeFormat))
	default:
		errorf("encode: unknown type for %T", v)
	}

	panic("not reached")
}

func decode(s []byte, typ int) interface{} {
	switch typ {
	case t_bytea:
		s = s[2:] // trim off "\\x"
		d := make([]byte, hex.DecodedLen(len(s)))
		_, err := hex.Decode(d, s)
		if err != nil {
			errorf("%s", err)
		}
		return d
	case t_timestamptz:
		return mustParse("2006-01-02 15:04:05-07", s)
	case t_timestamp:
		return mustParse("2006-01-02 15:04:05", s)
	case t_time:
		return mustParse("15:04:05", s)
	case t_timetz:
		return mustParse("15:04:05-07", s)
	case t_date:
		return mustParse("2006-01-02", s)
	case t_bool:
		return s[0] == 't';
	}

	return s
}

func mustParse(f string, s []byte) time.Time {
	str := string(s)
	// Special case until time.Parse bug is fixed:
	// http://code.google.com/p/go/issues/detail?id=3487
	if str[len(str)-2] == '.' {
		str += "0"
	}
	t, err := time.Parse(f, str)
	if err != nil {
		errorf("decode: %s", err)
	}
	return t
}

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

// Scan implements the Scanner interface.
func (nt *NullTime) Scan(value interface{}) error {
	nt.Time, nt.Valid = value.(time.Time)
	return nil
}
{'fraction_non_alphanumeric': 0.18165836507471433, 'fraction_numerical': 0.05010254907705831, 'mean_word_length': 3.601078167115903, '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': '848569', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1362, 'n_words': 362}