<commit_before>package bongo

import (
	"encoding/json"
	"errors"
	"fmt"
	"strconv"
	"strings"

	"github.com/jinzhu/gorm"
)

// Fetch tries the best option available for retrieving the data first tries
// cache layer, if fails, then tries db
func (b *Bongo) Fetch(i Modellable, id int64) error {
	if id == 0 {
		return IdIsNotSet
	}

	data, ok := i.(Cacher)
	if !ok {
		return errors.New("cacher is not implemented for given struct")
	}

	return b.GetFromBest(i, data, id)
}

// ById Fetches data from db by it's id
func (b *Bongo) ById(i Modellable, id int64) error {
	if err := b.DB.
		Table(i.TableName()).
		Where("id = ?", id).
		Find(i).
		Error; err != nil {
		return err
	}

	return nil
}

// Creates a new record with the given struct and its fields
func (b *Bongo) Create(i Modellable) error {
	if err := b.DB.Save(i).Error; err != nil {
		return err<commit_msg>Bongo: Add UnscopedById method<commit_after>package bongo

import (
	"encoding/json"
	"errors"
	"fmt"
	"strconv"
	"strings"

	"github.com/jinzhu/gorm"
)

// Fetch tries the best option available for retrieving the data first tries
// cache layer, if fails, then tries db
func (b *Bongo) Fetch(i Modellable, id int64) error {
	if id == 0 {
		return IdIsNotSet
	}

	data, ok := i.(Cacher)
	if !ok {
		return errors.New("cacher is not implemented for given struct")
	}

	return b.GetFromBest(i, data, id)
}

// ById Fetches data from db by it's id
func (b *Bongo) ById(i Modellable, id int64) error {
	if err := b.DB.
		Table(i.TableName()).
		Where("id = ?", id).
		Find(i).
		Error; err != nil {
		return err
	}

	return nil
}

func (b *Bongo) UnscopedById(i Modellable, id int64) error {
	if err := b.DB.
		Unscoped().
		Table(i.TableName()).
		Where("id = ?", id).
		Find(i).
		Error; err != nil {
		return err
	}

	return nil
}

// Creates a new record with the given struct and its fields
func (b *Bongo) Create(i Modellable) error {
	if err := b.DB.Save(i).Error; err != nil {
		return err
{'fraction_non_alphanumeric': 0.13536895674300253, 'fraction_numerical': 0.0061068702290076335, 'mean_word_length': 3.2646420824295013, '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': '7306251', 'n_tokens_mistral': 785, 'n_tokens_neox': 742, 'n_words': 249}