github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/ent.go (about) 1 // Code generated by ent, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "context" 7 "errors" 8 "fmt" 9 10 "entgo.io/ent" 11 "entgo.io/ent/dialect/sql" 12 "entgo.io/ent/dialect/sql/sqlgraph" 13 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/appcoin" 14 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/chainbase" 15 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/coinbase" 16 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/coindescription" 17 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/coinextra" 18 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/coinfiat" 19 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/coinfiatcurrency" 20 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/coinfiatcurrencyhistory" 21 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/coinusedfor" 22 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/currency" 23 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/currencyfeed" 24 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/currencyhistory" 25 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/exchangerate" 26 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/fiat" 27 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/fiatcurrency" 28 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/fiatcurrencyfeed" 29 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/fiatcurrencyhistory" 30 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/setting" 31 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/tran" 32 ) 33 34 // ent aliases to avoid import conflicts in user's code. 35 type ( 36 Op = ent.Op 37 Hook = ent.Hook 38 Value = ent.Value 39 Query = ent.Query 40 Policy = ent.Policy 41 Mutator = ent.Mutator 42 Mutation = ent.Mutation 43 MutateFunc = ent.MutateFunc 44 ) 45 46 // OrderFunc applies an ordering on the sql selector. 47 type OrderFunc func(*sql.Selector) 48 49 // columnChecker returns a function indicates if the column exists in the given column. 50 func columnChecker(table string) func(string) error { 51 checks := map[string]func(string) bool{ 52 appcoin.Table: appcoin.ValidColumn, 53 chainbase.Table: chainbase.ValidColumn, 54 coinbase.Table: coinbase.ValidColumn, 55 coindescription.Table: coindescription.ValidColumn, 56 coinextra.Table: coinextra.ValidColumn, 57 coinfiat.Table: coinfiat.ValidColumn, 58 coinfiatcurrency.Table: coinfiatcurrency.ValidColumn, 59 coinfiatcurrencyhistory.Table: coinfiatcurrencyhistory.ValidColumn, 60 coinusedfor.Table: coinusedfor.ValidColumn, 61 currency.Table: currency.ValidColumn, 62 currencyfeed.Table: currencyfeed.ValidColumn, 63 currencyhistory.Table: currencyhistory.ValidColumn, 64 exchangerate.Table: exchangerate.ValidColumn, 65 fiat.Table: fiat.ValidColumn, 66 fiatcurrency.Table: fiatcurrency.ValidColumn, 67 fiatcurrencyfeed.Table: fiatcurrencyfeed.ValidColumn, 68 fiatcurrencyhistory.Table: fiatcurrencyhistory.ValidColumn, 69 setting.Table: setting.ValidColumn, 70 tran.Table: tran.ValidColumn, 71 } 72 check, ok := checks[table] 73 if !ok { 74 return func(string) error { 75 return fmt.Errorf("unknown table %q", table) 76 } 77 } 78 return func(column string) error { 79 if !check(column) { 80 return fmt.Errorf("unknown column %q for table %q", column, table) 81 } 82 return nil 83 } 84 } 85 86 // Asc applies the given fields in ASC order. 87 func Asc(fields ...string) OrderFunc { 88 return func(s *sql.Selector) { 89 check := columnChecker(s.TableName()) 90 for _, f := range fields { 91 if err := check(f); err != nil { 92 s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) 93 } 94 s.OrderBy(sql.Asc(s.C(f))) 95 } 96 } 97 } 98 99 // Desc applies the given fields in DESC order. 100 func Desc(fields ...string) OrderFunc { 101 return func(s *sql.Selector) { 102 check := columnChecker(s.TableName()) 103 for _, f := range fields { 104 if err := check(f); err != nil { 105 s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) 106 } 107 s.OrderBy(sql.Desc(s.C(f))) 108 } 109 } 110 } 111 112 // AggregateFunc applies an aggregation step on the group-by traversal/selector. 113 type AggregateFunc func(*sql.Selector) string 114 115 // As is a pseudo aggregation function for renaming another other functions with custom names. For example: 116 // 117 // GroupBy(field1, field2). 118 // Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")). 119 // Scan(ctx, &v) 120 // 121 func As(fn AggregateFunc, end string) AggregateFunc { 122 return func(s *sql.Selector) string { 123 return sql.As(fn(s), end) 124 } 125 } 126 127 // Count applies the "count" aggregation function on each group. 128 func Count() AggregateFunc { 129 return func(s *sql.Selector) string { 130 return sql.Count("*") 131 } 132 } 133 134 // Max applies the "max" aggregation function on the given field of each group. 135 func Max(field string) AggregateFunc { 136 return func(s *sql.Selector) string { 137 check := columnChecker(s.TableName()) 138 if err := check(field); err != nil { 139 s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) 140 return "" 141 } 142 return sql.Max(s.C(field)) 143 } 144 } 145 146 // Mean applies the "mean" aggregation function on the given field of each group. 147 func Mean(field string) AggregateFunc { 148 return func(s *sql.Selector) string { 149 check := columnChecker(s.TableName()) 150 if err := check(field); err != nil { 151 s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) 152 return "" 153 } 154 return sql.Avg(s.C(field)) 155 } 156 } 157 158 // Min applies the "min" aggregation function on the given field of each group. 159 func Min(field string) AggregateFunc { 160 return func(s *sql.Selector) string { 161 check := columnChecker(s.TableName()) 162 if err := check(field); err != nil { 163 s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) 164 return "" 165 } 166 return sql.Min(s.C(field)) 167 } 168 } 169 170 // Sum applies the "sum" aggregation function on the given field of each group. 171 func Sum(field string) AggregateFunc { 172 return func(s *sql.Selector) string { 173 check := columnChecker(s.TableName()) 174 if err := check(field); err != nil { 175 s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) 176 return "" 177 } 178 return sql.Sum(s.C(field)) 179 } 180 } 181 182 // ValidationError returns when validating a field or edge fails. 183 type ValidationError struct { 184 Name string // Field or edge name. 185 err error 186 } 187 188 // Error implements the error interface. 189 func (e *ValidationError) Error() string { 190 return e.err.Error() 191 } 192 193 // Unwrap implements the errors.Wrapper interface. 194 func (e *ValidationError) Unwrap() error { 195 return e.err 196 } 197 198 // IsValidationError returns a boolean indicating whether the error is a validation error. 199 func IsValidationError(err error) bool { 200 if err == nil { 201 return false 202 } 203 var e *ValidationError 204 return errors.As(err, &e) 205 } 206 207 // NotFoundError returns when trying to fetch a specific entity and it was not found in the database. 208 type NotFoundError struct { 209 label string 210 } 211 212 // Error implements the error interface. 213 func (e *NotFoundError) Error() string { 214 return "ent: " + e.label + " not found" 215 } 216 217 // IsNotFound returns a boolean indicating whether the error is a not found error. 218 func IsNotFound(err error) bool { 219 if err == nil { 220 return false 221 } 222 var e *NotFoundError 223 return errors.As(err, &e) 224 } 225 226 // MaskNotFound masks not found error. 227 func MaskNotFound(err error) error { 228 if IsNotFound(err) { 229 return nil 230 } 231 return err 232 } 233 234 // NotSingularError returns when trying to fetch a singular entity and more then one was found in the database. 235 type NotSingularError struct { 236 label string 237 } 238 239 // Error implements the error interface. 240 func (e *NotSingularError) Error() string { 241 return "ent: " + e.label + " not singular" 242 } 243 244 // IsNotSingular returns a boolean indicating whether the error is a not singular error. 245 func IsNotSingular(err error) bool { 246 if err == nil { 247 return false 248 } 249 var e *NotSingularError 250 return errors.As(err, &e) 251 } 252 253 // NotLoadedError returns when trying to get a node that was not loaded by the query. 254 type NotLoadedError struct { 255 edge string 256 } 257 258 // Error implements the error interface. 259 func (e *NotLoadedError) Error() string { 260 return "ent: " + e.edge + " edge was not loaded" 261 } 262 263 // IsNotLoaded returns a boolean indicating whether the error is a not loaded error. 264 func IsNotLoaded(err error) bool { 265 if err == nil { 266 return false 267 } 268 var e *NotLoadedError 269 return errors.As(err, &e) 270 } 271 272 // ConstraintError returns when trying to create/update one or more entities and 273 // one or more of their constraints failed. For example, violation of edge or 274 // field uniqueness. 275 type ConstraintError struct { 276 msg string 277 wrap error 278 } 279 280 // Error implements the error interface. 281 func (e ConstraintError) Error() string { 282 return "ent: constraint failed: " + e.msg 283 } 284 285 // Unwrap implements the errors.Wrapper interface. 286 func (e *ConstraintError) Unwrap() error { 287 return e.wrap 288 } 289 290 // IsConstraintError returns a boolean indicating whether the error is a constraint failure. 291 func IsConstraintError(err error) bool { 292 if err == nil { 293 return false 294 } 295 var e *ConstraintError 296 return errors.As(err, &e) 297 } 298 299 // selector embedded by the different Select/GroupBy builders. 300 type selector struct { 301 label string 302 flds *[]string 303 scan func(context.Context, interface{}) error 304 } 305 306 // ScanX is like Scan, but panics if an error occurs. 307 func (s *selector) ScanX(ctx context.Context, v interface{}) { 308 if err := s.scan(ctx, v); err != nil { 309 panic(err) 310 } 311 } 312 313 // Strings returns list of strings from a selector. It is only allowed when selecting one field. 314 func (s *selector) Strings(ctx context.Context) ([]string, error) { 315 if len(*s.flds) > 1 { 316 return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field") 317 } 318 var v []string 319 if err := s.scan(ctx, &v); err != nil { 320 return nil, err 321 } 322 return v, nil 323 } 324 325 // StringsX is like Strings, but panics if an error occurs. 326 func (s *selector) StringsX(ctx context.Context) []string { 327 v, err := s.Strings(ctx) 328 if err != nil { 329 panic(err) 330 } 331 return v 332 } 333 334 // String returns a single string from a selector. It is only allowed when selecting one field. 335 func (s *selector) String(ctx context.Context) (_ string, err error) { 336 var v []string 337 if v, err = s.Strings(ctx); err != nil { 338 return 339 } 340 switch len(v) { 341 case 1: 342 return v[0], nil 343 case 0: 344 err = &NotFoundError{s.label} 345 default: 346 err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v)) 347 } 348 return 349 } 350 351 // StringX is like String, but panics if an error occurs. 352 func (s *selector) StringX(ctx context.Context) string { 353 v, err := s.String(ctx) 354 if err != nil { 355 panic(err) 356 } 357 return v 358 } 359 360 // Ints returns list of ints from a selector. It is only allowed when selecting one field. 361 func (s *selector) Ints(ctx context.Context) ([]int, error) { 362 if len(*s.flds) > 1 { 363 return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field") 364 } 365 var v []int 366 if err := s.scan(ctx, &v); err != nil { 367 return nil, err 368 } 369 return v, nil 370 } 371 372 // IntsX is like Ints, but panics if an error occurs. 373 func (s *selector) IntsX(ctx context.Context) []int { 374 v, err := s.Ints(ctx) 375 if err != nil { 376 panic(err) 377 } 378 return v 379 } 380 381 // Int returns a single int from a selector. It is only allowed when selecting one field. 382 func (s *selector) Int(ctx context.Context) (_ int, err error) { 383 var v []int 384 if v, err = s.Ints(ctx); err != nil { 385 return 386 } 387 switch len(v) { 388 case 1: 389 return v[0], nil 390 case 0: 391 err = &NotFoundError{s.label} 392 default: 393 err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v)) 394 } 395 return 396 } 397 398 // IntX is like Int, but panics if an error occurs. 399 func (s *selector) IntX(ctx context.Context) int { 400 v, err := s.Int(ctx) 401 if err != nil { 402 panic(err) 403 } 404 return v 405 } 406 407 // Float64s returns list of float64s from a selector. It is only allowed when selecting one field. 408 func (s *selector) Float64s(ctx context.Context) ([]float64, error) { 409 if len(*s.flds) > 1 { 410 return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field") 411 } 412 var v []float64 413 if err := s.scan(ctx, &v); err != nil { 414 return nil, err 415 } 416 return v, nil 417 } 418 419 // Float64sX is like Float64s, but panics if an error occurs. 420 func (s *selector) Float64sX(ctx context.Context) []float64 { 421 v, err := s.Float64s(ctx) 422 if err != nil { 423 panic(err) 424 } 425 return v 426 } 427 428 // Float64 returns a single float64 from a selector. It is only allowed when selecting one field. 429 func (s *selector) Float64(ctx context.Context) (_ float64, err error) { 430 var v []float64 431 if v, err = s.Float64s(ctx); err != nil { 432 return 433 } 434 switch len(v) { 435 case 1: 436 return v[0], nil 437 case 0: 438 err = &NotFoundError{s.label} 439 default: 440 err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v)) 441 } 442 return 443 } 444 445 // Float64X is like Float64, but panics if an error occurs. 446 func (s *selector) Float64X(ctx context.Context) float64 { 447 v, err := s.Float64(ctx) 448 if err != nil { 449 panic(err) 450 } 451 return v 452 } 453 454 // Bools returns list of bools from a selector. It is only allowed when selecting one field. 455 func (s *selector) Bools(ctx context.Context) ([]bool, error) { 456 if len(*s.flds) > 1 { 457 return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field") 458 } 459 var v []bool 460 if err := s.scan(ctx, &v); err != nil { 461 return nil, err 462 } 463 return v, nil 464 } 465 466 // BoolsX is like Bools, but panics if an error occurs. 467 func (s *selector) BoolsX(ctx context.Context) []bool { 468 v, err := s.Bools(ctx) 469 if err != nil { 470 panic(err) 471 } 472 return v 473 } 474 475 // Bool returns a single bool from a selector. It is only allowed when selecting one field. 476 func (s *selector) Bool(ctx context.Context) (_ bool, err error) { 477 var v []bool 478 if v, err = s.Bools(ctx); err != nil { 479 return 480 } 481 switch len(v) { 482 case 1: 483 return v[0], nil 484 case 0: 485 err = &NotFoundError{s.label} 486 default: 487 err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v)) 488 } 489 return 490 } 491 492 // BoolX is like Bool, but panics if an error occurs. 493 func (s *selector) BoolX(ctx context.Context) bool { 494 v, err := s.Bool(ctx) 495 if err != nil { 496 panic(err) 497 } 498 return v 499 } 500 501 // queryHook describes an internal hook for the different sqlAll methods. 502 type queryHook func(context.Context, *sqlgraph.QuerySpec)