securitypolicykeyword.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "entgo.io/ent"
  8. "entgo.io/ent/dialect/sql"
  9. "github.com/Wei-Shaw/sub2api/ent/group"
  10. "github.com/Wei-Shaw/sub2api/ent/securitypolicykeyword"
  11. )
  12. // SecurityPolicyKeyword is the model entity for the SecurityPolicyKeyword schema.
  13. type SecurityPolicyKeyword struct {
  14. config `json:"-"`
  15. // ID of the ent.
  16. ID int64 `json:"id,omitempty"`
  17. // CreatedAt holds the value of the "created_at" field.
  18. CreatedAt time.Time `json:"created_at,omitempty"`
  19. // UpdatedAt holds the value of the "updated_at" field.
  20. UpdatedAt time.Time `json:"updated_at,omitempty"`
  21. // DeletedAt holds the value of the "deleted_at" field.
  22. DeletedAt *time.Time `json:"deleted_at,omitempty"`
  23. // GroupID holds the value of the "group_id" field.
  24. GroupID *int64 `json:"group_id,omitempty"`
  25. // 关键词原文,匹配时大小写不敏感
  26. Keyword string `json:"keyword,omitempty"`
  27. // 分类:crack/reverse/pentest/privesc/evasion/custom
  28. Category string `json:"category,omitempty"`
  29. // 是否参与匹配
  30. Enabled bool `json:"enabled,omitempty"`
  31. // Edges holds the relations/edges for other nodes in the graph.
  32. // The values are being populated by the SecurityPolicyKeywordQuery when eager-loading is set.
  33. Edges SecurityPolicyKeywordEdges `json:"edges"`
  34. selectValues sql.SelectValues
  35. }
  36. // SecurityPolicyKeywordEdges holds the relations/edges for other nodes in the graph.
  37. type SecurityPolicyKeywordEdges struct {
  38. // Group holds the value of the group edge.
  39. Group *Group `json:"group,omitempty"`
  40. // loadedTypes holds the information for reporting if a
  41. // type was loaded (or requested) in eager-loading or not.
  42. loadedTypes [1]bool
  43. }
  44. // GroupOrErr returns the Group value or an error if the edge
  45. // was not loaded in eager-loading, or loaded but was not found.
  46. func (e SecurityPolicyKeywordEdges) GroupOrErr() (*Group, error) {
  47. if e.Group != nil {
  48. return e.Group, nil
  49. } else if e.loadedTypes[0] {
  50. return nil, &NotFoundError{label: group.Label}
  51. }
  52. return nil, &NotLoadedError{edge: "group"}
  53. }
  54. // scanValues returns the types for scanning values from sql.Rows.
  55. func (*SecurityPolicyKeyword) scanValues(columns []string) ([]any, error) {
  56. values := make([]any, len(columns))
  57. for i := range columns {
  58. switch columns[i] {
  59. case securitypolicykeyword.FieldEnabled:
  60. values[i] = new(sql.NullBool)
  61. case securitypolicykeyword.FieldID, securitypolicykeyword.FieldGroupID:
  62. values[i] = new(sql.NullInt64)
  63. case securitypolicykeyword.FieldKeyword, securitypolicykeyword.FieldCategory:
  64. values[i] = new(sql.NullString)
  65. case securitypolicykeyword.FieldCreatedAt, securitypolicykeyword.FieldUpdatedAt, securitypolicykeyword.FieldDeletedAt:
  66. values[i] = new(sql.NullTime)
  67. default:
  68. values[i] = new(sql.UnknownType)
  69. }
  70. }
  71. return values, nil
  72. }
  73. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  74. // to the SecurityPolicyKeyword fields.
  75. func (_m *SecurityPolicyKeyword) assignValues(columns []string, values []any) error {
  76. if m, n := len(values), len(columns); m < n {
  77. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  78. }
  79. for i := range columns {
  80. switch columns[i] {
  81. case securitypolicykeyword.FieldID:
  82. value, ok := values[i].(*sql.NullInt64)
  83. if !ok {
  84. return fmt.Errorf("unexpected type %T for field id", value)
  85. }
  86. _m.ID = int64(value.Int64)
  87. case securitypolicykeyword.FieldCreatedAt:
  88. if value, ok := values[i].(*sql.NullTime); !ok {
  89. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  90. } else if value.Valid {
  91. _m.CreatedAt = value.Time
  92. }
  93. case securitypolicykeyword.FieldUpdatedAt:
  94. if value, ok := values[i].(*sql.NullTime); !ok {
  95. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  96. } else if value.Valid {
  97. _m.UpdatedAt = value.Time
  98. }
  99. case securitypolicykeyword.FieldDeletedAt:
  100. if value, ok := values[i].(*sql.NullTime); !ok {
  101. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  102. } else if value.Valid {
  103. _m.DeletedAt = new(time.Time)
  104. *_m.DeletedAt = value.Time
  105. }
  106. case securitypolicykeyword.FieldGroupID:
  107. if value, ok := values[i].(*sql.NullInt64); !ok {
  108. return fmt.Errorf("unexpected type %T for field group_id", values[i])
  109. } else if value.Valid {
  110. _m.GroupID = new(int64)
  111. *_m.GroupID = value.Int64
  112. }
  113. case securitypolicykeyword.FieldKeyword:
  114. if value, ok := values[i].(*sql.NullString); !ok {
  115. return fmt.Errorf("unexpected type %T for field keyword", values[i])
  116. } else if value.Valid {
  117. _m.Keyword = value.String
  118. }
  119. case securitypolicykeyword.FieldCategory:
  120. if value, ok := values[i].(*sql.NullString); !ok {
  121. return fmt.Errorf("unexpected type %T for field category", values[i])
  122. } else if value.Valid {
  123. _m.Category = value.String
  124. }
  125. case securitypolicykeyword.FieldEnabled:
  126. if value, ok := values[i].(*sql.NullBool); !ok {
  127. return fmt.Errorf("unexpected type %T for field enabled", values[i])
  128. } else if value.Valid {
  129. _m.Enabled = value.Bool
  130. }
  131. default:
  132. _m.selectValues.Set(columns[i], values[i])
  133. }
  134. }
  135. return nil
  136. }
  137. // Value returns the ent.Value that was dynamically selected and assigned to the SecurityPolicyKeyword.
  138. // This includes values selected through modifiers, order, etc.
  139. func (_m *SecurityPolicyKeyword) Value(name string) (ent.Value, error) {
  140. return _m.selectValues.Get(name)
  141. }
  142. // QueryGroup queries the "group" edge of the SecurityPolicyKeyword entity.
  143. func (_m *SecurityPolicyKeyword) QueryGroup() *GroupQuery {
  144. return NewSecurityPolicyKeywordClient(_m.config).QueryGroup(_m)
  145. }
  146. // Update returns a builder for updating this SecurityPolicyKeyword.
  147. // Note that you need to call SecurityPolicyKeyword.Unwrap() before calling this method if this SecurityPolicyKeyword
  148. // was returned from a transaction, and the transaction was committed or rolled back.
  149. func (_m *SecurityPolicyKeyword) Update() *SecurityPolicyKeywordUpdateOne {
  150. return NewSecurityPolicyKeywordClient(_m.config).UpdateOne(_m)
  151. }
  152. // Unwrap unwraps the SecurityPolicyKeyword entity that was returned from a transaction after it was closed,
  153. // so that all future queries will be executed through the driver which created the transaction.
  154. func (_m *SecurityPolicyKeyword) Unwrap() *SecurityPolicyKeyword {
  155. _tx, ok := _m.config.driver.(*txDriver)
  156. if !ok {
  157. panic("ent: SecurityPolicyKeyword is not a transactional entity")
  158. }
  159. _m.config.driver = _tx.drv
  160. return _m
  161. }
  162. // String implements the fmt.Stringer.
  163. func (_m *SecurityPolicyKeyword) String() string {
  164. var builder strings.Builder
  165. builder.WriteString("SecurityPolicyKeyword(")
  166. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  167. builder.WriteString("created_at=")
  168. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  169. builder.WriteString(", ")
  170. builder.WriteString("updated_at=")
  171. builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
  172. builder.WriteString(", ")
  173. if v := _m.DeletedAt; v != nil {
  174. builder.WriteString("deleted_at=")
  175. builder.WriteString(v.Format(time.ANSIC))
  176. }
  177. builder.WriteString(", ")
  178. if v := _m.GroupID; v != nil {
  179. builder.WriteString("group_id=")
  180. builder.WriteString(fmt.Sprintf("%v", *v))
  181. }
  182. builder.WriteString(", ")
  183. builder.WriteString("keyword=")
  184. builder.WriteString(_m.Keyword)
  185. builder.WriteString(", ")
  186. builder.WriteString("category=")
  187. builder.WriteString(_m.Category)
  188. builder.WriteString(", ")
  189. builder.WriteString("enabled=")
  190. builder.WriteString(fmt.Sprintf("%v", _m.Enabled))
  191. builder.WriteByte(')')
  192. return builder.String()
  193. }
  194. // SecurityPolicyKeywords is a parsable slice of SecurityPolicyKeyword.
  195. type SecurityPolicyKeywords []*SecurityPolicyKeyword