<commit_before>// +build !disable_driver_sqlite

package sqlstorage

import (
	"database/sql"
	"fmt"
	"regexp"
	"strings"

	"github.com/facette/maputil"
	"github.com/facette/sliceutil"
	"github.com/jinzhu/gorm"
	"github.com/mattn/go-sqlite3"
	"github.com/pkg/errors"
)

const (
	defaultSqliteDriverPath = "data.db"
)

// sqliteDriver implements the database driver interface for SQLite 3.
type sqliteDriver struct {
	path string
}

func (d sqliteDriver) Name() string {
	return "sqlite3"
}

func (d sqliteDriver) Open() (*sql.DB, error) {
	return sql.Open("sqlite3_ext", d.path)
}

func (d sqliteDriver) Init(db *gorm.DB) error {
	// Enable 'foreign_key' pragma
	return db.Raw("PRAGMA foreign_keys = ON").Error
}

func (d sqliteDriver) NormalizeError(err error) error {
	sqliteErr, ok := err.(sqlite3.Error)
	if !ok {
		return err
	}

	switch sqliteErr.ExtendedCode {<commit_msg>Fix SQLite foreign keys pragma<commit_after>// +build !disable_driver_sqlite

package sqlstorage

import (
	"database/sql"
	"fmt"
	"regexp"
	"strings"

	"github.com/facette/maputil"
	"github.com/facette/sliceutil"
	"github.com/jinzhu/gorm"
	"github.com/mattn/go-sqlite3"
	"github.com/pkg/errors"
)

const (
	defaultSqliteDriverPath = "data.db"
)

// sqliteDriver implements the database driver interface for SQLite 3.
type sqliteDriver struct {
	path string
}

func (d sqliteDriver) Name() string {
	return "sqlite3"
}

func (d sqliteDriver) Open() (*sql.DB, error) {
	return sql.Open("sqlite3_ext", d.path)
}

func (d sqliteDriver) Init(db *gorm.DB) error {
	// Enable 'foreign_key' pragma
	return db.Exec("PRAGMA foreign_keys = ON").Error
}

func (d sqliteDriver) NormalizeError(err error) error {
	sqliteErr, ok := err.(sqlite3.Error)
	if !ok {
		return err
	}

	switch sqliteErr.ExtendedCode {
{'fraction_non_alphanumeric': 0.13175675675675674, 'fraction_numerical': 0.00563063063063063, 'mean_word_length': 4.434250764525994, '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': '3256531', 'n_tokens_mistral': 691, 'n_tokens_neox': 664, 'n_words': 156}