// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/safedep/vet/ent/codesignaturematch"
"github.com/safedep/vet/ent/codesourcefile"
)
// CodeSignatureMatchCreate is the builder for creating a CodeSignatureMatch entity.
type CodeSignatureMatchCreate struct {
config
mutation *CodeSignatureMatchMutation
hooks []Hook
}
// SetSignatureID sets the "signature_id" field.
func (csmc *CodeSignatureMatchCreate) SetSignatureID(s string) *CodeSignatureMatchCreate {
csmc.mutation.SetSignatureID(s)
return csmc
}
// SetSignatureVendor sets the "signature_vendor" field.
func (csmc *CodeSignatureMatchCreate) SetSignatureVendor(s string) *CodeSignatureMatchCreate {
csmc.mutation.SetSignatureVendor(s)
return csmc
}
// SetNillableSignatureVendor sets the "signature_vendor" field if the given value is not nil.
func (csmc *CodeSignatureMatchCreate) SetNillableSignatureVendor(s *string) *CodeSignatureMatchCreate {
if s != nil {
csmc.SetSignatureVendor(*s)
}
return csmc
}
// SetSignatureProduct sets the "signature_product" field.
func (csmc *CodeSignatureMatchCreate) SetSignatureProduct(s string) *CodeSignatureMatchCreate {
csmc.mutation.SetSignatureProduct(s)
return csmc
}
// SetNillableSignatureProduct sets the "signature_product" field if the given value is not nil.
func (csmc *CodeSignatureMatchCreate) SetNillableSignatureProduct(s *string) *CodeSignatureMatchCreate {
if s != nil {
csmc.SetSignatureProduct(*s)
}
return csmc
}
// SetSignatureService sets the "signature_service" field.
func (csmc *CodeSignatureMatchCreate) SetSignatureService(s string) *CodeSignatureMatchCreate {
csmc.mutation.SetSignatureService(s)
return csmc
}
// SetNillableSignatureService sets the "signature_service" field if the given value is not nil.
func (csmc *CodeSignatureMatchCreate) SetNillableSignatureService(s *string) *CodeSignatureMatchCreate {
if s != nil {
csmc.SetSignatureService(*s)
}
return csmc
}
// SetSignatureDescription sets the "signature_description" field.
func (csmc *CodeSignatureMatchCreate) SetSignatureDescription(s string) *CodeSignatureMatchCreate {
csmc.mutation.SetSignatureDescription(s)
return csmc
}
// SetNillableSignatureDescription sets the "signature_description" field if the given value is not nil.
func (csmc *CodeSignatureMatchCreate) SetNillableSignatureDescription(s *string) *CodeSignatureMatchCreate {
if s != nil {
csmc.SetSignatureDescription(*s)
}
return csmc
}
// SetTags sets the "tags" field.
func (csmc *CodeSignatureMatchCreate) SetTags(s []string) *CodeSignatureMatchCreate {
csmc.mutation.SetTags(s)
return csmc
}
// SetFilePath sets the "file_path" field.
func (csmc *CodeSignatureMatchCreate) SetFilePath(s string) *CodeSignatureMatchCreate {
csmc.mutation.SetFilePath(s)
return csmc
}
// SetLanguage sets the "language" field.
func (csmc *CodeSignatureMatchCreate) SetLanguage(s string) *CodeSignatureMatchCreate {
csmc.mutation.SetLanguage(s)
return csmc
}
// SetLine sets the "line" field.
func (csmc *CodeSignatureMatchCreate) SetLine(u uint) *CodeSignatureMatchCreate {
csmc.mutation.SetLine(u)
return csmc
}
// SetNillableLine sets the "line" field if the given value is not nil.
func (csmc *CodeSignatureMatchCreate) SetNillableLine(u *uint) *CodeSignatureMatchCreate {
if u != nil {
csmc.SetLine(*u)
}
return csmc
}
// SetColumn sets the "column" field.
func (csmc *CodeSignatureMatchCreate) SetColumn(u uint) *CodeSignatureMatchCreate {
csmc.mutation.SetColumn(u)
return csmc
}
// SetNillableColumn sets the "column" field if the given value is not nil.
func (csmc *CodeSignatureMatchCreate) SetNillableColumn(u *uint) *CodeSignatureMatchCreate {
if u != nil {
csmc.SetColumn(*u)
}
return csmc
}
// SetCalleeNamespace sets the "callee_namespace" field.
func (csmc *CodeSignatureMatchCreate) SetCalleeNamespace(s string) *CodeSignatureMatchCreate {
csmc.mutation.SetCalleeNamespace(s)
return csmc
}
// SetNillableCalleeNamespace sets the "callee_namespace" field if the given value is not nil.
func (csmc *CodeSignatureMatchCreate) SetNillableCalleeNamespace(s *string) *CodeSignatureMatchCreate {
if s != nil {
csmc.SetCalleeNamespace(*s)
}
return csmc
}
// SetMatchedCall sets the "matched_call" field.
func (csmc *CodeSignatureMatchCreate) SetMatchedCall(s string) *CodeSignatureMatchCreate {
csmc.mutation.SetMatchedCall(s)
return csmc
}
// SetNillableMatchedCall sets the "matched_call" field if the given value is not nil.
func (csmc *CodeSignatureMatchCreate) SetNillableMatchedCall(s *string) *CodeSignatureMatchCreate {
if s != nil {
csmc.SetMatchedCall(*s)
}
return csmc
}
// SetPackageHint sets the "package_hint" field.
func (csmc *CodeSignatureMatchCreate) SetPackageHint(s string) *CodeSignatureMatchCreate {
csmc.mutation.SetPackageHint(s)
return csmc
}
// SetNillablePackageHint sets the "package_hint" field if the given value is not nil.
func (csmc *CodeSignatureMatchCreate) SetNillablePackageHint(s *string) *CodeSignatureMatchCreate {
if s != nil {
csmc.SetPackageHint(*s)
}
return csmc
}
// SetSourceFileID sets the "source_file" edge to the CodeSourceFile entity by ID.
func (csmc *CodeSignatureMatchCreate) SetSourceFileID(id int) *CodeSignatureMatchCreate {
csmc.mutation.SetSourceFileID(id)
return csmc
}
// SetSourceFile sets the "source_file" edge to the CodeSourceFile entity.
func (csmc *CodeSignatureMatchCreate) SetSourceFile(c *CodeSourceFile) *CodeSignatureMatchCreate {
return csmc.SetSourceFileID(c.ID)
}
// Mutation returns the CodeSignatureMatchMutation object of the builder.
func (csmc *CodeSignatureMatchCreate) Mutation() *CodeSignatureMatchMutation {
return csmc.mutation
}
// Save creates the CodeSignatureMatch in the database.
func (csmc *CodeSignatureMatchCreate) Save(ctx context.Context) (*CodeSignatureMatch, error) {
return withHooks(ctx, csmc.sqlSave, csmc.mutation, csmc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (csmc *CodeSignatureMatchCreate) SaveX(ctx context.Context) *CodeSignatureMatch {
v, err := csmc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (csmc *CodeSignatureMatchCreate) Exec(ctx context.Context) error {
_, err := csmc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (csmc *CodeSignatureMatchCreate) ExecX(ctx context.Context) {
if err := csmc.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (csmc *CodeSignatureMatchCreate) check() error {
if _, ok := csmc.mutation.SignatureID(); !ok {
return &ValidationError{Name: "signature_id", err: errors.New(`ent: missing required field "CodeSignatureMatch.signature_id"`)}
}
if v, ok := csmc.mutation.SignatureID(); ok {
if err := codesignaturematch.SignatureIDValidator(v); err != nil {
return &ValidationError{Name: "signature_id", err: fmt.Errorf(`ent: validator failed for field "CodeSignatureMatch.signature_id": %w`, err)}
}
}
if _, ok := csmc.mutation.FilePath(); !ok {
return &ValidationError{Name: "file_path", err: errors.New(`ent: missing required field "CodeSignatureMatch.file_path"`)}
}
if v, ok := csmc.mutation.FilePath(); ok {
if err := codesignaturematch.FilePathValidator(v); err != nil {
return &ValidationError{Name: "file_path", err: fmt.Errorf(`ent: validator failed for field "CodeSignatureMatch.file_path": %w`, err)}
}
}
if _, ok := csmc.mutation.Language(); !ok {
return &ValidationError{Name: "language", err: errors.New(`ent: missing required field "CodeSignatureMatch.language"`)}
}
if v, ok := csmc.mutation.Language(); ok {
if err := codesignaturematch.LanguageValidator(v); err != nil {
return &ValidationError{Name: "language", err: fmt.Errorf(`ent: validator failed for field "CodeSignatureMatch.language": %w`, err)}
}
}
if len(csmc.mutation.SourceFileIDs()) == 0 {
return &ValidationError{Name: "source_file", err: errors.New(`ent: missing required edge "CodeSignatureMatch.source_file"`)}
}
return nil
}
func (csmc *CodeSignatureMatchCreate) sqlSave(ctx context.Context) (*CodeSignatureMatch, error) {
if err := csmc.check(); err != nil {
return nil, err
}
_node, _spec := csmc.createSpec()
if err := sqlgraph.CreateNode(ctx, csmc.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)
csmc.mutation.id = &_node.ID
csmc.mutation.done = true
return _node, nil
}
func (csmc *CodeSignatureMatchCreate) createSpec() (*CodeSignatureMatch, *sqlgraph.CreateSpec) {
var (
_node = &CodeSignatureMatch{config: csmc.config}
_spec = sqlgraph.NewCreateSpec(codesignaturematch.Table, sqlgraph.NewFieldSpec(codesignaturematch.FieldID, field.TypeInt))
)
if value, ok := csmc.mutation.SignatureID(); ok {
_spec.SetField(codesignaturematch.FieldSignatureID, field.TypeString, value)
_node.SignatureID = value
}
if value, ok := csmc.mutation.SignatureVendor(); ok {
_spec.SetField(codesignaturematch.FieldSignatureVendor, field.TypeString, value)
_node.SignatureVendor = value
}
if value, ok := csmc.mutation.SignatureProduct(); ok {
_spec.SetField(codesignaturematch.FieldSignatureProduct, field.TypeString, value)
_node.SignatureProduct = value
}
if value, ok := csmc.mutation.SignatureService(); ok {
_spec.SetField(codesignaturematch.FieldSignatureService, field.TypeString, value)
_node.SignatureService = value
}
if value, ok := csmc.mutation.SignatureDescription(); ok {
_spec.SetField(codesignaturematch.FieldSignatureDescription, field.TypeString, value)
_node.SignatureDescription = value
}
if value, ok := csmc.mutation.Tags(); ok {
_spec.SetField(codesignaturematch.FieldTags, field.TypeJSON, value)
_node.Tags = value
}
if value, ok := csmc.mutation.FilePath(); ok {
_spec.SetField(codesignaturematch.FieldFilePath, field.TypeString, value)
_node.FilePath = value
}
if value, ok := csmc.mutation.Language(); ok {
_spec.SetField(codesignaturematch.FieldLanguage, field.TypeString, value)
_node.Language = value
}
if value, ok := csmc.mutation.Line(); ok {
_spec.SetField(codesignaturematch.FieldLine, field.TypeUint, value)
_node.Line = value
}
if value, ok := csmc.mutation.Column(); ok {
_spec.SetField(codesignaturematch.FieldColumn, field.TypeUint, value)
_node.Column = value
}
if value, ok := csmc.mutation.CalleeNamespace(); ok {
_spec.SetField(codesignaturematch.FieldCalleeNamespace, field.TypeString, value)
_node.CalleeNamespace = value
}
if value, ok := csmc.mutation.MatchedCall(); ok {
_spec.SetField(codesignaturematch.FieldMatchedCall, field.TypeString, value)
_node.MatchedCall = value
}
if value, ok := csmc.mutation.PackageHint(); ok {
_spec.SetField(codesignaturematch.FieldPackageHint, field.TypeString, value)
_node.PackageHint = &value
}
if nodes := csmc.mutation.SourceFileIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: codesignaturematch.SourceFileTable,
Columns: []string{codesignaturematch.SourceFileColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(codesourcefile.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.code_signature_match_source_file = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// CodeSignatureMatchCreateBulk is the builder for creating many CodeSignatureMatch entities in bulk.
type CodeSignatureMatchCreateBulk struct {
config
err error
builders []*CodeSignatureMatchCreate
}
// Save creates the CodeSignatureMatch entities in the database.
func (csmcb *CodeSignatureMatchCreateBulk) Save(ctx context.Context) ([]*CodeSignatureMatch, error) {
if csmcb.err != nil {
return nil, csmcb.err
}
specs := make([]*sqlgraph.CreateSpec, len(csmcb.builders))
nodes := make([]*CodeSignatureMatch, len(csmcb.builders))
mutators := make([]Mutator, len(csmcb.builders))
for i := range csmcb.builders {
func(i int, root context.Context) {
builder := csmcb.builders[i]
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*CodeSignatureMatchMutation)
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, csmcb.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, csmcb.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, csmcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (csmcb *CodeSignatureMatchCreateBulk) SaveX(ctx context.Context) []*CodeSignatureMatch {
v, err := csmcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (csmcb *CodeSignatureMatchCreateBulk) Exec(ctx context.Context) error {
_, err := csmcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (csmcb *CodeSignatureMatchCreateBulk) ExecX(ctx context.Context) {
if err := csmcb.Exec(ctx); err != nil {
panic(err)
}
}