增加 document 结构和迁移

改进 api
This commit is contained in:
ivamp 2024-07-20 23:37:01 +08:00
parent 385739194e
commit 6d98dd7317
18 changed files with 4284 additions and 0 deletions

149
ent/document.go Normal file
View File

@ -0,0 +1,149 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"leafdev.top/leaf/rag/ent/document"
)
// Document is the model entity for the Document schema.
type Document struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// UserID holds the value of the "user_id" field.
UserID string `json:"user_id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
document_block_document *int
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Document) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case document.FieldID:
values[i] = new(sql.NullInt64)
case document.FieldName, document.FieldUserID:
values[i] = new(sql.NullString)
case document.FieldCreatedAt, document.FieldUpdatedAt:
values[i] = new(sql.NullTime)
case document.ForeignKeys[0]: // document_block_document
values[i] = new(sql.NullInt64)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Document fields.
func (d *Document) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case document.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
d.ID = int(value.Int64)
case document.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
d.Name = value.String
}
case document.FieldUserID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field user_id", values[i])
} else if value.Valid {
d.UserID = value.String
}
case document.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
d.CreatedAt = value.Time
}
case document.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
d.UpdatedAt = value.Time
}
case document.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field document_block_document", value)
} else if value.Valid {
d.document_block_document = new(int)
*d.document_block_document = int(value.Int64)
}
default:
d.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Document.
// This includes values selected through modifiers, order, etc.
func (d *Document) Value(name string) (ent.Value, error) {
return d.selectValues.Get(name)
}
// Update returns a builder for updating this Document.
// Note that you need to call Document.Unwrap() before calling this method if this Document
// was returned from a transaction, and the transaction was committed or rolled back.
func (d *Document) Update() *DocumentUpdateOne {
return NewDocumentClient(d.config).UpdateOne(d)
}
// Unwrap unwraps the Document entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (d *Document) Unwrap() *Document {
_tx, ok := d.config.driver.(*txDriver)
if !ok {
panic("ent: Document is not a transactional entity")
}
d.config.driver = _tx.drv
return d
}
// String implements the fmt.Stringer.
func (d *Document) String() string {
var builder strings.Builder
builder.WriteString("Document(")
builder.WriteString(fmt.Sprintf("id=%v, ", d.ID))
builder.WriteString("name=")
builder.WriteString(d.Name)
builder.WriteString(", ")
builder.WriteString("user_id=")
builder.WriteString(d.UserID)
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(d.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(d.UpdatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// Documents is a parsable slice of Document.
type Documents []*Document

91
ent/document/document.go Normal file
View File

@ -0,0 +1,91 @@
// Code generated by ent, DO NOT EDIT.
package document
import (
"time"
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the document type in the database.
Label = "document"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldUserID holds the string denoting the user_id field in the database.
FieldUserID = "user_id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// Table holds the table name of the document in the database.
Table = "documents"
)
// Columns holds all SQL columns for document fields.
var Columns = []string{
FieldID,
FieldName,
FieldUserID,
FieldCreatedAt,
FieldUpdatedAt,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the "documents"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"document_block_document",
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
for i := range ForeignKeys {
if column == ForeignKeys[i] {
return true
}
}
return false
}
var (
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
)
// OrderOption defines the ordering options for the Document queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByUserID orders the results by the user_id field.
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUserID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}

300
ent/document/where.go Normal file
View File

@ -0,0 +1,300 @@
// Code generated by ent, DO NOT EDIT.
package document
import (
"time"
"entgo.io/ent/dialect/sql"
"leafdev.top/leaf/rag/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.Document {
return predicate.Document(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.Document {
return predicate.Document(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.Document {
return predicate.Document(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.Document {
return predicate.Document(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.Document {
return predicate.Document(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.Document {
return predicate.Document(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.Document {
return predicate.Document(sql.FieldLTE(FieldID, id))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldName, v))
}
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
func UserID(v string) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldUserID, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldUpdatedAt, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.Document {
return predicate.Document(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.Document {
return predicate.Document(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.Document {
return predicate.Document(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.Document {
return predicate.Document(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.Document {
return predicate.Document(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.Document {
return predicate.Document(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.Document {
return predicate.Document(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.Document {
return predicate.Document(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.Document {
return predicate.Document(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.Document {
return predicate.Document(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.Document {
return predicate.Document(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.Document {
return predicate.Document(sql.FieldContainsFold(FieldName, v))
}
// UserIDEQ applies the EQ predicate on the "user_id" field.
func UserIDEQ(v string) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldUserID, v))
}
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
func UserIDNEQ(v string) predicate.Document {
return predicate.Document(sql.FieldNEQ(FieldUserID, v))
}
// UserIDIn applies the In predicate on the "user_id" field.
func UserIDIn(vs ...string) predicate.Document {
return predicate.Document(sql.FieldIn(FieldUserID, vs...))
}
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
func UserIDNotIn(vs ...string) predicate.Document {
return predicate.Document(sql.FieldNotIn(FieldUserID, vs...))
}
// UserIDGT applies the GT predicate on the "user_id" field.
func UserIDGT(v string) predicate.Document {
return predicate.Document(sql.FieldGT(FieldUserID, v))
}
// UserIDGTE applies the GTE predicate on the "user_id" field.
func UserIDGTE(v string) predicate.Document {
return predicate.Document(sql.FieldGTE(FieldUserID, v))
}
// UserIDLT applies the LT predicate on the "user_id" field.
func UserIDLT(v string) predicate.Document {
return predicate.Document(sql.FieldLT(FieldUserID, v))
}
// UserIDLTE applies the LTE predicate on the "user_id" field.
func UserIDLTE(v string) predicate.Document {
return predicate.Document(sql.FieldLTE(FieldUserID, v))
}
// UserIDContains applies the Contains predicate on the "user_id" field.
func UserIDContains(v string) predicate.Document {
return predicate.Document(sql.FieldContains(FieldUserID, v))
}
// UserIDHasPrefix applies the HasPrefix predicate on the "user_id" field.
func UserIDHasPrefix(v string) predicate.Document {
return predicate.Document(sql.FieldHasPrefix(FieldUserID, v))
}
// UserIDHasSuffix applies the HasSuffix predicate on the "user_id" field.
func UserIDHasSuffix(v string) predicate.Document {
return predicate.Document(sql.FieldHasSuffix(FieldUserID, v))
}
// UserIDEqualFold applies the EqualFold predicate on the "user_id" field.
func UserIDEqualFold(v string) predicate.Document {
return predicate.Document(sql.FieldEqualFold(FieldUserID, v))
}
// UserIDContainsFold applies the ContainsFold predicate on the "user_id" field.
func UserIDContainsFold(v string) predicate.Document {
return predicate.Document(sql.FieldContainsFold(FieldUserID, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.Document {
return predicate.Document(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.Document {
return predicate.Document(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.Document {
return predicate.Document(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.Document {
return predicate.Document(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.Document {
return predicate.Document(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.Document {
return predicate.Document(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.Document {
return predicate.Document(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.Document {
return predicate.Document(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.Document {
return predicate.Document(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.Document {
return predicate.Document(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.Document {
return predicate.Document(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.Document {
return predicate.Document(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.Document {
return predicate.Document(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.Document {
return predicate.Document(sql.FieldLTE(FieldUpdatedAt, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Document) predicate.Document {
return predicate.Document(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.Document) predicate.Document {
return predicate.Document(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Document) predicate.Document {
return predicate.Document(sql.NotPredicates(p))
}

253
ent/document_create.go Normal file
View File

@ -0,0 +1,253 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/document"
)
// DocumentCreate is the builder for creating a Document entity.
type DocumentCreate struct {
config
mutation *DocumentMutation
hooks []Hook
}
// SetName sets the "name" field.
func (dc *DocumentCreate) SetName(s string) *DocumentCreate {
dc.mutation.SetName(s)
return dc
}
// SetUserID sets the "user_id" field.
func (dc *DocumentCreate) SetUserID(s string) *DocumentCreate {
dc.mutation.SetUserID(s)
return dc
}
// SetCreatedAt sets the "created_at" field.
func (dc *DocumentCreate) SetCreatedAt(t time.Time) *DocumentCreate {
dc.mutation.SetCreatedAt(t)
return dc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dc *DocumentCreate) SetNillableCreatedAt(t *time.Time) *DocumentCreate {
if t != nil {
dc.SetCreatedAt(*t)
}
return dc
}
// SetUpdatedAt sets the "updated_at" field.
func (dc *DocumentCreate) SetUpdatedAt(t time.Time) *DocumentCreate {
dc.mutation.SetUpdatedAt(t)
return dc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dc *DocumentCreate) SetNillableUpdatedAt(t *time.Time) *DocumentCreate {
if t != nil {
dc.SetUpdatedAt(*t)
}
return dc
}
// Mutation returns the DocumentMutation object of the builder.
func (dc *DocumentCreate) Mutation() *DocumentMutation {
return dc.mutation
}
// Save creates the Document in the database.
func (dc *DocumentCreate) Save(ctx context.Context) (*Document, error) {
dc.defaults()
return withHooks(ctx, dc.sqlSave, dc.mutation, dc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (dc *DocumentCreate) SaveX(ctx context.Context) *Document {
v, err := dc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dc *DocumentCreate) Exec(ctx context.Context) error {
_, err := dc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dc *DocumentCreate) ExecX(ctx context.Context) {
if err := dc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (dc *DocumentCreate) defaults() {
if _, ok := dc.mutation.CreatedAt(); !ok {
v := document.DefaultCreatedAt()
dc.mutation.SetCreatedAt(v)
}
if _, ok := dc.mutation.UpdatedAt(); !ok {
v := document.DefaultUpdatedAt()
dc.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (dc *DocumentCreate) check() error {
if _, ok := dc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Document.name"`)}
}
if _, ok := dc.mutation.UserID(); !ok {
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "Document.user_id"`)}
}
if _, ok := dc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Document.created_at"`)}
}
if _, ok := dc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Document.updated_at"`)}
}
return nil
}
func (dc *DocumentCreate) sqlSave(ctx context.Context) (*Document, error) {
if err := dc.check(); err != nil {
return nil, err
}
_node, _spec := dc.createSpec()
if err := sqlgraph.CreateNode(ctx, dc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
dc.mutation.id = &_node.ID
dc.mutation.done = true
return _node, nil
}
func (dc *DocumentCreate) createSpec() (*Document, *sqlgraph.CreateSpec) {
var (
_node = &Document{config: dc.config}
_spec = sqlgraph.NewCreateSpec(document.Table, sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt))
)
if value, ok := dc.mutation.Name(); ok {
_spec.SetField(document.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := dc.mutation.UserID(); ok {
_spec.SetField(document.FieldUserID, field.TypeString, value)
_node.UserID = value
}
if value, ok := dc.mutation.CreatedAt(); ok {
_spec.SetField(document.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := dc.mutation.UpdatedAt(); ok {
_spec.SetField(document.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
return _node, _spec
}
// DocumentCreateBulk is the builder for creating many Document entities in bulk.
type DocumentCreateBulk struct {
config
err error
builders []*DocumentCreate
}
// Save creates the Document entities in the database.
func (dcb *DocumentCreateBulk) Save(ctx context.Context) ([]*Document, error) {
if dcb.err != nil {
return nil, dcb.err
}
specs := make([]*sqlgraph.CreateSpec, len(dcb.builders))
nodes := make([]*Document, len(dcb.builders))
mutators := make([]Mutator, len(dcb.builders))
for i := range dcb.builders {
func(i int, root context.Context) {
builder := dcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DocumentMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, dcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, dcb.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, dcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (dcb *DocumentCreateBulk) SaveX(ctx context.Context) []*Document {
v, err := dcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dcb *DocumentCreateBulk) Exec(ctx context.Context) error {
_, err := dcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dcb *DocumentCreateBulk) ExecX(ctx context.Context) {
if err := dcb.Exec(ctx); err != nil {
panic(err)
}
}

88
ent/document_delete.go Normal file
View File

@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/document"
"leafdev.top/leaf/rag/ent/predicate"
)
// DocumentDelete is the builder for deleting a Document entity.
type DocumentDelete struct {
config
hooks []Hook
mutation *DocumentMutation
}
// Where appends a list predicates to the DocumentDelete builder.
func (dd *DocumentDelete) Where(ps ...predicate.Document) *DocumentDelete {
dd.mutation.Where(ps...)
return dd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (dd *DocumentDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, dd.sqlExec, dd.mutation, dd.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (dd *DocumentDelete) ExecX(ctx context.Context) int {
n, err := dd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (dd *DocumentDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(document.Table, sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt))
if ps := dd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, dd.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
dd.mutation.done = true
return affected, err
}
// DocumentDeleteOne is the builder for deleting a single Document entity.
type DocumentDeleteOne struct {
dd *DocumentDelete
}
// Where appends a list predicates to the DocumentDelete builder.
func (ddo *DocumentDeleteOne) Where(ps ...predicate.Document) *DocumentDeleteOne {
ddo.dd.mutation.Where(ps...)
return ddo
}
// Exec executes the deletion query.
func (ddo *DocumentDeleteOne) Exec(ctx context.Context) error {
n, err := ddo.dd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{document.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (ddo *DocumentDeleteOne) ExecX(ctx context.Context) {
if err := ddo.Exec(ctx); err != nil {
panic(err)
}
}

531
ent/document_query.go Normal file
View File

@ -0,0 +1,531 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/document"
"leafdev.top/leaf/rag/ent/predicate"
)
// DocumentQuery is the builder for querying Document entities.
type DocumentQuery struct {
config
ctx *QueryContext
order []document.OrderOption
inters []Interceptor
predicates []predicate.Document
withFKs bool
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the DocumentQuery builder.
func (dq *DocumentQuery) Where(ps ...predicate.Document) *DocumentQuery {
dq.predicates = append(dq.predicates, ps...)
return dq
}
// Limit the number of records to be returned by this query.
func (dq *DocumentQuery) Limit(limit int) *DocumentQuery {
dq.ctx.Limit = &limit
return dq
}
// Offset to start from.
func (dq *DocumentQuery) Offset(offset int) *DocumentQuery {
dq.ctx.Offset = &offset
return dq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (dq *DocumentQuery) Unique(unique bool) *DocumentQuery {
dq.ctx.Unique = &unique
return dq
}
// Order specifies how the records should be ordered.
func (dq *DocumentQuery) Order(o ...document.OrderOption) *DocumentQuery {
dq.order = append(dq.order, o...)
return dq
}
// First returns the first Document entity from the query.
// Returns a *NotFoundError when no Document was found.
func (dq *DocumentQuery) First(ctx context.Context) (*Document, error) {
nodes, err := dq.Limit(1).All(setContextOp(ctx, dq.ctx, "First"))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{document.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (dq *DocumentQuery) FirstX(ctx context.Context) *Document {
node, err := dq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first Document ID from the query.
// Returns a *NotFoundError when no Document ID was found.
func (dq *DocumentQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = dq.Limit(1).IDs(setContextOp(ctx, dq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{document.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (dq *DocumentQuery) FirstIDX(ctx context.Context) int {
id, err := dq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single Document entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one Document entity is found.
// Returns a *NotFoundError when no Document entities are found.
func (dq *DocumentQuery) Only(ctx context.Context) (*Document, error) {
nodes, err := dq.Limit(2).All(setContextOp(ctx, dq.ctx, "Only"))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{document.Label}
default:
return nil, &NotSingularError{document.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (dq *DocumentQuery) OnlyX(ctx context.Context) *Document {
node, err := dq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only Document ID in the query.
// Returns a *NotSingularError when more than one Document ID is found.
// Returns a *NotFoundError when no entities are found.
func (dq *DocumentQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = dq.Limit(2).IDs(setContextOp(ctx, dq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{document.Label}
default:
err = &NotSingularError{document.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (dq *DocumentQuery) OnlyIDX(ctx context.Context) int {
id, err := dq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of Documents.
func (dq *DocumentQuery) All(ctx context.Context) ([]*Document, error) {
ctx = setContextOp(ctx, dq.ctx, "All")
if err := dq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*Document, *DocumentQuery]()
return withInterceptors[[]*Document](ctx, dq, qr, dq.inters)
}
// AllX is like All, but panics if an error occurs.
func (dq *DocumentQuery) AllX(ctx context.Context) []*Document {
nodes, err := dq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of Document IDs.
func (dq *DocumentQuery) IDs(ctx context.Context) (ids []int, err error) {
if dq.ctx.Unique == nil && dq.path != nil {
dq.Unique(true)
}
ctx = setContextOp(ctx, dq.ctx, "IDs")
if err = dq.Select(document.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (dq *DocumentQuery) IDsX(ctx context.Context) []int {
ids, err := dq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (dq *DocumentQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, dq.ctx, "Count")
if err := dq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, dq, querierCount[*DocumentQuery](), dq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (dq *DocumentQuery) CountX(ctx context.Context) int {
count, err := dq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (dq *DocumentQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, dq.ctx, "Exist")
switch _, err := dq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (dq *DocumentQuery) ExistX(ctx context.Context) bool {
exist, err := dq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the DocumentQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (dq *DocumentQuery) Clone() *DocumentQuery {
if dq == nil {
return nil
}
return &DocumentQuery{
config: dq.config,
ctx: dq.ctx.Clone(),
order: append([]document.OrderOption{}, dq.order...),
inters: append([]Interceptor{}, dq.inters...),
predicates: append([]predicate.Document{}, dq.predicates...),
// clone intermediate query.
sql: dq.sql.Clone(),
path: dq.path,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.Document.Query().
// GroupBy(document.FieldName).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (dq *DocumentQuery) GroupBy(field string, fields ...string) *DocumentGroupBy {
dq.ctx.Fields = append([]string{field}, fields...)
grbuild := &DocumentGroupBy{build: dq}
grbuild.flds = &dq.ctx.Fields
grbuild.label = document.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// }
//
// client.Document.Query().
// Select(document.FieldName).
// Scan(ctx, &v)
func (dq *DocumentQuery) Select(fields ...string) *DocumentSelect {
dq.ctx.Fields = append(dq.ctx.Fields, fields...)
sbuild := &DocumentSelect{DocumentQuery: dq}
sbuild.label = document.Label
sbuild.flds, sbuild.scan = &dq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a DocumentSelect configured with the given aggregations.
func (dq *DocumentQuery) Aggregate(fns ...AggregateFunc) *DocumentSelect {
return dq.Select().Aggregate(fns...)
}
func (dq *DocumentQuery) prepareQuery(ctx context.Context) error {
for _, inter := range dq.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, dq); err != nil {
return err
}
}
}
for _, f := range dq.ctx.Fields {
if !document.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if dq.path != nil {
prev, err := dq.path(ctx)
if err != nil {
return err
}
dq.sql = prev
}
return nil
}
func (dq *DocumentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Document, error) {
var (
nodes = []*Document{}
withFKs = dq.withFKs
_spec = dq.querySpec()
)
if withFKs {
_spec.Node.Columns = append(_spec.Node.Columns, document.ForeignKeys...)
}
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Document).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &Document{config: dq.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, dq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (dq *DocumentQuery) sqlCount(ctx context.Context) (int, error) {
_spec := dq.querySpec()
_spec.Node.Columns = dq.ctx.Fields
if len(dq.ctx.Fields) > 0 {
_spec.Unique = dq.ctx.Unique != nil && *dq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, dq.driver, _spec)
}
func (dq *DocumentQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(document.Table, document.Columns, sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt))
_spec.From = dq.sql
if unique := dq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if dq.path != nil {
_spec.Unique = true
}
if fields := dq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, document.FieldID)
for i := range fields {
if fields[i] != document.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := dq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := dq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := dq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := dq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (dq *DocumentQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(dq.driver.Dialect())
t1 := builder.Table(document.Table)
columns := dq.ctx.Fields
if len(columns) == 0 {
columns = document.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if dq.sql != nil {
selector = dq.sql
selector.Select(selector.Columns(columns...)...)
}
if dq.ctx.Unique != nil && *dq.ctx.Unique {
selector.Distinct()
}
for _, p := range dq.predicates {
p(selector)
}
for _, p := range dq.order {
p(selector)
}
if offset := dq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := dq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// DocumentGroupBy is the group-by builder for Document entities.
type DocumentGroupBy struct {
selector
build *DocumentQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (dgb *DocumentGroupBy) Aggregate(fns ...AggregateFunc) *DocumentGroupBy {
dgb.fns = append(dgb.fns, fns...)
return dgb
}
// Scan applies the selector query and scans the result into the given value.
func (dgb *DocumentGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, dgb.build.ctx, "GroupBy")
if err := dgb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*DocumentQuery, *DocumentGroupBy](ctx, dgb.build, dgb, dgb.build.inters, v)
}
func (dgb *DocumentGroupBy) sqlScan(ctx context.Context, root *DocumentQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(dgb.fns))
for _, fn := range dgb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*dgb.flds)+len(dgb.fns))
for _, f := range *dgb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*dgb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := dgb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// DocumentSelect is the builder for selecting fields of Document entities.
type DocumentSelect struct {
*DocumentQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (ds *DocumentSelect) Aggregate(fns ...AggregateFunc) *DocumentSelect {
ds.fns = append(ds.fns, fns...)
return ds
}
// Scan applies the selector query and scans the result into the given value.
func (ds *DocumentSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, ds.ctx, "Select")
if err := ds.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*DocumentQuery, *DocumentSelect](ctx, ds.DocumentQuery, ds, ds.inters, v)
}
func (ds *DocumentSelect) sqlScan(ctx context.Context, root *DocumentQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(ds.fns))
for _, fn := range ds.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*ds.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := ds.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}

312
ent/document_update.go Normal file
View File

@ -0,0 +1,312 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/document"
"leafdev.top/leaf/rag/ent/predicate"
)
// DocumentUpdate is the builder for updating Document entities.
type DocumentUpdate struct {
config
hooks []Hook
mutation *DocumentMutation
}
// Where appends a list predicates to the DocumentUpdate builder.
func (du *DocumentUpdate) Where(ps ...predicate.Document) *DocumentUpdate {
du.mutation.Where(ps...)
return du
}
// SetName sets the "name" field.
func (du *DocumentUpdate) SetName(s string) *DocumentUpdate {
du.mutation.SetName(s)
return du
}
// SetNillableName sets the "name" field if the given value is not nil.
func (du *DocumentUpdate) SetNillableName(s *string) *DocumentUpdate {
if s != nil {
du.SetName(*s)
}
return du
}
// SetUserID sets the "user_id" field.
func (du *DocumentUpdate) SetUserID(s string) *DocumentUpdate {
du.mutation.SetUserID(s)
return du
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (du *DocumentUpdate) SetNillableUserID(s *string) *DocumentUpdate {
if s != nil {
du.SetUserID(*s)
}
return du
}
// SetCreatedAt sets the "created_at" field.
func (du *DocumentUpdate) SetCreatedAt(t time.Time) *DocumentUpdate {
du.mutation.SetCreatedAt(t)
return du
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (du *DocumentUpdate) SetNillableCreatedAt(t *time.Time) *DocumentUpdate {
if t != nil {
du.SetCreatedAt(*t)
}
return du
}
// SetUpdatedAt sets the "updated_at" field.
func (du *DocumentUpdate) SetUpdatedAt(t time.Time) *DocumentUpdate {
du.mutation.SetUpdatedAt(t)
return du
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (du *DocumentUpdate) SetNillableUpdatedAt(t *time.Time) *DocumentUpdate {
if t != nil {
du.SetUpdatedAt(*t)
}
return du
}
// Mutation returns the DocumentMutation object of the builder.
func (du *DocumentUpdate) Mutation() *DocumentMutation {
return du.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (du *DocumentUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, du.sqlSave, du.mutation, du.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (du *DocumentUpdate) SaveX(ctx context.Context) int {
affected, err := du.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (du *DocumentUpdate) Exec(ctx context.Context) error {
_, err := du.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (du *DocumentUpdate) ExecX(ctx context.Context) {
if err := du.Exec(ctx); err != nil {
panic(err)
}
}
func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(document.Table, document.Columns, sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt))
if ps := du.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := du.mutation.Name(); ok {
_spec.SetField(document.FieldName, field.TypeString, value)
}
if value, ok := du.mutation.UserID(); ok {
_spec.SetField(document.FieldUserID, field.TypeString, value)
}
if value, ok := du.mutation.CreatedAt(); ok {
_spec.SetField(document.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := du.mutation.UpdatedAt(); ok {
_spec.SetField(document.FieldUpdatedAt, field.TypeTime, value)
}
if n, err = sqlgraph.UpdateNodes(ctx, du.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{document.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
du.mutation.done = true
return n, nil
}
// DocumentUpdateOne is the builder for updating a single Document entity.
type DocumentUpdateOne struct {
config
fields []string
hooks []Hook
mutation *DocumentMutation
}
// SetName sets the "name" field.
func (duo *DocumentUpdateOne) SetName(s string) *DocumentUpdateOne {
duo.mutation.SetName(s)
return duo
}
// SetNillableName sets the "name" field if the given value is not nil.
func (duo *DocumentUpdateOne) SetNillableName(s *string) *DocumentUpdateOne {
if s != nil {
duo.SetName(*s)
}
return duo
}
// SetUserID sets the "user_id" field.
func (duo *DocumentUpdateOne) SetUserID(s string) *DocumentUpdateOne {
duo.mutation.SetUserID(s)
return duo
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (duo *DocumentUpdateOne) SetNillableUserID(s *string) *DocumentUpdateOne {
if s != nil {
duo.SetUserID(*s)
}
return duo
}
// SetCreatedAt sets the "created_at" field.
func (duo *DocumentUpdateOne) SetCreatedAt(t time.Time) *DocumentUpdateOne {
duo.mutation.SetCreatedAt(t)
return duo
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (duo *DocumentUpdateOne) SetNillableCreatedAt(t *time.Time) *DocumentUpdateOne {
if t != nil {
duo.SetCreatedAt(*t)
}
return duo
}
// SetUpdatedAt sets the "updated_at" field.
func (duo *DocumentUpdateOne) SetUpdatedAt(t time.Time) *DocumentUpdateOne {
duo.mutation.SetUpdatedAt(t)
return duo
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (duo *DocumentUpdateOne) SetNillableUpdatedAt(t *time.Time) *DocumentUpdateOne {
if t != nil {
duo.SetUpdatedAt(*t)
}
return duo
}
// Mutation returns the DocumentMutation object of the builder.
func (duo *DocumentUpdateOne) Mutation() *DocumentMutation {
return duo.mutation
}
// Where appends a list predicates to the DocumentUpdate builder.
func (duo *DocumentUpdateOne) Where(ps ...predicate.Document) *DocumentUpdateOne {
duo.mutation.Where(ps...)
return duo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (duo *DocumentUpdateOne) Select(field string, fields ...string) *DocumentUpdateOne {
duo.fields = append([]string{field}, fields...)
return duo
}
// Save executes the query and returns the updated Document entity.
func (duo *DocumentUpdateOne) Save(ctx context.Context) (*Document, error) {
return withHooks(ctx, duo.sqlSave, duo.mutation, duo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (duo *DocumentUpdateOne) SaveX(ctx context.Context) *Document {
node, err := duo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (duo *DocumentUpdateOne) Exec(ctx context.Context) error {
_, err := duo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (duo *DocumentUpdateOne) ExecX(ctx context.Context) {
if err := duo.Exec(ctx); err != nil {
panic(err)
}
}
func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err error) {
_spec := sqlgraph.NewUpdateSpec(document.Table, document.Columns, sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt))
id, ok := duo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Document.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := duo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, document.FieldID)
for _, f := range fields {
if !document.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != document.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := duo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := duo.mutation.Name(); ok {
_spec.SetField(document.FieldName, field.TypeString, value)
}
if value, ok := duo.mutation.UserID(); ok {
_spec.SetField(document.FieldUserID, field.TypeString, value)
}
if value, ok := duo.mutation.CreatedAt(); ok {
_spec.SetField(document.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := duo.mutation.UpdatedAt(); ok {
_spec.SetField(document.FieldUpdatedAt, field.TypeTime, value)
}
_node = &Document{config: duo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, duo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{document.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
duo.mutation.done = true
return _node, nil
}

198
ent/documentblock.go Normal file
View File

@ -0,0 +1,198 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"leafdev.top/leaf/rag/ent/documentblock"
)
// DocumentBlock is the model entity for the DocumentBlock schema.
type DocumentBlock struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Content holds the value of the "content" field.
Content string `json:"content,omitempty"`
// Order holds the value of the "order" field.
Order int `json:"order,omitempty"`
// DocumentID holds the value of the "document_id" field.
DocumentID int `json:"document_id,omitempty"`
// UserID holds the value of the "user_id" field.
UserID string `json:"user_id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the DocumentBlockQuery when eager-loading is set.
Edges DocumentBlockEdges `json:"edges"`
selectValues sql.SelectValues
}
// DocumentBlockEdges holds the relations/edges for other nodes in the graph.
type DocumentBlockEdges struct {
// Document holds the value of the document edge.
Document []*Document `json:"document,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// DocumentOrErr returns the Document value or an error if the edge
// was not loaded in eager-loading.
func (e DocumentBlockEdges) DocumentOrErr() ([]*Document, error) {
if e.loadedTypes[0] {
return e.Document, nil
}
return nil, &NotLoadedError{edge: "document"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*DocumentBlock) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case documentblock.FieldID, documentblock.FieldOrder, documentblock.FieldDocumentID:
values[i] = new(sql.NullInt64)
case documentblock.FieldName, documentblock.FieldContent, documentblock.FieldUserID:
values[i] = new(sql.NullString)
case documentblock.FieldCreatedAt, documentblock.FieldUpdatedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the DocumentBlock fields.
func (db *DocumentBlock) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case documentblock.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
db.ID = int(value.Int64)
case documentblock.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
db.Name = value.String
}
case documentblock.FieldContent:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field content", values[i])
} else if value.Valid {
db.Content = value.String
}
case documentblock.FieldOrder:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field order", values[i])
} else if value.Valid {
db.Order = int(value.Int64)
}
case documentblock.FieldDocumentID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field document_id", values[i])
} else if value.Valid {
db.DocumentID = int(value.Int64)
}
case documentblock.FieldUserID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field user_id", values[i])
} else if value.Valid {
db.UserID = value.String
}
case documentblock.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
db.CreatedAt = value.Time
}
case documentblock.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
db.UpdatedAt = value.Time
}
default:
db.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the DocumentBlock.
// This includes values selected through modifiers, order, etc.
func (db *DocumentBlock) Value(name string) (ent.Value, error) {
return db.selectValues.Get(name)
}
// QueryDocument queries the "document" edge of the DocumentBlock entity.
func (db *DocumentBlock) QueryDocument() *DocumentQuery {
return NewDocumentBlockClient(db.config).QueryDocument(db)
}
// Update returns a builder for updating this DocumentBlock.
// Note that you need to call DocumentBlock.Unwrap() before calling this method if this DocumentBlock
// was returned from a transaction, and the transaction was committed or rolled back.
func (db *DocumentBlock) Update() *DocumentBlockUpdateOne {
return NewDocumentBlockClient(db.config).UpdateOne(db)
}
// Unwrap unwraps the DocumentBlock entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (db *DocumentBlock) Unwrap() *DocumentBlock {
_tx, ok := db.config.driver.(*txDriver)
if !ok {
panic("ent: DocumentBlock is not a transactional entity")
}
db.config.driver = _tx.drv
return db
}
// String implements the fmt.Stringer.
func (db *DocumentBlock) String() string {
var builder strings.Builder
builder.WriteString("DocumentBlock(")
builder.WriteString(fmt.Sprintf("id=%v, ", db.ID))
builder.WriteString("name=")
builder.WriteString(db.Name)
builder.WriteString(", ")
builder.WriteString("content=")
builder.WriteString(db.Content)
builder.WriteString(", ")
builder.WriteString("order=")
builder.WriteString(fmt.Sprintf("%v", db.Order))
builder.WriteString(", ")
builder.WriteString("document_id=")
builder.WriteString(fmt.Sprintf("%v", db.DocumentID))
builder.WriteString(", ")
builder.WriteString("user_id=")
builder.WriteString(db.UserID)
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(db.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(db.UpdatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// DocumentBlocks is a parsable slice of DocumentBlock.
type DocumentBlocks []*DocumentBlock

View File

@ -0,0 +1,135 @@
// Code generated by ent, DO NOT EDIT.
package documentblock
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the documentblock type in the database.
Label = "document_block"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldContent holds the string denoting the content field in the database.
FieldContent = "content"
// FieldOrder holds the string denoting the order field in the database.
FieldOrder = "order"
// FieldDocumentID holds the string denoting the document_id field in the database.
FieldDocumentID = "document_id"
// FieldUserID holds the string denoting the user_id field in the database.
FieldUserID = "user_id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// EdgeDocument holds the string denoting the document edge name in mutations.
EdgeDocument = "document"
// Table holds the table name of the documentblock in the database.
Table = "document_blocks"
// DocumentTable is the table that holds the document relation/edge.
DocumentTable = "documents"
// DocumentInverseTable is the table name for the Document entity.
// It exists in this package in order to avoid circular dependency with the "document" package.
DocumentInverseTable = "documents"
// DocumentColumn is the table column denoting the document relation/edge.
DocumentColumn = "document_block_document"
)
// Columns holds all SQL columns for documentblock fields.
var Columns = []string{
FieldID,
FieldName,
FieldContent,
FieldOrder,
FieldDocumentID,
FieldUserID,
FieldCreatedAt,
FieldUpdatedAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
)
// OrderOption defines the ordering options for the DocumentBlock queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByContent orders the results by the content field.
func ByContent(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldContent, opts...).ToFunc()
}
// ByOrder orders the results by the order field.
func ByOrder(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldOrder, opts...).ToFunc()
}
// ByDocumentID orders the results by the document_id field.
func ByDocumentID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDocumentID, opts...).ToFunc()
}
// ByUserID orders the results by the user_id field.
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUserID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByDocumentCount orders the results by document count.
func ByDocumentCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newDocumentStep(), opts...)
}
}
// ByDocument orders the results by document terms.
func ByDocument(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newDocumentStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newDocumentStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(DocumentInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, DocumentTable, DocumentColumn),
)
}

484
ent/documentblock/where.go Normal file
View File

@ -0,0 +1,484 @@
// Code generated by ent, DO NOT EDIT.
package documentblock
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"leafdev.top/leaf/rag/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLTE(FieldID, id))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldName, v))
}
// Content applies equality check predicate on the "content" field. It's identical to ContentEQ.
func Content(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldContent, v))
}
// Order applies equality check predicate on the "order" field. It's identical to OrderEQ.
func Order(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldOrder, v))
}
// DocumentID applies equality check predicate on the "document_id" field. It's identical to DocumentIDEQ.
func DocumentID(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldDocumentID, v))
}
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
func UserID(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldUserID, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldUpdatedAt, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldContainsFold(FieldName, v))
}
// ContentEQ applies the EQ predicate on the "content" field.
func ContentEQ(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldContent, v))
}
// ContentNEQ applies the NEQ predicate on the "content" field.
func ContentNEQ(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNEQ(FieldContent, v))
}
// ContentIn applies the In predicate on the "content" field.
func ContentIn(vs ...string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldIn(FieldContent, vs...))
}
// ContentNotIn applies the NotIn predicate on the "content" field.
func ContentNotIn(vs ...string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNotIn(FieldContent, vs...))
}
// ContentGT applies the GT predicate on the "content" field.
func ContentGT(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGT(FieldContent, v))
}
// ContentGTE applies the GTE predicate on the "content" field.
func ContentGTE(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGTE(FieldContent, v))
}
// ContentLT applies the LT predicate on the "content" field.
func ContentLT(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLT(FieldContent, v))
}
// ContentLTE applies the LTE predicate on the "content" field.
func ContentLTE(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLTE(FieldContent, v))
}
// ContentContains applies the Contains predicate on the "content" field.
func ContentContains(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldContains(FieldContent, v))
}
// ContentHasPrefix applies the HasPrefix predicate on the "content" field.
func ContentHasPrefix(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldHasPrefix(FieldContent, v))
}
// ContentHasSuffix applies the HasSuffix predicate on the "content" field.
func ContentHasSuffix(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldHasSuffix(FieldContent, v))
}
// ContentEqualFold applies the EqualFold predicate on the "content" field.
func ContentEqualFold(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEqualFold(FieldContent, v))
}
// ContentContainsFold applies the ContainsFold predicate on the "content" field.
func ContentContainsFold(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldContainsFold(FieldContent, v))
}
// OrderEQ applies the EQ predicate on the "order" field.
func OrderEQ(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldOrder, v))
}
// OrderNEQ applies the NEQ predicate on the "order" field.
func OrderNEQ(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNEQ(FieldOrder, v))
}
// OrderIn applies the In predicate on the "order" field.
func OrderIn(vs ...int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldIn(FieldOrder, vs...))
}
// OrderNotIn applies the NotIn predicate on the "order" field.
func OrderNotIn(vs ...int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNotIn(FieldOrder, vs...))
}
// OrderGT applies the GT predicate on the "order" field.
func OrderGT(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGT(FieldOrder, v))
}
// OrderGTE applies the GTE predicate on the "order" field.
func OrderGTE(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGTE(FieldOrder, v))
}
// OrderLT applies the LT predicate on the "order" field.
func OrderLT(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLT(FieldOrder, v))
}
// OrderLTE applies the LTE predicate on the "order" field.
func OrderLTE(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLTE(FieldOrder, v))
}
// DocumentIDEQ applies the EQ predicate on the "document_id" field.
func DocumentIDEQ(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldDocumentID, v))
}
// DocumentIDNEQ applies the NEQ predicate on the "document_id" field.
func DocumentIDNEQ(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNEQ(FieldDocumentID, v))
}
// DocumentIDIn applies the In predicate on the "document_id" field.
func DocumentIDIn(vs ...int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldIn(FieldDocumentID, vs...))
}
// DocumentIDNotIn applies the NotIn predicate on the "document_id" field.
func DocumentIDNotIn(vs ...int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNotIn(FieldDocumentID, vs...))
}
// DocumentIDGT applies the GT predicate on the "document_id" field.
func DocumentIDGT(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGT(FieldDocumentID, v))
}
// DocumentIDGTE applies the GTE predicate on the "document_id" field.
func DocumentIDGTE(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGTE(FieldDocumentID, v))
}
// DocumentIDLT applies the LT predicate on the "document_id" field.
func DocumentIDLT(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLT(FieldDocumentID, v))
}
// DocumentIDLTE applies the LTE predicate on the "document_id" field.
func DocumentIDLTE(v int) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLTE(FieldDocumentID, v))
}
// UserIDEQ applies the EQ predicate on the "user_id" field.
func UserIDEQ(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldUserID, v))
}
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
func UserIDNEQ(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNEQ(FieldUserID, v))
}
// UserIDIn applies the In predicate on the "user_id" field.
func UserIDIn(vs ...string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldIn(FieldUserID, vs...))
}
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
func UserIDNotIn(vs ...string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNotIn(FieldUserID, vs...))
}
// UserIDGT applies the GT predicate on the "user_id" field.
func UserIDGT(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGT(FieldUserID, v))
}
// UserIDGTE applies the GTE predicate on the "user_id" field.
func UserIDGTE(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGTE(FieldUserID, v))
}
// UserIDLT applies the LT predicate on the "user_id" field.
func UserIDLT(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLT(FieldUserID, v))
}
// UserIDLTE applies the LTE predicate on the "user_id" field.
func UserIDLTE(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLTE(FieldUserID, v))
}
// UserIDContains applies the Contains predicate on the "user_id" field.
func UserIDContains(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldContains(FieldUserID, v))
}
// UserIDHasPrefix applies the HasPrefix predicate on the "user_id" field.
func UserIDHasPrefix(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldHasPrefix(FieldUserID, v))
}
// UserIDHasSuffix applies the HasSuffix predicate on the "user_id" field.
func UserIDHasSuffix(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldHasSuffix(FieldUserID, v))
}
// UserIDEqualFold applies the EqualFold predicate on the "user_id" field.
func UserIDEqualFold(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEqualFold(FieldUserID, v))
}
// UserIDContainsFold applies the ContainsFold predicate on the "user_id" field.
func UserIDContainsFold(v string) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldContainsFold(FieldUserID, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.FieldLTE(FieldUpdatedAt, v))
}
// HasDocument applies the HasEdge predicate on the "document" edge.
func HasDocument() predicate.DocumentBlock {
return predicate.DocumentBlock(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, DocumentTable, DocumentColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasDocumentWith applies the HasEdge predicate on the "document" edge with a given conditions (other predicates).
func HasDocumentWith(preds ...predicate.Document) predicate.DocumentBlock {
return predicate.DocumentBlock(func(s *sql.Selector) {
step := newDocumentStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.DocumentBlock) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.DocumentBlock) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.DocumentBlock) predicate.DocumentBlock {
return predicate.DocumentBlock(sql.NotPredicates(p))
}

324
ent/documentblock_create.go Normal file
View File

@ -0,0 +1,324 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/document"
"leafdev.top/leaf/rag/ent/documentblock"
)
// DocumentBlockCreate is the builder for creating a DocumentBlock entity.
type DocumentBlockCreate struct {
config
mutation *DocumentBlockMutation
hooks []Hook
}
// SetName sets the "name" field.
func (dbc *DocumentBlockCreate) SetName(s string) *DocumentBlockCreate {
dbc.mutation.SetName(s)
return dbc
}
// SetContent sets the "content" field.
func (dbc *DocumentBlockCreate) SetContent(s string) *DocumentBlockCreate {
dbc.mutation.SetContent(s)
return dbc
}
// SetOrder sets the "order" field.
func (dbc *DocumentBlockCreate) SetOrder(i int) *DocumentBlockCreate {
dbc.mutation.SetOrder(i)
return dbc
}
// SetDocumentID sets the "document_id" field.
func (dbc *DocumentBlockCreate) SetDocumentID(i int) *DocumentBlockCreate {
dbc.mutation.SetDocumentID(i)
return dbc
}
// SetUserID sets the "user_id" field.
func (dbc *DocumentBlockCreate) SetUserID(s string) *DocumentBlockCreate {
dbc.mutation.SetUserID(s)
return dbc
}
// SetCreatedAt sets the "created_at" field.
func (dbc *DocumentBlockCreate) SetCreatedAt(t time.Time) *DocumentBlockCreate {
dbc.mutation.SetCreatedAt(t)
return dbc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dbc *DocumentBlockCreate) SetNillableCreatedAt(t *time.Time) *DocumentBlockCreate {
if t != nil {
dbc.SetCreatedAt(*t)
}
return dbc
}
// SetUpdatedAt sets the "updated_at" field.
func (dbc *DocumentBlockCreate) SetUpdatedAt(t time.Time) *DocumentBlockCreate {
dbc.mutation.SetUpdatedAt(t)
return dbc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dbc *DocumentBlockCreate) SetNillableUpdatedAt(t *time.Time) *DocumentBlockCreate {
if t != nil {
dbc.SetUpdatedAt(*t)
}
return dbc
}
// AddDocumentIDs adds the "document" edge to the Document entity by IDs.
func (dbc *DocumentBlockCreate) AddDocumentIDs(ids ...int) *DocumentBlockCreate {
dbc.mutation.AddDocumentIDs(ids...)
return dbc
}
// AddDocument adds the "document" edges to the Document entity.
func (dbc *DocumentBlockCreate) AddDocument(d ...*Document) *DocumentBlockCreate {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dbc.AddDocumentIDs(ids...)
}
// Mutation returns the DocumentBlockMutation object of the builder.
func (dbc *DocumentBlockCreate) Mutation() *DocumentBlockMutation {
return dbc.mutation
}
// Save creates the DocumentBlock in the database.
func (dbc *DocumentBlockCreate) Save(ctx context.Context) (*DocumentBlock, error) {
dbc.defaults()
return withHooks(ctx, dbc.sqlSave, dbc.mutation, dbc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (dbc *DocumentBlockCreate) SaveX(ctx context.Context) *DocumentBlock {
v, err := dbc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dbc *DocumentBlockCreate) Exec(ctx context.Context) error {
_, err := dbc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dbc *DocumentBlockCreate) ExecX(ctx context.Context) {
if err := dbc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (dbc *DocumentBlockCreate) defaults() {
if _, ok := dbc.mutation.CreatedAt(); !ok {
v := documentblock.DefaultCreatedAt()
dbc.mutation.SetCreatedAt(v)
}
if _, ok := dbc.mutation.UpdatedAt(); !ok {
v := documentblock.DefaultUpdatedAt()
dbc.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (dbc *DocumentBlockCreate) check() error {
if _, ok := dbc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "DocumentBlock.name"`)}
}
if _, ok := dbc.mutation.Content(); !ok {
return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "DocumentBlock.content"`)}
}
if _, ok := dbc.mutation.Order(); !ok {
return &ValidationError{Name: "order", err: errors.New(`ent: missing required field "DocumentBlock.order"`)}
}
if _, ok := dbc.mutation.DocumentID(); !ok {
return &ValidationError{Name: "document_id", err: errors.New(`ent: missing required field "DocumentBlock.document_id"`)}
}
if _, ok := dbc.mutation.UserID(); !ok {
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "DocumentBlock.user_id"`)}
}
if _, ok := dbc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "DocumentBlock.created_at"`)}
}
if _, ok := dbc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "DocumentBlock.updated_at"`)}
}
return nil
}
func (dbc *DocumentBlockCreate) sqlSave(ctx context.Context) (*DocumentBlock, error) {
if err := dbc.check(); err != nil {
return nil, err
}
_node, _spec := dbc.createSpec()
if err := sqlgraph.CreateNode(ctx, dbc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
dbc.mutation.id = &_node.ID
dbc.mutation.done = true
return _node, nil
}
func (dbc *DocumentBlockCreate) createSpec() (*DocumentBlock, *sqlgraph.CreateSpec) {
var (
_node = &DocumentBlock{config: dbc.config}
_spec = sqlgraph.NewCreateSpec(documentblock.Table, sqlgraph.NewFieldSpec(documentblock.FieldID, field.TypeInt))
)
if value, ok := dbc.mutation.Name(); ok {
_spec.SetField(documentblock.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := dbc.mutation.Content(); ok {
_spec.SetField(documentblock.FieldContent, field.TypeString, value)
_node.Content = value
}
if value, ok := dbc.mutation.Order(); ok {
_spec.SetField(documentblock.FieldOrder, field.TypeInt, value)
_node.Order = value
}
if value, ok := dbc.mutation.DocumentID(); ok {
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt, value)
_node.DocumentID = value
}
if value, ok := dbc.mutation.UserID(); ok {
_spec.SetField(documentblock.FieldUserID, field.TypeString, value)
_node.UserID = value
}
if value, ok := dbc.mutation.CreatedAt(); ok {
_spec.SetField(documentblock.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := dbc.mutation.UpdatedAt(); ok {
_spec.SetField(documentblock.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if nodes := dbc.mutation.DocumentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// DocumentBlockCreateBulk is the builder for creating many DocumentBlock entities in bulk.
type DocumentBlockCreateBulk struct {
config
err error
builders []*DocumentBlockCreate
}
// Save creates the DocumentBlock entities in the database.
func (dbcb *DocumentBlockCreateBulk) Save(ctx context.Context) ([]*DocumentBlock, error) {
if dbcb.err != nil {
return nil, dbcb.err
}
specs := make([]*sqlgraph.CreateSpec, len(dbcb.builders))
nodes := make([]*DocumentBlock, len(dbcb.builders))
mutators := make([]Mutator, len(dbcb.builders))
for i := range dbcb.builders {
func(i int, root context.Context) {
builder := dbcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DocumentBlockMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, dbcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, dbcb.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, dbcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (dbcb *DocumentBlockCreateBulk) SaveX(ctx context.Context) []*DocumentBlock {
v, err := dbcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dbcb *DocumentBlockCreateBulk) Exec(ctx context.Context) error {
_, err := dbcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dbcb *DocumentBlockCreateBulk) ExecX(ctx context.Context) {
if err := dbcb.Exec(ctx); err != nil {
panic(err)
}
}

View File

@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/documentblock"
"leafdev.top/leaf/rag/ent/predicate"
)
// DocumentBlockDelete is the builder for deleting a DocumentBlock entity.
type DocumentBlockDelete struct {
config
hooks []Hook
mutation *DocumentBlockMutation
}
// Where appends a list predicates to the DocumentBlockDelete builder.
func (dbd *DocumentBlockDelete) Where(ps ...predicate.DocumentBlock) *DocumentBlockDelete {
dbd.mutation.Where(ps...)
return dbd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (dbd *DocumentBlockDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, dbd.sqlExec, dbd.mutation, dbd.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (dbd *DocumentBlockDelete) ExecX(ctx context.Context) int {
n, err := dbd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (dbd *DocumentBlockDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(documentblock.Table, sqlgraph.NewFieldSpec(documentblock.FieldID, field.TypeInt))
if ps := dbd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, dbd.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
dbd.mutation.done = true
return affected, err
}
// DocumentBlockDeleteOne is the builder for deleting a single DocumentBlock entity.
type DocumentBlockDeleteOne struct {
dbd *DocumentBlockDelete
}
// Where appends a list predicates to the DocumentBlockDelete builder.
func (dbdo *DocumentBlockDeleteOne) Where(ps ...predicate.DocumentBlock) *DocumentBlockDeleteOne {
dbdo.dbd.mutation.Where(ps...)
return dbdo
}
// Exec executes the deletion query.
func (dbdo *DocumentBlockDeleteOne) Exec(ctx context.Context) error {
n, err := dbdo.dbd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{documentblock.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (dbdo *DocumentBlockDeleteOne) ExecX(ctx context.Context) {
if err := dbdo.Exec(ctx); err != nil {
panic(err)
}
}

606
ent/documentblock_query.go Normal file
View File

@ -0,0 +1,606 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"database/sql/driver"
"fmt"
"math"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/document"
"leafdev.top/leaf/rag/ent/documentblock"
"leafdev.top/leaf/rag/ent/predicate"
)
// DocumentBlockQuery is the builder for querying DocumentBlock entities.
type DocumentBlockQuery struct {
config
ctx *QueryContext
order []documentblock.OrderOption
inters []Interceptor
predicates []predicate.DocumentBlock
withDocument *DocumentQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the DocumentBlockQuery builder.
func (dbq *DocumentBlockQuery) Where(ps ...predicate.DocumentBlock) *DocumentBlockQuery {
dbq.predicates = append(dbq.predicates, ps...)
return dbq
}
// Limit the number of records to be returned by this query.
func (dbq *DocumentBlockQuery) Limit(limit int) *DocumentBlockQuery {
dbq.ctx.Limit = &limit
return dbq
}
// Offset to start from.
func (dbq *DocumentBlockQuery) Offset(offset int) *DocumentBlockQuery {
dbq.ctx.Offset = &offset
return dbq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (dbq *DocumentBlockQuery) Unique(unique bool) *DocumentBlockQuery {
dbq.ctx.Unique = &unique
return dbq
}
// Order specifies how the records should be ordered.
func (dbq *DocumentBlockQuery) Order(o ...documentblock.OrderOption) *DocumentBlockQuery {
dbq.order = append(dbq.order, o...)
return dbq
}
// QueryDocument chains the current query on the "document" edge.
func (dbq *DocumentBlockQuery) QueryDocument() *DocumentQuery {
query := (&DocumentClient{config: dbq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := dbq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := dbq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(documentblock.Table, documentblock.FieldID, selector),
sqlgraph.To(document.Table, document.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, documentblock.DocumentTable, documentblock.DocumentColumn),
)
fromU = sqlgraph.SetNeighbors(dbq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first DocumentBlock entity from the query.
// Returns a *NotFoundError when no DocumentBlock was found.
func (dbq *DocumentBlockQuery) First(ctx context.Context) (*DocumentBlock, error) {
nodes, err := dbq.Limit(1).All(setContextOp(ctx, dbq.ctx, "First"))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{documentblock.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (dbq *DocumentBlockQuery) FirstX(ctx context.Context) *DocumentBlock {
node, err := dbq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first DocumentBlock ID from the query.
// Returns a *NotFoundError when no DocumentBlock ID was found.
func (dbq *DocumentBlockQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = dbq.Limit(1).IDs(setContextOp(ctx, dbq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{documentblock.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (dbq *DocumentBlockQuery) FirstIDX(ctx context.Context) int {
id, err := dbq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single DocumentBlock entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one DocumentBlock entity is found.
// Returns a *NotFoundError when no DocumentBlock entities are found.
func (dbq *DocumentBlockQuery) Only(ctx context.Context) (*DocumentBlock, error) {
nodes, err := dbq.Limit(2).All(setContextOp(ctx, dbq.ctx, "Only"))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{documentblock.Label}
default:
return nil, &NotSingularError{documentblock.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (dbq *DocumentBlockQuery) OnlyX(ctx context.Context) *DocumentBlock {
node, err := dbq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only DocumentBlock ID in the query.
// Returns a *NotSingularError when more than one DocumentBlock ID is found.
// Returns a *NotFoundError when no entities are found.
func (dbq *DocumentBlockQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = dbq.Limit(2).IDs(setContextOp(ctx, dbq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{documentblock.Label}
default:
err = &NotSingularError{documentblock.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (dbq *DocumentBlockQuery) OnlyIDX(ctx context.Context) int {
id, err := dbq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of DocumentBlocks.
func (dbq *DocumentBlockQuery) All(ctx context.Context) ([]*DocumentBlock, error) {
ctx = setContextOp(ctx, dbq.ctx, "All")
if err := dbq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*DocumentBlock, *DocumentBlockQuery]()
return withInterceptors[[]*DocumentBlock](ctx, dbq, qr, dbq.inters)
}
// AllX is like All, but panics if an error occurs.
func (dbq *DocumentBlockQuery) AllX(ctx context.Context) []*DocumentBlock {
nodes, err := dbq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of DocumentBlock IDs.
func (dbq *DocumentBlockQuery) IDs(ctx context.Context) (ids []int, err error) {
if dbq.ctx.Unique == nil && dbq.path != nil {
dbq.Unique(true)
}
ctx = setContextOp(ctx, dbq.ctx, "IDs")
if err = dbq.Select(documentblock.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (dbq *DocumentBlockQuery) IDsX(ctx context.Context) []int {
ids, err := dbq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (dbq *DocumentBlockQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, dbq.ctx, "Count")
if err := dbq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, dbq, querierCount[*DocumentBlockQuery](), dbq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (dbq *DocumentBlockQuery) CountX(ctx context.Context) int {
count, err := dbq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (dbq *DocumentBlockQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, dbq.ctx, "Exist")
switch _, err := dbq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (dbq *DocumentBlockQuery) ExistX(ctx context.Context) bool {
exist, err := dbq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the DocumentBlockQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (dbq *DocumentBlockQuery) Clone() *DocumentBlockQuery {
if dbq == nil {
return nil
}
return &DocumentBlockQuery{
config: dbq.config,
ctx: dbq.ctx.Clone(),
order: append([]documentblock.OrderOption{}, dbq.order...),
inters: append([]Interceptor{}, dbq.inters...),
predicates: append([]predicate.DocumentBlock{}, dbq.predicates...),
withDocument: dbq.withDocument.Clone(),
// clone intermediate query.
sql: dbq.sql.Clone(),
path: dbq.path,
}
}
// WithDocument tells the query-builder to eager-load the nodes that are connected to
// the "document" edge. The optional arguments are used to configure the query builder of the edge.
func (dbq *DocumentBlockQuery) WithDocument(opts ...func(*DocumentQuery)) *DocumentBlockQuery {
query := (&DocumentClient{config: dbq.config}).Query()
for _, opt := range opts {
opt(query)
}
dbq.withDocument = query
return dbq
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.DocumentBlock.Query().
// GroupBy(documentblock.FieldName).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (dbq *DocumentBlockQuery) GroupBy(field string, fields ...string) *DocumentBlockGroupBy {
dbq.ctx.Fields = append([]string{field}, fields...)
grbuild := &DocumentBlockGroupBy{build: dbq}
grbuild.flds = &dbq.ctx.Fields
grbuild.label = documentblock.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// }
//
// client.DocumentBlock.Query().
// Select(documentblock.FieldName).
// Scan(ctx, &v)
func (dbq *DocumentBlockQuery) Select(fields ...string) *DocumentBlockSelect {
dbq.ctx.Fields = append(dbq.ctx.Fields, fields...)
sbuild := &DocumentBlockSelect{DocumentBlockQuery: dbq}
sbuild.label = documentblock.Label
sbuild.flds, sbuild.scan = &dbq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a DocumentBlockSelect configured with the given aggregations.
func (dbq *DocumentBlockQuery) Aggregate(fns ...AggregateFunc) *DocumentBlockSelect {
return dbq.Select().Aggregate(fns...)
}
func (dbq *DocumentBlockQuery) prepareQuery(ctx context.Context) error {
for _, inter := range dbq.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, dbq); err != nil {
return err
}
}
}
for _, f := range dbq.ctx.Fields {
if !documentblock.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if dbq.path != nil {
prev, err := dbq.path(ctx)
if err != nil {
return err
}
dbq.sql = prev
}
return nil
}
func (dbq *DocumentBlockQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*DocumentBlock, error) {
var (
nodes = []*DocumentBlock{}
_spec = dbq.querySpec()
loadedTypes = [1]bool{
dbq.withDocument != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*DocumentBlock).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &DocumentBlock{config: dbq.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, dbq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := dbq.withDocument; query != nil {
if err := dbq.loadDocument(ctx, query, nodes,
func(n *DocumentBlock) { n.Edges.Document = []*Document{} },
func(n *DocumentBlock, e *Document) { n.Edges.Document = append(n.Edges.Document, e) }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (dbq *DocumentBlockQuery) loadDocument(ctx context.Context, query *DocumentQuery, nodes []*DocumentBlock, init func(*DocumentBlock), assign func(*DocumentBlock, *Document)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int]*DocumentBlock)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
if init != nil {
init(nodes[i])
}
}
query.withFKs = true
query.Where(predicate.Document(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(documentblock.DocumentColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.document_block_document
if fk == nil {
return fmt.Errorf(`foreign-key "document_block_document" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "document_block_document" returned %v for node %v`, *fk, n.ID)
}
assign(node, n)
}
return nil
}
func (dbq *DocumentBlockQuery) sqlCount(ctx context.Context) (int, error) {
_spec := dbq.querySpec()
_spec.Node.Columns = dbq.ctx.Fields
if len(dbq.ctx.Fields) > 0 {
_spec.Unique = dbq.ctx.Unique != nil && *dbq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, dbq.driver, _spec)
}
func (dbq *DocumentBlockQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(documentblock.Table, documentblock.Columns, sqlgraph.NewFieldSpec(documentblock.FieldID, field.TypeInt))
_spec.From = dbq.sql
if unique := dbq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if dbq.path != nil {
_spec.Unique = true
}
if fields := dbq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, documentblock.FieldID)
for i := range fields {
if fields[i] != documentblock.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := dbq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := dbq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := dbq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := dbq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (dbq *DocumentBlockQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(dbq.driver.Dialect())
t1 := builder.Table(documentblock.Table)
columns := dbq.ctx.Fields
if len(columns) == 0 {
columns = documentblock.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if dbq.sql != nil {
selector = dbq.sql
selector.Select(selector.Columns(columns...)...)
}
if dbq.ctx.Unique != nil && *dbq.ctx.Unique {
selector.Distinct()
}
for _, p := range dbq.predicates {
p(selector)
}
for _, p := range dbq.order {
p(selector)
}
if offset := dbq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := dbq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// DocumentBlockGroupBy is the group-by builder for DocumentBlock entities.
type DocumentBlockGroupBy struct {
selector
build *DocumentBlockQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (dbgb *DocumentBlockGroupBy) Aggregate(fns ...AggregateFunc) *DocumentBlockGroupBy {
dbgb.fns = append(dbgb.fns, fns...)
return dbgb
}
// Scan applies the selector query and scans the result into the given value.
func (dbgb *DocumentBlockGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, dbgb.build.ctx, "GroupBy")
if err := dbgb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*DocumentBlockQuery, *DocumentBlockGroupBy](ctx, dbgb.build, dbgb, dbgb.build.inters, v)
}
func (dbgb *DocumentBlockGroupBy) sqlScan(ctx context.Context, root *DocumentBlockQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(dbgb.fns))
for _, fn := range dbgb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*dbgb.flds)+len(dbgb.fns))
for _, f := range *dbgb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*dbgb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := dbgb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// DocumentBlockSelect is the builder for selecting fields of DocumentBlock entities.
type DocumentBlockSelect struct {
*DocumentBlockQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (dbs *DocumentBlockSelect) Aggregate(fns ...AggregateFunc) *DocumentBlockSelect {
dbs.fns = append(dbs.fns, fns...)
return dbs
}
// Scan applies the selector query and scans the result into the given value.
func (dbs *DocumentBlockSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, dbs.ctx, "Select")
if err := dbs.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*DocumentBlockQuery, *DocumentBlockSelect](ctx, dbs.DocumentBlockQuery, dbs, dbs.inters, v)
}
func (dbs *DocumentBlockSelect) sqlScan(ctx context.Context, root *DocumentBlockQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(dbs.fns))
for _, fn := range dbs.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*dbs.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := dbs.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}

617
ent/documentblock_update.go Normal file
View File

@ -0,0 +1,617 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/document"
"leafdev.top/leaf/rag/ent/documentblock"
"leafdev.top/leaf/rag/ent/predicate"
)
// DocumentBlockUpdate is the builder for updating DocumentBlock entities.
type DocumentBlockUpdate struct {
config
hooks []Hook
mutation *DocumentBlockMutation
}
// Where appends a list predicates to the DocumentBlockUpdate builder.
func (dbu *DocumentBlockUpdate) Where(ps ...predicate.DocumentBlock) *DocumentBlockUpdate {
dbu.mutation.Where(ps...)
return dbu
}
// SetName sets the "name" field.
func (dbu *DocumentBlockUpdate) SetName(s string) *DocumentBlockUpdate {
dbu.mutation.SetName(s)
return dbu
}
// SetNillableName sets the "name" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableName(s *string) *DocumentBlockUpdate {
if s != nil {
dbu.SetName(*s)
}
return dbu
}
// SetContent sets the "content" field.
func (dbu *DocumentBlockUpdate) SetContent(s string) *DocumentBlockUpdate {
dbu.mutation.SetContent(s)
return dbu
}
// SetNillableContent sets the "content" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableContent(s *string) *DocumentBlockUpdate {
if s != nil {
dbu.SetContent(*s)
}
return dbu
}
// SetOrder sets the "order" field.
func (dbu *DocumentBlockUpdate) SetOrder(i int) *DocumentBlockUpdate {
dbu.mutation.ResetOrder()
dbu.mutation.SetOrder(i)
return dbu
}
// SetNillableOrder sets the "order" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableOrder(i *int) *DocumentBlockUpdate {
if i != nil {
dbu.SetOrder(*i)
}
return dbu
}
// AddOrder adds i to the "order" field.
func (dbu *DocumentBlockUpdate) AddOrder(i int) *DocumentBlockUpdate {
dbu.mutation.AddOrder(i)
return dbu
}
// SetDocumentID sets the "document_id" field.
func (dbu *DocumentBlockUpdate) SetDocumentID(i int) *DocumentBlockUpdate {
dbu.mutation.ResetDocumentID()
dbu.mutation.SetDocumentID(i)
return dbu
}
// SetNillableDocumentID sets the "document_id" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableDocumentID(i *int) *DocumentBlockUpdate {
if i != nil {
dbu.SetDocumentID(*i)
}
return dbu
}
// AddDocumentID adds i to the "document_id" field.
func (dbu *DocumentBlockUpdate) AddDocumentID(i int) *DocumentBlockUpdate {
dbu.mutation.AddDocumentID(i)
return dbu
}
// SetUserID sets the "user_id" field.
func (dbu *DocumentBlockUpdate) SetUserID(s string) *DocumentBlockUpdate {
dbu.mutation.SetUserID(s)
return dbu
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableUserID(s *string) *DocumentBlockUpdate {
if s != nil {
dbu.SetUserID(*s)
}
return dbu
}
// SetCreatedAt sets the "created_at" field.
func (dbu *DocumentBlockUpdate) SetCreatedAt(t time.Time) *DocumentBlockUpdate {
dbu.mutation.SetCreatedAt(t)
return dbu
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableCreatedAt(t *time.Time) *DocumentBlockUpdate {
if t != nil {
dbu.SetCreatedAt(*t)
}
return dbu
}
// SetUpdatedAt sets the "updated_at" field.
func (dbu *DocumentBlockUpdate) SetUpdatedAt(t time.Time) *DocumentBlockUpdate {
dbu.mutation.SetUpdatedAt(t)
return dbu
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableUpdatedAt(t *time.Time) *DocumentBlockUpdate {
if t != nil {
dbu.SetUpdatedAt(*t)
}
return dbu
}
// AddDocumentIDs adds the "document" edge to the Document entity by IDs.
func (dbu *DocumentBlockUpdate) AddDocumentIDs(ids ...int) *DocumentBlockUpdate {
dbu.mutation.AddDocumentIDs(ids...)
return dbu
}
// AddDocument adds the "document" edges to the Document entity.
func (dbu *DocumentBlockUpdate) AddDocument(d ...*Document) *DocumentBlockUpdate {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dbu.AddDocumentIDs(ids...)
}
// Mutation returns the DocumentBlockMutation object of the builder.
func (dbu *DocumentBlockUpdate) Mutation() *DocumentBlockMutation {
return dbu.mutation
}
// ClearDocument clears all "document" edges to the Document entity.
func (dbu *DocumentBlockUpdate) ClearDocument() *DocumentBlockUpdate {
dbu.mutation.ClearDocument()
return dbu
}
// RemoveDocumentIDs removes the "document" edge to Document entities by IDs.
func (dbu *DocumentBlockUpdate) RemoveDocumentIDs(ids ...int) *DocumentBlockUpdate {
dbu.mutation.RemoveDocumentIDs(ids...)
return dbu
}
// RemoveDocument removes "document" edges to Document entities.
func (dbu *DocumentBlockUpdate) RemoveDocument(d ...*Document) *DocumentBlockUpdate {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dbu.RemoveDocumentIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (dbu *DocumentBlockUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, dbu.sqlSave, dbu.mutation, dbu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (dbu *DocumentBlockUpdate) SaveX(ctx context.Context) int {
affected, err := dbu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (dbu *DocumentBlockUpdate) Exec(ctx context.Context) error {
_, err := dbu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dbu *DocumentBlockUpdate) ExecX(ctx context.Context) {
if err := dbu.Exec(ctx); err != nil {
panic(err)
}
}
func (dbu *DocumentBlockUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(documentblock.Table, documentblock.Columns, sqlgraph.NewFieldSpec(documentblock.FieldID, field.TypeInt))
if ps := dbu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := dbu.mutation.Name(); ok {
_spec.SetField(documentblock.FieldName, field.TypeString, value)
}
if value, ok := dbu.mutation.Content(); ok {
_spec.SetField(documentblock.FieldContent, field.TypeString, value)
}
if value, ok := dbu.mutation.Order(); ok {
_spec.SetField(documentblock.FieldOrder, field.TypeInt, value)
}
if value, ok := dbu.mutation.AddedOrder(); ok {
_spec.AddField(documentblock.FieldOrder, field.TypeInt, value)
}
if value, ok := dbu.mutation.DocumentID(); ok {
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt, value)
}
if value, ok := dbu.mutation.AddedDocumentID(); ok {
_spec.AddField(documentblock.FieldDocumentID, field.TypeInt, value)
}
if value, ok := dbu.mutation.UserID(); ok {
_spec.SetField(documentblock.FieldUserID, field.TypeString, value)
}
if value, ok := dbu.mutation.CreatedAt(); ok {
_spec.SetField(documentblock.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := dbu.mutation.UpdatedAt(); ok {
_spec.SetField(documentblock.FieldUpdatedAt, field.TypeTime, value)
}
if dbu.mutation.DocumentCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dbu.mutation.RemovedDocumentIDs(); len(nodes) > 0 && !dbu.mutation.DocumentCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dbu.mutation.DocumentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, dbu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{documentblock.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
dbu.mutation.done = true
return n, nil
}
// DocumentBlockUpdateOne is the builder for updating a single DocumentBlock entity.
type DocumentBlockUpdateOne struct {
config
fields []string
hooks []Hook
mutation *DocumentBlockMutation
}
// SetName sets the "name" field.
func (dbuo *DocumentBlockUpdateOne) SetName(s string) *DocumentBlockUpdateOne {
dbuo.mutation.SetName(s)
return dbuo
}
// SetNillableName sets the "name" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableName(s *string) *DocumentBlockUpdateOne {
if s != nil {
dbuo.SetName(*s)
}
return dbuo
}
// SetContent sets the "content" field.
func (dbuo *DocumentBlockUpdateOne) SetContent(s string) *DocumentBlockUpdateOne {
dbuo.mutation.SetContent(s)
return dbuo
}
// SetNillableContent sets the "content" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableContent(s *string) *DocumentBlockUpdateOne {
if s != nil {
dbuo.SetContent(*s)
}
return dbuo
}
// SetOrder sets the "order" field.
func (dbuo *DocumentBlockUpdateOne) SetOrder(i int) *DocumentBlockUpdateOne {
dbuo.mutation.ResetOrder()
dbuo.mutation.SetOrder(i)
return dbuo
}
// SetNillableOrder sets the "order" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableOrder(i *int) *DocumentBlockUpdateOne {
if i != nil {
dbuo.SetOrder(*i)
}
return dbuo
}
// AddOrder adds i to the "order" field.
func (dbuo *DocumentBlockUpdateOne) AddOrder(i int) *DocumentBlockUpdateOne {
dbuo.mutation.AddOrder(i)
return dbuo
}
// SetDocumentID sets the "document_id" field.
func (dbuo *DocumentBlockUpdateOne) SetDocumentID(i int) *DocumentBlockUpdateOne {
dbuo.mutation.ResetDocumentID()
dbuo.mutation.SetDocumentID(i)
return dbuo
}
// SetNillableDocumentID sets the "document_id" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableDocumentID(i *int) *DocumentBlockUpdateOne {
if i != nil {
dbuo.SetDocumentID(*i)
}
return dbuo
}
// AddDocumentID adds i to the "document_id" field.
func (dbuo *DocumentBlockUpdateOne) AddDocumentID(i int) *DocumentBlockUpdateOne {
dbuo.mutation.AddDocumentID(i)
return dbuo
}
// SetUserID sets the "user_id" field.
func (dbuo *DocumentBlockUpdateOne) SetUserID(s string) *DocumentBlockUpdateOne {
dbuo.mutation.SetUserID(s)
return dbuo
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableUserID(s *string) *DocumentBlockUpdateOne {
if s != nil {
dbuo.SetUserID(*s)
}
return dbuo
}
// SetCreatedAt sets the "created_at" field.
func (dbuo *DocumentBlockUpdateOne) SetCreatedAt(t time.Time) *DocumentBlockUpdateOne {
dbuo.mutation.SetCreatedAt(t)
return dbuo
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableCreatedAt(t *time.Time) *DocumentBlockUpdateOne {
if t != nil {
dbuo.SetCreatedAt(*t)
}
return dbuo
}
// SetUpdatedAt sets the "updated_at" field.
func (dbuo *DocumentBlockUpdateOne) SetUpdatedAt(t time.Time) *DocumentBlockUpdateOne {
dbuo.mutation.SetUpdatedAt(t)
return dbuo
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableUpdatedAt(t *time.Time) *DocumentBlockUpdateOne {
if t != nil {
dbuo.SetUpdatedAt(*t)
}
return dbuo
}
// AddDocumentIDs adds the "document" edge to the Document entity by IDs.
func (dbuo *DocumentBlockUpdateOne) AddDocumentIDs(ids ...int) *DocumentBlockUpdateOne {
dbuo.mutation.AddDocumentIDs(ids...)
return dbuo
}
// AddDocument adds the "document" edges to the Document entity.
func (dbuo *DocumentBlockUpdateOne) AddDocument(d ...*Document) *DocumentBlockUpdateOne {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dbuo.AddDocumentIDs(ids...)
}
// Mutation returns the DocumentBlockMutation object of the builder.
func (dbuo *DocumentBlockUpdateOne) Mutation() *DocumentBlockMutation {
return dbuo.mutation
}
// ClearDocument clears all "document" edges to the Document entity.
func (dbuo *DocumentBlockUpdateOne) ClearDocument() *DocumentBlockUpdateOne {
dbuo.mutation.ClearDocument()
return dbuo
}
// RemoveDocumentIDs removes the "document" edge to Document entities by IDs.
func (dbuo *DocumentBlockUpdateOne) RemoveDocumentIDs(ids ...int) *DocumentBlockUpdateOne {
dbuo.mutation.RemoveDocumentIDs(ids...)
return dbuo
}
// RemoveDocument removes "document" edges to Document entities.
func (dbuo *DocumentBlockUpdateOne) RemoveDocument(d ...*Document) *DocumentBlockUpdateOne {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dbuo.RemoveDocumentIDs(ids...)
}
// Where appends a list predicates to the DocumentBlockUpdate builder.
func (dbuo *DocumentBlockUpdateOne) Where(ps ...predicate.DocumentBlock) *DocumentBlockUpdateOne {
dbuo.mutation.Where(ps...)
return dbuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (dbuo *DocumentBlockUpdateOne) Select(field string, fields ...string) *DocumentBlockUpdateOne {
dbuo.fields = append([]string{field}, fields...)
return dbuo
}
// Save executes the query and returns the updated DocumentBlock entity.
func (dbuo *DocumentBlockUpdateOne) Save(ctx context.Context) (*DocumentBlock, error) {
return withHooks(ctx, dbuo.sqlSave, dbuo.mutation, dbuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (dbuo *DocumentBlockUpdateOne) SaveX(ctx context.Context) *DocumentBlock {
node, err := dbuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (dbuo *DocumentBlockUpdateOne) Exec(ctx context.Context) error {
_, err := dbuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dbuo *DocumentBlockUpdateOne) ExecX(ctx context.Context) {
if err := dbuo.Exec(ctx); err != nil {
panic(err)
}
}
func (dbuo *DocumentBlockUpdateOne) sqlSave(ctx context.Context) (_node *DocumentBlock, err error) {
_spec := sqlgraph.NewUpdateSpec(documentblock.Table, documentblock.Columns, sqlgraph.NewFieldSpec(documentblock.FieldID, field.TypeInt))
id, ok := dbuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "DocumentBlock.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := dbuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, documentblock.FieldID)
for _, f := range fields {
if !documentblock.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != documentblock.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := dbuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := dbuo.mutation.Name(); ok {
_spec.SetField(documentblock.FieldName, field.TypeString, value)
}
if value, ok := dbuo.mutation.Content(); ok {
_spec.SetField(documentblock.FieldContent, field.TypeString, value)
}
if value, ok := dbuo.mutation.Order(); ok {
_spec.SetField(documentblock.FieldOrder, field.TypeInt, value)
}
if value, ok := dbuo.mutation.AddedOrder(); ok {
_spec.AddField(documentblock.FieldOrder, field.TypeInt, value)
}
if value, ok := dbuo.mutation.DocumentID(); ok {
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt, value)
}
if value, ok := dbuo.mutation.AddedDocumentID(); ok {
_spec.AddField(documentblock.FieldDocumentID, field.TypeInt, value)
}
if value, ok := dbuo.mutation.UserID(); ok {
_spec.SetField(documentblock.FieldUserID, field.TypeString, value)
}
if value, ok := dbuo.mutation.CreatedAt(); ok {
_spec.SetField(documentblock.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := dbuo.mutation.UpdatedAt(); ok {
_spec.SetField(documentblock.FieldUpdatedAt, field.TypeTime, value)
}
if dbuo.mutation.DocumentCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dbuo.mutation.RemovedDocumentIDs(); len(nodes) > 0 && !dbuo.mutation.DocumentCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dbuo.mutation.DocumentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &DocumentBlock{config: dbuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, dbuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{documentblock.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
dbuo.mutation.done = true
return _node, nil
}

35
ent/schema/document.go Normal file
View File

@ -0,0 +1,35 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"time"
)
// Document holds the schema definition for the Document entity.
type Document struct {
ent.Schema
}
// Fields of the Document.
func (Document) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
field.String("user_id"),
field.Time("created_at").Default(time.Now),
field.Time("updated_at").Default(time.Now),
}
}
// Edges of the Document.
func (Document) Edges() []ent.Edge {
return nil
}
func (Document) Indexes() []ent.Index {
return []ent.Index{
index.Fields("name", "user_id"),
}
}

View File

@ -0,0 +1,43 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"time"
)
// DocumentBlock holds the schema definition for the DocumentBlock entity.
type DocumentBlock struct {
ent.Schema
}
// Fields of the DocumentBlock.
func (DocumentBlock) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
field.String("content"),
// order
field.Int("order"),
// document id
field.Int("document_id"),
field.String("user_id"),
field.Time("created_at").Default(time.Now),
field.Time("updated_at").Default(time.Now),
}
}
// Edges of the DocumentBlock.
func (DocumentBlock) Edges() []ent.Edge {
return []ent.Edge{
edge.To("document", Document.Type),
}
}
func (DocumentBlock) Indexes() []ent.Index {
return []ent.Index{
index.Fields("name", "user_id", "order"),
}
}

View File

@ -0,0 +1,19 @@
-- +goose Up
-- create "document_blocks" table
CREATE TABLE "document_blocks" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "content" character varying NOT NULL, "document_id" bigint NOT NULL, "user_id" character varying NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, PRIMARY KEY ("id"));
-- create index "documentblock_name_user_id" to table: "document_blocks"
CREATE INDEX "documentblock_name_user_id" ON "document_blocks" ("name", "user_id");
-- create "documents" table
CREATE TABLE "documents" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "user_id" character varying NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, "document_block_document" bigint NULL, PRIMARY KEY ("id"), CONSTRAINT "documents_document_blocks_document" FOREIGN KEY ("document_block_document") REFERENCES "document_blocks" ("id") ON DELETE SET NULL);
-- create index "document_name_user_id" to table: "documents"
CREATE INDEX "document_name_user_id" ON "documents" ("name", "user_id");
-- +goose Down
-- reverse: create index "document_name_user_id" to table: "documents"
DROP INDEX "document_name_user_id";
-- reverse: create "documents" table
DROP TABLE "documents";
-- reverse: create index "documentblock_name_user_id" to table: "document_blocks"
DROP INDEX "documentblock_name_user_id";
-- reverse: create "document_blocks" table
DROP TABLE "document_blocks";

View File

@ -0,0 +1,11 @@
-- +goose Up
-- modify "document_blocks" table
ALTER TABLE "document_blocks" ADD COLUMN "order" bigint NOT NULL;
-- create index "documentblock_name_user_id_order" to table: "document_blocks"
CREATE INDEX "documentblock_name_user_id_order" ON "document_blocks" ("name", "user_id", "order");
-- +goose Down
-- reverse: create index "documentblock_name_user_id_order" to table: "document_blocks"
DROP INDEX "documentblock_name_user_id_order";
-- reverse: modify "document_blocks" table
ALTER TABLE "document_blocks" DROP COLUMN "order";