// Code generated by go generate; DO NOT EDIT.
package db

import (
	"encoding/json"
	stdsql "database/sql"
	"time"

	"github.com/sorintlab/errors"
	sq "github.com/huandu/go-sqlbuilder"

	"agola.io/agola/internal/sqlg/sql"

	types "agola.io/agola/services/configstore/types"
)
var (
	remoteSourceInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inAPIURL string, inSkipVerify bool, inType types.RemoteSourceType, inAuthType types.RemoteSourceAuthType, inOauth2ClientID string, inOauth2ClientSecret string, inSSHHostKey string, inSkipSSHHostKeyCheck bool, inRegistrationEnabled bool, inLoginEnabled bool) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("remotesource").Cols("id", "revision", "creation_time", "update_time", "name", "apiurl", "skip_verify", "type", "auth_type", "oauth2_client_id", "oauth2_client_secret", "ssh_host_key", "skip_ssh_host_key_check", "registration_enabled", "login_enabled").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inAPIURL, inSkipVerify, inType, inAuthType, inOauth2ClientID, inOauth2ClientSecret, inSSHHostKey, inSkipSSHHostKeyCheck, inRegistrationEnabled, inLoginEnabled)
	}
	remoteSourceUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inAPIURL string, inSkipVerify bool, inType types.RemoteSourceType, inAuthType types.RemoteSourceAuthType, inOauth2ClientID string, inOauth2ClientSecret string, inSSHHostKey string, inSkipSSHHostKeyCheck bool, inRegistrationEnabled bool, inLoginEnabled bool) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("remotesource").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("name", inName), ub.Assign("apiurl", inAPIURL), ub.Assign("skip_verify", inSkipVerify), ub.Assign("type", inType), ub.Assign("auth_type", inAuthType), ub.Assign("oauth2_client_id", inOauth2ClientID), ub.Assign("oauth2_client_secret", inOauth2ClientSecret), ub.Assign("ssh_host_key", inSSHHostKey), ub.Assign("skip_ssh_host_key_check", inSkipSSHHostKeyCheck), ub.Assign("registration_enabled", inRegistrationEnabled), ub.Assign("login_enabled", inLoginEnabled)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	remoteSourceInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inAPIURL string, inSkipVerify bool, inType types.RemoteSourceType, inAuthType types.RemoteSourceAuthType, inOauth2ClientID string, inOauth2ClientSecret string, inSSHHostKey string, inSkipSSHHostKeyCheck bool, inRegistrationEnabled bool, inLoginEnabled bool) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("remotesource").Cols("id", "revision", "creation_time", "update_time", "name", "apiurl", "skip_verify", "type", "auth_type", "oauth2_client_id", "oauth2_client_secret", "ssh_host_key", "skip_ssh_host_key_check", "registration_enabled", "login_enabled").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inAPIURL, inSkipVerify, inType, inAuthType, inOauth2ClientID, inOauth2ClientSecret, inSSHHostKey, inSkipSSHHostKeyCheck, inRegistrationEnabled, inLoginEnabled)
	}
)

func (d *DB) insertRemoteSourceSqlite3(tx *sql.Tx, remotesource *types.RemoteSource) error {
	q := remoteSourceInsertSqlite3(remotesource.ID, remotesource.Revision, remotesource.CreationTime, remotesource.UpdateTime, remotesource.Name, remotesource.APIURL, remotesource.SkipVerify, remotesource.Type, remotesource.AuthType, remotesource.Oauth2ClientID, remotesource.Oauth2ClientSecret, remotesource.SSHHostKey, remotesource.SkipSSHHostKeyCheck, remotesource.RegistrationEnabled, remotesource.LoginEnabled)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert remoteSource")
	}

	return nil
}

func (d *DB) updateRemoteSourceSqlite3(tx *sql.Tx, curRevision uint64, remotesource *types.RemoteSource) (stdsql.Result, error) {
	q := remoteSourceUpdateSqlite3(curRevision, remotesource.ID, remotesource.Revision, remotesource.CreationTime, remotesource.UpdateTime, remotesource.Name, remotesource.APIURL, remotesource.SkipVerify, remotesource.Type, remotesource.AuthType, remotesource.Oauth2ClientID, remotesource.Oauth2ClientSecret, remotesource.SSHHostKey, remotesource.SkipSSHHostKeyCheck, remotesource.RegistrationEnabled, remotesource.LoginEnabled)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update remoteSource")
	}

	return res, nil
}

func (d *DB) insertRawRemoteSourceSqlite3(tx *sql.Tx, remotesource *types.RemoteSource) error {
	q := remoteSourceInsertRawSqlite3(remotesource.ID, remotesource.Revision, remotesource.CreationTime, remotesource.UpdateTime, remotesource.Name, remotesource.APIURL, remotesource.SkipVerify, remotesource.Type, remotesource.AuthType, remotesource.Oauth2ClientID, remotesource.Oauth2ClientSecret, remotesource.SSHHostKey, remotesource.SkipSSHHostKeyCheck, remotesource.RegistrationEnabled, remotesource.LoginEnabled)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert remoteSource")
	}

	return nil
}
var (
	userInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inSecret string, inAdmin bool) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("user_t").Cols("id", "revision", "creation_time", "update_time", "name", "secret", "admin").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inSecret, inAdmin)
	}
	userUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inSecret string, inAdmin bool) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("user_t").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("name", inName), ub.Assign("secret", inSecret), ub.Assign("admin", inAdmin)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	userInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inSecret string, inAdmin bool) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("user_t").Cols("id", "revision", "creation_time", "update_time", "name", "secret", "admin").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inSecret, inAdmin)
	}
)

func (d *DB) insertUserSqlite3(tx *sql.Tx, user *types.User) error {
	q := userInsertSqlite3(user.ID, user.Revision, user.CreationTime, user.UpdateTime, user.Name, user.Secret, user.Admin)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert user")
	}

	return nil
}

func (d *DB) updateUserSqlite3(tx *sql.Tx, curRevision uint64, user *types.User) (stdsql.Result, error) {
	q := userUpdateSqlite3(curRevision, user.ID, user.Revision, user.CreationTime, user.UpdateTime, user.Name, user.Secret, user.Admin)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update user")
	}

	return res, nil
}

func (d *DB) insertRawUserSqlite3(tx *sql.Tx, user *types.User) error {
	q := userInsertRawSqlite3(user.ID, user.Revision, user.CreationTime, user.UpdateTime, user.Name, user.Secret, user.Admin)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert user")
	}

	return nil
}
var (
	userTokenInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inUserID string, inName string, inValue string) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("usertoken").Cols("id", "revision", "creation_time", "update_time", "user_id", "name", "value").Values(inId, inRevision, inCreationTime, inUpdateTime, inUserID, inName, inValue)
	}
	userTokenUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inUserID string, inName string, inValue string) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("usertoken").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("user_id", inUserID), ub.Assign("name", inName), ub.Assign("value", inValue)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	userTokenInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inUserID string, inName string, inValue string) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("usertoken").Cols("id", "revision", "creation_time", "update_time", "user_id", "name", "value").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inUserID, inName, inValue)
	}
)

func (d *DB) insertUserTokenSqlite3(tx *sql.Tx, usertoken *types.UserToken) error {
	q := userTokenInsertSqlite3(usertoken.ID, usertoken.Revision, usertoken.CreationTime, usertoken.UpdateTime, usertoken.UserID, usertoken.Name, usertoken.Value)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert userToken")
	}

	return nil
}

func (d *DB) updateUserTokenSqlite3(tx *sql.Tx, curRevision uint64, usertoken *types.UserToken) (stdsql.Result, error) {
	q := userTokenUpdateSqlite3(curRevision, usertoken.ID, usertoken.Revision, usertoken.CreationTime, usertoken.UpdateTime, usertoken.UserID, usertoken.Name, usertoken.Value)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update userToken")
	}

	return res, nil
}

func (d *DB) insertRawUserTokenSqlite3(tx *sql.Tx, usertoken *types.UserToken) error {
	q := userTokenInsertRawSqlite3(usertoken.ID, usertoken.Revision, usertoken.CreationTime, usertoken.UpdateTime, usertoken.UserID, usertoken.Name, usertoken.Value)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert userToken")
	}

	return nil
}
var (
	linkedAccountInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inUserID string, inRemoteUserID string, inRemoteUserName string, inRemoteUserAvatarURL string, inRemoteSourceID string, inUserAccessToken string, inOauth2AccessToken string, inOauth2RefreshToken string, inOauth2AccessTokenExpiresAt time.Time) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("linkedaccount").Cols("id", "revision", "creation_time", "update_time", "user_id", "remote_user_id", "remote_user_name", "remote_user_avatar_url", "remote_source_id", "user_access_token", "oauth2_access_token", "oauth2_refresh_token", "oauth2_access_token_expires_at").Values(inId, inRevision, inCreationTime, inUpdateTime, inUserID, inRemoteUserID, inRemoteUserName, inRemoteUserAvatarURL, inRemoteSourceID, inUserAccessToken, inOauth2AccessToken, inOauth2RefreshToken, inOauth2AccessTokenExpiresAt)
	}
	linkedAccountUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inUserID string, inRemoteUserID string, inRemoteUserName string, inRemoteUserAvatarURL string, inRemoteSourceID string, inUserAccessToken string, inOauth2AccessToken string, inOauth2RefreshToken string, inOauth2AccessTokenExpiresAt time.Time) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("linkedaccount").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("user_id", inUserID), ub.Assign("remote_user_id", inRemoteUserID), ub.Assign("remote_user_name", inRemoteUserName), ub.Assign("remote_user_avatar_url", inRemoteUserAvatarURL), ub.Assign("remote_source_id", inRemoteSourceID), ub.Assign("user_access_token", inUserAccessToken), ub.Assign("oauth2_access_token", inOauth2AccessToken), ub.Assign("oauth2_refresh_token", inOauth2RefreshToken), ub.Assign("oauth2_access_token_expires_at", inOauth2AccessTokenExpiresAt)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	linkedAccountInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inUserID string, inRemoteUserID string, inRemoteUserName string, inRemoteUserAvatarURL string, inRemoteSourceID string, inUserAccessToken string, inOauth2AccessToken string, inOauth2RefreshToken string, inOauth2AccessTokenExpiresAt time.Time) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("linkedaccount").Cols("id", "revision", "creation_time", "update_time", "user_id", "remote_user_id", "remote_user_name", "remote_user_avatar_url", "remote_source_id", "user_access_token", "oauth2_access_token", "oauth2_refresh_token", "oauth2_access_token_expires_at").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inUserID, inRemoteUserID, inRemoteUserName, inRemoteUserAvatarURL, inRemoteSourceID, inUserAccessToken, inOauth2AccessToken, inOauth2RefreshToken, inOauth2AccessTokenExpiresAt)
	}
)

func (d *DB) insertLinkedAccountSqlite3(tx *sql.Tx, linkedaccount *types.LinkedAccount) error {
	q := linkedAccountInsertSqlite3(linkedaccount.ID, linkedaccount.Revision, linkedaccount.CreationTime, linkedaccount.UpdateTime, linkedaccount.UserID, linkedaccount.RemoteUserID, linkedaccount.RemoteUserName, linkedaccount.RemoteUserAvatarURL, linkedaccount.RemoteSourceID, linkedaccount.UserAccessToken, linkedaccount.Oauth2AccessToken, linkedaccount.Oauth2RefreshToken, linkedaccount.Oauth2AccessTokenExpiresAt)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert linkedAccount")
	}

	return nil
}

func (d *DB) updateLinkedAccountSqlite3(tx *sql.Tx, curRevision uint64, linkedaccount *types.LinkedAccount) (stdsql.Result, error) {
	q := linkedAccountUpdateSqlite3(curRevision, linkedaccount.ID, linkedaccount.Revision, linkedaccount.CreationTime, linkedaccount.UpdateTime, linkedaccount.UserID, linkedaccount.RemoteUserID, linkedaccount.RemoteUserName, linkedaccount.RemoteUserAvatarURL, linkedaccount.RemoteSourceID, linkedaccount.UserAccessToken, linkedaccount.Oauth2AccessToken, linkedaccount.Oauth2RefreshToken, linkedaccount.Oauth2AccessTokenExpiresAt)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update linkedAccount")
	}

	return res, nil
}

func (d *DB) insertRawLinkedAccountSqlite3(tx *sql.Tx, linkedaccount *types.LinkedAccount) error {
	q := linkedAccountInsertRawSqlite3(linkedaccount.ID, linkedaccount.Revision, linkedaccount.CreationTime, linkedaccount.UpdateTime, linkedaccount.UserID, linkedaccount.RemoteUserID, linkedaccount.RemoteUserName, linkedaccount.RemoteUserAvatarURL, linkedaccount.RemoteSourceID, linkedaccount.UserAccessToken, linkedaccount.Oauth2AccessToken, linkedaccount.Oauth2RefreshToken, linkedaccount.Oauth2AccessTokenExpiresAt)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert linkedAccount")
	}

	return nil
}
var (
	organizationInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inVisibility types.Visibility, inCreatorUserID string) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("organization").Cols("id", "revision", "creation_time", "update_time", "name", "visibility", "creator_user_id").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inVisibility, inCreatorUserID)
	}
	organizationUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inVisibility types.Visibility, inCreatorUserID string) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("organization").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("name", inName), ub.Assign("visibility", inVisibility), ub.Assign("creator_user_id", inCreatorUserID)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	organizationInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inVisibility types.Visibility, inCreatorUserID string) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("organization").Cols("id", "revision", "creation_time", "update_time", "name", "visibility", "creator_user_id").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inVisibility, inCreatorUserID)
	}
)

func (d *DB) insertOrganizationSqlite3(tx *sql.Tx, organization *types.Organization) error {
	q := organizationInsertSqlite3(organization.ID, organization.Revision, organization.CreationTime, organization.UpdateTime, organization.Name, organization.Visibility, organization.CreatorUserID)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert organization")
	}

	return nil
}

func (d *DB) updateOrganizationSqlite3(tx *sql.Tx, curRevision uint64, organization *types.Organization) (stdsql.Result, error) {
	q := organizationUpdateSqlite3(curRevision, organization.ID, organization.Revision, organization.CreationTime, organization.UpdateTime, organization.Name, organization.Visibility, organization.CreatorUserID)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update organization")
	}

	return res, nil
}

func (d *DB) insertRawOrganizationSqlite3(tx *sql.Tx, organization *types.Organization) error {
	q := organizationInsertRawSqlite3(organization.ID, organization.Revision, organization.CreationTime, organization.UpdateTime, organization.Name, organization.Visibility, organization.CreatorUserID)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert organization")
	}

	return nil
}
var (
	organizationMemberInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inOrganizationID string, inUserID string, inMemberRole types.MemberRole) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("orgmember").Cols("id", "revision", "creation_time", "update_time", "organization_id", "user_id", "member_role").Values(inId, inRevision, inCreationTime, inUpdateTime, inOrganizationID, inUserID, inMemberRole)
	}
	organizationMemberUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inOrganizationID string, inUserID string, inMemberRole types.MemberRole) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("orgmember").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("organization_id", inOrganizationID), ub.Assign("user_id", inUserID), ub.Assign("member_role", inMemberRole)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	organizationMemberInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inOrganizationID string, inUserID string, inMemberRole types.MemberRole) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("orgmember").Cols("id", "revision", "creation_time", "update_time", "organization_id", "user_id", "member_role").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inOrganizationID, inUserID, inMemberRole)
	}
)

func (d *DB) insertOrganizationMemberSqlite3(tx *sql.Tx, organizationmember *types.OrganizationMember) error {
	q := organizationMemberInsertSqlite3(organizationmember.ID, organizationmember.Revision, organizationmember.CreationTime, organizationmember.UpdateTime, organizationmember.OrganizationID, organizationmember.UserID, organizationmember.MemberRole)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert organizationMember")
	}

	return nil
}

func (d *DB) updateOrganizationMemberSqlite3(tx *sql.Tx, curRevision uint64, organizationmember *types.OrganizationMember) (stdsql.Result, error) {
	q := organizationMemberUpdateSqlite3(curRevision, organizationmember.ID, organizationmember.Revision, organizationmember.CreationTime, organizationmember.UpdateTime, organizationmember.OrganizationID, organizationmember.UserID, organizationmember.MemberRole)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update organizationMember")
	}

	return res, nil
}

func (d *DB) insertRawOrganizationMemberSqlite3(tx *sql.Tx, organizationmember *types.OrganizationMember) error {
	q := organizationMemberInsertRawSqlite3(organizationmember.ID, organizationmember.Revision, organizationmember.CreationTime, organizationmember.UpdateTime, organizationmember.OrganizationID, organizationmember.UserID, organizationmember.MemberRole)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert organizationMember")
	}

	return nil
}
var (
	projectGroupInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inVisibility types.Visibility) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("projectgroup").Cols("id", "revision", "creation_time", "update_time", "name", "parent_kind", "parent_id", "visibility").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inParentKind, inParentID, inVisibility)
	}
	projectGroupUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inVisibility types.Visibility) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("projectgroup").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("name", inName), ub.Assign("parent_kind", inParentKind), ub.Assign("parent_id", inParentID), ub.Assign("visibility", inVisibility)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	projectGroupInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inVisibility types.Visibility) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("projectgroup").Cols("id", "revision", "creation_time", "update_time", "name", "parent_kind", "parent_id", "visibility").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inParentKind, inParentID, inVisibility)
	}
)

func (d *DB) insertProjectGroupSqlite3(tx *sql.Tx, projectgroup *types.ProjectGroup) error {
	q := projectGroupInsertSqlite3(projectgroup.ID, projectgroup.Revision, projectgroup.CreationTime, projectgroup.UpdateTime, projectgroup.Name, projectgroup.Parent.Kind, projectgroup.Parent.ID, projectgroup.Visibility)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert projectGroup")
	}

	return nil
}

func (d *DB) updateProjectGroupSqlite3(tx *sql.Tx, curRevision uint64, projectgroup *types.ProjectGroup) (stdsql.Result, error) {
	q := projectGroupUpdateSqlite3(curRevision, projectgroup.ID, projectgroup.Revision, projectgroup.CreationTime, projectgroup.UpdateTime, projectgroup.Name, projectgroup.Parent.Kind, projectgroup.Parent.ID, projectgroup.Visibility)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update projectGroup")
	}

	return res, nil
}

func (d *DB) insertRawProjectGroupSqlite3(tx *sql.Tx, projectgroup *types.ProjectGroup) error {
	q := projectGroupInsertRawSqlite3(projectgroup.ID, projectgroup.Revision, projectgroup.CreationTime, projectgroup.UpdateTime, projectgroup.Name, projectgroup.Parent.Kind, projectgroup.Parent.ID, projectgroup.Visibility)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert projectGroup")
	}

	return nil
}
var (
	projectInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inSecret string, inVisibility types.Visibility, inRemoteRepositoryConfigType types.RemoteRepositoryConfigType, inRemoteSourceID string, inLinkedAccountID string, inRepositoryID string, inRepositoryPath string, inSSHPrivateKey string, inSkipSSHHostKeyCheck bool, inWebhookSecret string, inPassVarsToForkedPR bool, inDefaultBranch string) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("project").Cols("id", "revision", "creation_time", "update_time", "name", "parent_kind", "parent_id", "secret", "visibility", "remote_repository_config_type", "remote_source_id", "linked_account_id", "repository_id", "repository_path", "ssh_private_key", "skip_ssh_host_key_check", "webhook_secret", "pass_vars_to_forked_pr", "default_branch").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inParentKind, inParentID, inSecret, inVisibility, inRemoteRepositoryConfigType, inRemoteSourceID, inLinkedAccountID, inRepositoryID, inRepositoryPath, inSSHPrivateKey, inSkipSSHHostKeyCheck, inWebhookSecret, inPassVarsToForkedPR, inDefaultBranch)
	}
	projectUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inSecret string, inVisibility types.Visibility, inRemoteRepositoryConfigType types.RemoteRepositoryConfigType, inRemoteSourceID string, inLinkedAccountID string, inRepositoryID string, inRepositoryPath string, inSSHPrivateKey string, inSkipSSHHostKeyCheck bool, inWebhookSecret string, inPassVarsToForkedPR bool, inDefaultBranch string) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("project").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("name", inName), ub.Assign("parent_kind", inParentKind), ub.Assign("parent_id", inParentID), ub.Assign("secret", inSecret), ub.Assign("visibility", inVisibility), ub.Assign("remote_repository_config_type", inRemoteRepositoryConfigType), ub.Assign("remote_source_id", inRemoteSourceID), ub.Assign("linked_account_id", inLinkedAccountID), ub.Assign("repository_id", inRepositoryID), ub.Assign("repository_path", inRepositoryPath), ub.Assign("ssh_private_key", inSSHPrivateKey), ub.Assign("skip_ssh_host_key_check", inSkipSSHHostKeyCheck), ub.Assign("webhook_secret", inWebhookSecret), ub.Assign("pass_vars_to_forked_pr", inPassVarsToForkedPR), ub.Assign("default_branch", inDefaultBranch)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	projectInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inSecret string, inVisibility types.Visibility, inRemoteRepositoryConfigType types.RemoteRepositoryConfigType, inRemoteSourceID string, inLinkedAccountID string, inRepositoryID string, inRepositoryPath string, inSSHPrivateKey string, inSkipSSHHostKeyCheck bool, inWebhookSecret string, inPassVarsToForkedPR bool, inDefaultBranch string) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("project").Cols("id", "revision", "creation_time", "update_time", "name", "parent_kind", "parent_id", "secret", "visibility", "remote_repository_config_type", "remote_source_id", "linked_account_id", "repository_id", "repository_path", "ssh_private_key", "skip_ssh_host_key_check", "webhook_secret", "pass_vars_to_forked_pr", "default_branch").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inParentKind, inParentID, inSecret, inVisibility, inRemoteRepositoryConfigType, inRemoteSourceID, inLinkedAccountID, inRepositoryID, inRepositoryPath, inSSHPrivateKey, inSkipSSHHostKeyCheck, inWebhookSecret, inPassVarsToForkedPR, inDefaultBranch)
	}
)

func (d *DB) insertProjectSqlite3(tx *sql.Tx, project *types.Project) error {
	q := projectInsertSqlite3(project.ID, project.Revision, project.CreationTime, project.UpdateTime, project.Name, project.Parent.Kind, project.Parent.ID, project.Secret, project.Visibility, project.RemoteRepositoryConfigType, project.RemoteSourceID, project.LinkedAccountID, project.RepositoryID, project.RepositoryPath, project.SSHPrivateKey, project.SkipSSHHostKeyCheck, project.WebhookSecret, project.PassVarsToForkedPR, project.DefaultBranch)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert project")
	}

	return nil
}

func (d *DB) updateProjectSqlite3(tx *sql.Tx, curRevision uint64, project *types.Project) (stdsql.Result, error) {
	q := projectUpdateSqlite3(curRevision, project.ID, project.Revision, project.CreationTime, project.UpdateTime, project.Name, project.Parent.Kind, project.Parent.ID, project.Secret, project.Visibility, project.RemoteRepositoryConfigType, project.RemoteSourceID, project.LinkedAccountID, project.RepositoryID, project.RepositoryPath, project.SSHPrivateKey, project.SkipSSHHostKeyCheck, project.WebhookSecret, project.PassVarsToForkedPR, project.DefaultBranch)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update project")
	}

	return res, nil
}

func (d *DB) insertRawProjectSqlite3(tx *sql.Tx, project *types.Project) error {
	q := projectInsertRawSqlite3(project.ID, project.Revision, project.CreationTime, project.UpdateTime, project.Name, project.Parent.Kind, project.Parent.ID, project.Secret, project.Visibility, project.RemoteRepositoryConfigType, project.RemoteSourceID, project.LinkedAccountID, project.RepositoryID, project.RepositoryPath, project.SSHPrivateKey, project.SkipSSHHostKeyCheck, project.WebhookSecret, project.PassVarsToForkedPR, project.DefaultBranch)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert project")
	}

	return nil
}
var (
	secretInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inType types.SecretType, inData []byte, inSecretProviderID string, inPath string) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("secret").Cols("id", "revision", "creation_time", "update_time", "name", "parent_kind", "parent_id", "type", "data", "secret_provider_id", "path").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inParentKind, inParentID, inType, inData, inSecretProviderID, inPath)
	}
	secretUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inType types.SecretType, inData []byte, inSecretProviderID string, inPath string) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("secret").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("name", inName), ub.Assign("parent_kind", inParentKind), ub.Assign("parent_id", inParentID), ub.Assign("type", inType), ub.Assign("data", inData), ub.Assign("secret_provider_id", inSecretProviderID), ub.Assign("path", inPath)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	secretInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inType types.SecretType, inData []byte, inSecretProviderID string, inPath string) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("secret").Cols("id", "revision", "creation_time", "update_time", "name", "parent_kind", "parent_id", "type", "data", "secret_provider_id", "path").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inParentKind, inParentID, inType, inData, inSecretProviderID, inPath)
	}
)

func (d *DB) insertSecretSqlite3(tx *sql.Tx, secret *types.Secret) error {
	inDataJSON, err := json.Marshal(secret.Data)
	if err != nil {
		return errors.Wrap(err, "failed to marshal secret.Data")
	}
	q := secretInsertSqlite3(secret.ID, secret.Revision, secret.CreationTime, secret.UpdateTime, secret.Name, secret.Parent.Kind, secret.Parent.ID, secret.Type, inDataJSON, secret.SecretProviderID, secret.Path)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert secret")
	}

	return nil
}

func (d *DB) updateSecretSqlite3(tx *sql.Tx, curRevision uint64, secret *types.Secret) (stdsql.Result, error) {
	inDataJSON, err := json.Marshal(secret.Data)
	if err != nil {
		return nil, errors.Wrap(err, "failed to marshal secret.Data")
	}
	q := secretUpdateSqlite3(curRevision, secret.ID, secret.Revision, secret.CreationTime, secret.UpdateTime, secret.Name, secret.Parent.Kind, secret.Parent.ID, secret.Type, inDataJSON, secret.SecretProviderID, secret.Path)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update secret")
	}

	return res, nil
}

func (d *DB) insertRawSecretSqlite3(tx *sql.Tx, secret *types.Secret) error {
	inDataJSON, err := json.Marshal(secret.Data)
	if err != nil {
		return errors.Wrap(err, "failed to marshal secret.Data")
	}
	q := secretInsertRawSqlite3(secret.ID, secret.Revision, secret.CreationTime, secret.UpdateTime, secret.Name, secret.Parent.Kind, secret.Parent.ID, secret.Type, inDataJSON, secret.SecretProviderID, secret.Path)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert secret")
	}

	return nil
}
var (
	variableInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inValues []byte) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("variable").Cols("id", "revision", "creation_time", "update_time", "name", "parent_kind", "parent_id", "variable_values").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inParentKind, inParentID, inValues)
	}
	variableUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inValues []byte) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("variable").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("name", inName), ub.Assign("parent_kind", inParentKind), ub.Assign("parent_id", inParentID), ub.Assign("variable_values", inValues)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	variableInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inName string, inParentKind types.ObjectKind, inParentID string, inValues []byte) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("variable").Cols("id", "revision", "creation_time", "update_time", "name", "parent_kind", "parent_id", "variable_values").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inName, inParentKind, inParentID, inValues)
	}
)

func (d *DB) insertVariableSqlite3(tx *sql.Tx, variable *types.Variable) error {
	inValuesJSON, err := json.Marshal(variable.Values)
	if err != nil {
		return errors.Wrap(err, "failed to marshal variable.Values")
	}
	q := variableInsertSqlite3(variable.ID, variable.Revision, variable.CreationTime, variable.UpdateTime, variable.Name, variable.Parent.Kind, variable.Parent.ID, inValuesJSON)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert variable")
	}

	return nil
}

func (d *DB) updateVariableSqlite3(tx *sql.Tx, curRevision uint64, variable *types.Variable) (stdsql.Result, error) {
	inValuesJSON, err := json.Marshal(variable.Values)
	if err != nil {
		return nil, errors.Wrap(err, "failed to marshal variable.Values")
	}
	q := variableUpdateSqlite3(curRevision, variable.ID, variable.Revision, variable.CreationTime, variable.UpdateTime, variable.Name, variable.Parent.Kind, variable.Parent.ID, inValuesJSON)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update variable")
	}

	return res, nil
}

func (d *DB) insertRawVariableSqlite3(tx *sql.Tx, variable *types.Variable) error {
	inValuesJSON, err := json.Marshal(variable.Values)
	if err != nil {
		return errors.Wrap(err, "failed to marshal variable.Values")
	}
	q := variableInsertRawSqlite3(variable.ID, variable.Revision, variable.CreationTime, variable.UpdateTime, variable.Name, variable.Parent.Kind, variable.Parent.ID, inValuesJSON)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert variable")
	}

	return nil
}
var (
	orgInvitationInsertSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inUserID string, inOrganizationID string, inRole types.MemberRole) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("orginvitation").Cols("id", "revision", "creation_time", "update_time", "user_id", "organization_id", "role").Values(inId, inRevision, inCreationTime, inUpdateTime, inUserID, inOrganizationID, inRole)
	}
	orgInvitationUpdateSqlite3 = func(curRevision uint64, inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inUserID string, inOrganizationID string, inRole types.MemberRole) *sq.UpdateBuilder {
		ub:= sq.NewUpdateBuilder()
		return ub.Update("orginvitation").Set(ub.Assign("id", inId), ub.Assign("revision", inRevision), ub.Assign("creation_time", inCreationTime), ub.Assign("update_time", inUpdateTime), ub.Assign("user_id", inUserID), ub.Assign("organization_id", inOrganizationID), ub.Assign("role", inRole)).Where(ub.E("id", inId), ub.E("revision", curRevision))
	}

	orgInvitationInsertRawSqlite3 = func(inId string, inRevision uint64, inCreationTime time.Time, inUpdateTime time.Time, inUserID string, inOrganizationID string, inRole types.MemberRole) *sq.InsertBuilder {
		ib:= sq.NewInsertBuilder()
		return ib.InsertInto("orginvitation").Cols("id", "revision", "creation_time", "update_time", "user_id", "organization_id", "role").SQL("").Values(inId, inRevision, inCreationTime, inUpdateTime, inUserID, inOrganizationID, inRole)
	}
)

func (d *DB) insertOrgInvitationSqlite3(tx *sql.Tx, orginvitation *types.OrgInvitation) error {
	q := orgInvitationInsertSqlite3(orginvitation.ID, orginvitation.Revision, orginvitation.CreationTime, orginvitation.UpdateTime, orginvitation.UserID, orginvitation.OrganizationID, orginvitation.Role)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert orgInvitation")
	}

	return nil
}

func (d *DB) updateOrgInvitationSqlite3(tx *sql.Tx, curRevision uint64, orginvitation *types.OrgInvitation) (stdsql.Result, error) {
	q := orgInvitationUpdateSqlite3(curRevision, orginvitation.ID, orginvitation.Revision, orginvitation.CreationTime, orginvitation.UpdateTime, orginvitation.UserID, orginvitation.OrganizationID, orginvitation.Role)

	res, err := d.exec(tx, q)
	if err != nil {
		return nil, errors.Wrap(err, "failed to update orgInvitation")
	}

	return res, nil
}

func (d *DB) insertRawOrgInvitationSqlite3(tx *sql.Tx, orginvitation *types.OrgInvitation) error {
	q := orgInvitationInsertRawSqlite3(orginvitation.ID, orginvitation.Revision, orginvitation.CreationTime, orginvitation.UpdateTime, orginvitation.UserID, orginvitation.OrganizationID, orginvitation.Role)

	if _, err := d.exec(tx, q); err != nil {
		return errors.Wrap(err, "failed to insert orgInvitation")
	}

	return nil
}
