<commit_before>package twitter

import (
	"database/sql"

	"github.com/remeh/smartwitter/log"
	"github.com/remeh/smartwitter/storage"

	"github.com/lib/pq"
)

type tweetDAO struct {
	DB *sql.DB
}

// ----------------------

var dao *tweetDAO

func TweetDAO() *tweetDAO {
	if dao != nil {
		return dao
	}

	dao = &tweetDAO{
		DB: storage.DB(),
	}

	if err := dao.InitStmt(); err != nil {
		log.Error("Can't prepare TweetDAO")
		panic(err)
	}

	return dao
}

func (d *tweetDAO) InitStmt() error {
	var err error
	return err
}

func (d *tweetDAO) Upsert(t *Tweet) error {
	if _, err := d.DB.Exec(`
		INSERT INTO "tweet" ("uid", "creation_time", "last_update", "twitter_id", "twitter_creation_time", "text", "twitter_user_uid", "retweet_count", "favorite_count", "lang", "keywords", "link")
		VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
		ON CONFLICT ("uid") DO UPDATE SET
			"creation_time" = $2,
			"last_update" = $3,
			"twitter_id" = $4,
			"twitter_creation_time" = $5,<commit_msg>twitter: tweetdao: do not upsert creation_time.<commit_after>package twitter

import (
	"database/sql"

	"github.com/remeh/smartwitter/log"
	"github.com/remeh/smartwitter/storage"

	"github.com/lib/pq"
)

type tweetDAO struct {
	DB *sql.DB
}

// ----------------------

var dao *tweetDAO

func TweetDAO() *tweetDAO {
	if dao != nil {
		return dao
	}

	dao = &tweetDAO{
		DB: storage.DB(),
	}

	if err := dao.InitStmt(); err != nil {
		log.Error("Can't prepare TweetDAO")
		panic(err)
	}

	return dao
}

func (d *tweetDAO) InitStmt() error {
	var err error
	return err
}

func (d *tweetDAO) Upsert(t *Tweet) error {
	if _, err := d.DB.Exec(`
		INSERT INTO "tweet" ("uid", "creation_time", "last_update", "twitter_id", "twitter_creation_time", "text", "twitter_user_uid", "retweet_count", "favorite_count", "lang", "keywords", "link")
		VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
		ON CONFLICT ("uid") DO UPDATE SET
			"last_update" = $3,
			"twitter_id" = $4,
			"twitter_creation_time" = $5,
{'fraction_non_alphanumeric': 0.1975062344139651, 'fraction_numerical': 0.018453865336658354, 'mean_word_length': 3.569476082004556, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6395851', 'n_tokens_mistral': 899, 'n_tokens_neox': 839, 'n_words': 200}