// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.14.0
// source: tables_gen.sql

package core_repo

import (
	"context"
)

const createTable = `-- name: CreateTable :one

INSERT INTO "public"."_tables" (name,user_id,columns) VALUES ($1, $2, $3) RETURNING id, user_id, name, columns, created, updated
`

type CreateTableParams struct {
	Name    string `json:"name"`
	UserID  int64  `json:"user_id"`
	Columns string `json:"columns"`
}

// -------------------------- ADD _TABLES <-> _TABLES --------------------------
func (q *Queries) CreateTable(ctx context.Context, arg CreateTableParams) (Table, error) {
	row := q.db.QueryRowContext(ctx, createTable, arg.Name, arg.UserID, arg.Columns)
	var i Table
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Name,
		&i.Columns,
		&i.Created,
		&i.Updated,
	)
	return i, err
}

const deleteTableWhereName = `-- name: DeleteTableWhereName :exec
DELETE FROM "public"."_tables" WHERE name = $1
`

func (q *Queries) DeleteTableWhereName(ctx context.Context, name string) error {
	_, err := q.db.ExecContext(ctx, deleteTableWhereName, name)
	return err
}

const deleteTablesWhereUser = `-- name: DeleteTablesWhereUser :exec

DELETE FROM "public"."_tables" WHERE user_id = $1
`

// -------------------------- REMOVE _TABLES <-> _TABLES --------------------------
func (q *Queries) DeleteTablesWhereUser(ctx context.Context, userID int64) error {
	_, err := q.db.ExecContext(ctx, deleteTablesWhereUser, userID)
	return err
}

const getAllTables = `-- name: GetAllTables :many

SELECT id, user_id, name, columns, created, updated FROM "public"."_tables"
`

// ------------------------------ GET MULTIPLE _TABLES <== [_TABLES] ------------------------------
func (q *Queries) GetAllTables(ctx context.Context) ([]Table, error) {
	rows, err := q.db.QueryContext(ctx, getAllTables)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Table{}
	for rows.Next() {
		var i Table
		if err := rows.Scan(
			&i.ID,
			&i.UserID,
			&i.Name,
			&i.Columns,
			&i.Created,
			&i.Updated,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const getSomeTables = `-- name: GetSomeTables :many
SELECT id, user_id, name, columns, created, updated FROM "public"."_tables" LIMIT $2::int OFFSET $1::int
`

type GetSomeTablesParams struct {
	Offset int32 `json:"offset_"`
	Limit  int32 `json:"limit_"`
}

func (q *Queries) GetSomeTables(ctx context.Context, arg GetSomeTablesParams) ([]Table, error) {
	rows, err := q.db.QueryContext(ctx, getSomeTables, arg.Offset, arg.Limit)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Table{}
	for rows.Next() {
		var i Table
		if err := rows.Scan(
			&i.ID,
			&i.UserID,
			&i.Name,
			&i.Columns,
			&i.Created,
			&i.Updated,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const getSomeTablesWhereUser = `-- name: GetSomeTablesWhereUser :many
SELECT id, user_id, name, columns, created, updated FROM "public"."_tables" WHERE user_id = $1 LIMIT $3::int OFFSET $2::int
`

type GetSomeTablesWhereUserParams struct {
	UserID int64 `json:"user_id"`
	Offset int32 `json:"offset_"`
	Limit  int32 `json:"limit_"`
}

func (q *Queries) GetSomeTablesWhereUser(ctx context.Context, arg GetSomeTablesWhereUserParams) ([]Table, error) {
	rows, err := q.db.QueryContext(ctx, getSomeTablesWhereUser, arg.UserID, arg.Offset, arg.Limit)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Table{}
	for rows.Next() {
		var i Table
		if err := rows.Scan(
			&i.ID,
			&i.UserID,
			&i.Name,
			&i.Columns,
			&i.Created,
			&i.Updated,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const getTableByUserIdAndTableName = `-- name: GetTableByUserIdAndTableName :one
SELECT id, user_id, name, columns, created, updated FROM "public"."_tables" WHERE user_id = $1 AND name = $2 LIMIT 1
`

type GetTableByUserIdAndTableNameParams struct {
	UserID int64  `json:"user_id"`
	Name   string `json:"name"`
}

func (q *Queries) GetTableByUserIdAndTableName(ctx context.Context, arg GetTableByUserIdAndTableNameParams) (Table, error) {
	row := q.db.QueryRowContext(ctx, getTableByUserIdAndTableName, arg.UserID, arg.Name)
	var i Table
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Name,
		&i.Columns,
		&i.Created,
		&i.Updated,
	)
	return i, err
}

const getTableWhereName = `-- name: GetTableWhereName :one

SELECT id, user_id, name, columns, created, updated FROM "public"."_tables" WHERE name = $1 LIMIT 1
`

// -------------------------- GET ONE _TABLES <- _TABLES --------------------------
func (q *Queries) GetTableWhereName(ctx context.Context, name string) (Table, error) {
	row := q.db.QueryRowContext(ctx, getTableWhereName, name)
	var i Table
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Name,
		&i.Columns,
		&i.Created,
		&i.Updated,
	)
	return i, err
}

const getTablesWhereUser = `-- name: GetTablesWhereUser :many

SELECT id, user_id, name, columns, created, updated FROM "public"."_tables" WHERE user_id = $1
`

// --------------------- GET MULTIPLE _TABLES OF _USERS.user_id <== [_TABLES] ---------------------
func (q *Queries) GetTablesWhereUser(ctx context.Context, userID int64) ([]Table, error) {
	rows, err := q.db.QueryContext(ctx, getTablesWhereUser, userID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Table{}
	for rows.Next() {
		var i Table
		if err := rows.Scan(
			&i.ID,
			&i.UserID,
			&i.Name,
			&i.Columns,
			&i.Created,
			&i.Updated,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateTableColumns = `-- name: UpdateTableColumns :one

UPDATE "public"."_tables" SET columns = $1 WHERE id = $2 RETURNING id, user_id, name, columns, created, updated
`

type UpdateTableColumnsParams struct {
	Columns string `json:"columns"`
	ID      int64  `json:"id"`
}

// -------------------------- UPDATE _TABLES <-> _TABLES --------------------------
func (q *Queries) UpdateTableColumns(ctx context.Context, arg UpdateTableColumnsParams) (Table, error) {
	row := q.db.QueryRowContext(ctx, updateTableColumns, arg.Columns, arg.ID)
	var i Table
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Name,
		&i.Columns,
		&i.Created,
		&i.Updated,
	)
	return i, err
}
