apikey.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. // Code generated by ent, DO NOT EDIT.
  2. package apikey
  3. import (
  4. "time"
  5. "entgo.io/ent"
  6. "entgo.io/ent/dialect/sql"
  7. "entgo.io/ent/dialect/sql/sqlgraph"
  8. )
  9. const (
  10. // Label holds the string label denoting the apikey type in the database.
  11. Label = "api_key"
  12. // FieldID holds the string denoting the id field in the database.
  13. FieldID = "id"
  14. // FieldCreatedAt holds the string denoting the created_at field in the database.
  15. FieldCreatedAt = "created_at"
  16. // FieldUpdatedAt holds the string denoting the updated_at field in the database.
  17. FieldUpdatedAt = "updated_at"
  18. // FieldDeletedAt holds the string denoting the deleted_at field in the database.
  19. FieldDeletedAt = "deleted_at"
  20. // FieldUserID holds the string denoting the user_id field in the database.
  21. FieldUserID = "user_id"
  22. // FieldKey holds the string denoting the key field in the database.
  23. FieldKey = "key"
  24. // FieldKeyHash holds the string denoting the key_hash field in the database.
  25. FieldKeyHash = "key_hash"
  26. // FieldKeyPrefix holds the string denoting the key_prefix field in the database.
  27. FieldKeyPrefix = "key_prefix"
  28. // FieldName holds the string denoting the name field in the database.
  29. FieldName = "name"
  30. // FieldGroupID holds the string denoting the group_id field in the database.
  31. FieldGroupID = "group_id"
  32. // FieldStatus holds the string denoting the status field in the database.
  33. FieldStatus = "status"
  34. // FieldLastUsedAt holds the string denoting the last_used_at field in the database.
  35. FieldLastUsedAt = "last_used_at"
  36. // FieldIPWhitelist holds the string denoting the ip_whitelist field in the database.
  37. FieldIPWhitelist = "ip_whitelist"
  38. // FieldIPBlacklist holds the string denoting the ip_blacklist field in the database.
  39. FieldIPBlacklist = "ip_blacklist"
  40. // FieldQuota holds the string denoting the quota field in the database.
  41. FieldQuota = "quota"
  42. // FieldQuotaUsed holds the string denoting the quota_used field in the database.
  43. FieldQuotaUsed = "quota_used"
  44. // FieldExpiresAt holds the string denoting the expires_at field in the database.
  45. FieldExpiresAt = "expires_at"
  46. // FieldRateLimit5h holds the string denoting the rate_limit_5h field in the database.
  47. FieldRateLimit5h = "rate_limit_5h"
  48. // FieldRateLimit1d holds the string denoting the rate_limit_1d field in the database.
  49. FieldRateLimit1d = "rate_limit_1d"
  50. // FieldRateLimit7d holds the string denoting the rate_limit_7d field in the database.
  51. FieldRateLimit7d = "rate_limit_7d"
  52. // FieldUsage5h holds the string denoting the usage_5h field in the database.
  53. FieldUsage5h = "usage_5h"
  54. // FieldUsage1d holds the string denoting the usage_1d field in the database.
  55. FieldUsage1d = "usage_1d"
  56. // FieldUsage7d holds the string denoting the usage_7d field in the database.
  57. FieldUsage7d = "usage_7d"
  58. // FieldWindow5hStart holds the string denoting the window_5h_start field in the database.
  59. FieldWindow5hStart = "window_5h_start"
  60. // FieldWindow1dStart holds the string denoting the window_1d_start field in the database.
  61. FieldWindow1dStart = "window_1d_start"
  62. // FieldWindow7dStart holds the string denoting the window_7d_start field in the database.
  63. FieldWindow7dStart = "window_7d_start"
  64. // EdgeUser holds the string denoting the user edge name in mutations.
  65. EdgeUser = "user"
  66. // EdgeGroup holds the string denoting the group edge name in mutations.
  67. EdgeGroup = "group"
  68. // EdgeUsageLogs holds the string denoting the usage_logs edge name in mutations.
  69. EdgeUsageLogs = "usage_logs"
  70. // Table holds the table name of the apikey in the database.
  71. Table = "api_keys"
  72. // UserTable is the table that holds the user relation/edge.
  73. UserTable = "api_keys"
  74. // UserInverseTable is the table name for the User entity.
  75. // It exists in this package in order to avoid circular dependency with the "user" package.
  76. UserInverseTable = "users"
  77. // UserColumn is the table column denoting the user relation/edge.
  78. UserColumn = "user_id"
  79. // GroupTable is the table that holds the group relation/edge.
  80. GroupTable = "api_keys"
  81. // GroupInverseTable is the table name for the Group entity.
  82. // It exists in this package in order to avoid circular dependency with the "group" package.
  83. GroupInverseTable = "groups"
  84. // GroupColumn is the table column denoting the group relation/edge.
  85. GroupColumn = "group_id"
  86. // UsageLogsTable is the table that holds the usage_logs relation/edge.
  87. UsageLogsTable = "usage_logs"
  88. // UsageLogsInverseTable is the table name for the UsageLog entity.
  89. // It exists in this package in order to avoid circular dependency with the "usagelog" package.
  90. UsageLogsInverseTable = "usage_logs"
  91. // UsageLogsColumn is the table column denoting the usage_logs relation/edge.
  92. UsageLogsColumn = "api_key_id"
  93. )
  94. // Columns holds all SQL columns for apikey fields.
  95. var Columns = []string{
  96. FieldID,
  97. FieldCreatedAt,
  98. FieldUpdatedAt,
  99. FieldDeletedAt,
  100. FieldUserID,
  101. FieldKey,
  102. FieldKeyHash,
  103. FieldKeyPrefix,
  104. FieldName,
  105. FieldGroupID,
  106. FieldStatus,
  107. FieldLastUsedAt,
  108. FieldIPWhitelist,
  109. FieldIPBlacklist,
  110. FieldQuota,
  111. FieldQuotaUsed,
  112. FieldExpiresAt,
  113. FieldRateLimit5h,
  114. FieldRateLimit1d,
  115. FieldRateLimit7d,
  116. FieldUsage5h,
  117. FieldUsage1d,
  118. FieldUsage7d,
  119. FieldWindow5hStart,
  120. FieldWindow1dStart,
  121. FieldWindow7dStart,
  122. }
  123. // ValidColumn reports if the column name is valid (part of the table columns).
  124. func ValidColumn(column string) bool {
  125. for i := range Columns {
  126. if column == Columns[i] {
  127. return true
  128. }
  129. }
  130. return false
  131. }
  132. // Note that the variables below are initialized by the runtime
  133. // package on the initialization of the application. Therefore,
  134. // it should be imported in the main as follows:
  135. //
  136. // import _ "github.com/Wei-Shaw/sub2api/ent/runtime"
  137. var (
  138. Hooks [1]ent.Hook
  139. Interceptors [1]ent.Interceptor
  140. // DefaultCreatedAt holds the default value on creation for the "created_at" field.
  141. DefaultCreatedAt func() time.Time
  142. // DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
  143. DefaultUpdatedAt func() time.Time
  144. // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
  145. UpdateDefaultUpdatedAt func() time.Time
  146. // KeyValidator is a validator for the "key" field. It is called by the builders before save.
  147. KeyValidator func(string) error
  148. // KeyHashValidator is a validator for the "key_hash" field. It is called by the builders before save.
  149. KeyHashValidator func(string) error
  150. // KeyPrefixValidator is a validator for the "key_prefix" field. It is called by the builders before save.
  151. KeyPrefixValidator func(string) error
  152. // NameValidator is a validator for the "name" field. It is called by the builders before save.
  153. NameValidator func(string) error
  154. // DefaultStatus holds the default value on creation for the "status" field.
  155. DefaultStatus string
  156. // StatusValidator is a validator for the "status" field. It is called by the builders before save.
  157. StatusValidator func(string) error
  158. // DefaultQuota holds the default value on creation for the "quota" field.
  159. DefaultQuota float64
  160. // DefaultQuotaUsed holds the default value on creation for the "quota_used" field.
  161. DefaultQuotaUsed float64
  162. // DefaultRateLimit5h holds the default value on creation for the "rate_limit_5h" field.
  163. DefaultRateLimit5h float64
  164. // DefaultRateLimit1d holds the default value on creation for the "rate_limit_1d" field.
  165. DefaultRateLimit1d float64
  166. // DefaultRateLimit7d holds the default value on creation for the "rate_limit_7d" field.
  167. DefaultRateLimit7d float64
  168. // DefaultUsage5h holds the default value on creation for the "usage_5h" field.
  169. DefaultUsage5h float64
  170. // DefaultUsage1d holds the default value on creation for the "usage_1d" field.
  171. DefaultUsage1d float64
  172. // DefaultUsage7d holds the default value on creation for the "usage_7d" field.
  173. DefaultUsage7d float64
  174. )
  175. // OrderOption defines the ordering options for the APIKey queries.
  176. type OrderOption func(*sql.Selector)
  177. // ByID orders the results by the id field.
  178. func ByID(opts ...sql.OrderTermOption) OrderOption {
  179. return sql.OrderByField(FieldID, opts...).ToFunc()
  180. }
  181. // ByCreatedAt orders the results by the created_at field.
  182. func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
  183. return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
  184. }
  185. // ByUpdatedAt orders the results by the updated_at field.
  186. func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
  187. return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
  188. }
  189. // ByDeletedAt orders the results by the deleted_at field.
  190. func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
  191. return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
  192. }
  193. // ByUserID orders the results by the user_id field.
  194. func ByUserID(opts ...sql.OrderTermOption) OrderOption {
  195. return sql.OrderByField(FieldUserID, opts...).ToFunc()
  196. }
  197. // ByKey orders the results by the key field.
  198. func ByKey(opts ...sql.OrderTermOption) OrderOption {
  199. return sql.OrderByField(FieldKey, opts...).ToFunc()
  200. }
  201. // ByKeyHash orders the results by the key_hash field.
  202. func ByKeyHash(opts ...sql.OrderTermOption) OrderOption {
  203. return sql.OrderByField(FieldKeyHash, opts...).ToFunc()
  204. }
  205. // ByKeyPrefix orders the results by the key_prefix field.
  206. func ByKeyPrefix(opts ...sql.OrderTermOption) OrderOption {
  207. return sql.OrderByField(FieldKeyPrefix, opts...).ToFunc()
  208. }
  209. // ByName orders the results by the name field.
  210. func ByName(opts ...sql.OrderTermOption) OrderOption {
  211. return sql.OrderByField(FieldName, opts...).ToFunc()
  212. }
  213. // ByGroupID orders the results by the group_id field.
  214. func ByGroupID(opts ...sql.OrderTermOption) OrderOption {
  215. return sql.OrderByField(FieldGroupID, opts...).ToFunc()
  216. }
  217. // ByStatus orders the results by the status field.
  218. func ByStatus(opts ...sql.OrderTermOption) OrderOption {
  219. return sql.OrderByField(FieldStatus, opts...).ToFunc()
  220. }
  221. // ByLastUsedAt orders the results by the last_used_at field.
  222. func ByLastUsedAt(opts ...sql.OrderTermOption) OrderOption {
  223. return sql.OrderByField(FieldLastUsedAt, opts...).ToFunc()
  224. }
  225. // ByQuota orders the results by the quota field.
  226. func ByQuota(opts ...sql.OrderTermOption) OrderOption {
  227. return sql.OrderByField(FieldQuota, opts...).ToFunc()
  228. }
  229. // ByQuotaUsed orders the results by the quota_used field.
  230. func ByQuotaUsed(opts ...sql.OrderTermOption) OrderOption {
  231. return sql.OrderByField(FieldQuotaUsed, opts...).ToFunc()
  232. }
  233. // ByExpiresAt orders the results by the expires_at field.
  234. func ByExpiresAt(opts ...sql.OrderTermOption) OrderOption {
  235. return sql.OrderByField(FieldExpiresAt, opts...).ToFunc()
  236. }
  237. // ByRateLimit5h orders the results by the rate_limit_5h field.
  238. func ByRateLimit5h(opts ...sql.OrderTermOption) OrderOption {
  239. return sql.OrderByField(FieldRateLimit5h, opts...).ToFunc()
  240. }
  241. // ByRateLimit1d orders the results by the rate_limit_1d field.
  242. func ByRateLimit1d(opts ...sql.OrderTermOption) OrderOption {
  243. return sql.OrderByField(FieldRateLimit1d, opts...).ToFunc()
  244. }
  245. // ByRateLimit7d orders the results by the rate_limit_7d field.
  246. func ByRateLimit7d(opts ...sql.OrderTermOption) OrderOption {
  247. return sql.OrderByField(FieldRateLimit7d, opts...).ToFunc()
  248. }
  249. // ByUsage5h orders the results by the usage_5h field.
  250. func ByUsage5h(opts ...sql.OrderTermOption) OrderOption {
  251. return sql.OrderByField(FieldUsage5h, opts...).ToFunc()
  252. }
  253. // ByUsage1d orders the results by the usage_1d field.
  254. func ByUsage1d(opts ...sql.OrderTermOption) OrderOption {
  255. return sql.OrderByField(FieldUsage1d, opts...).ToFunc()
  256. }
  257. // ByUsage7d orders the results by the usage_7d field.
  258. func ByUsage7d(opts ...sql.OrderTermOption) OrderOption {
  259. return sql.OrderByField(FieldUsage7d, opts...).ToFunc()
  260. }
  261. // ByWindow5hStart orders the results by the window_5h_start field.
  262. func ByWindow5hStart(opts ...sql.OrderTermOption) OrderOption {
  263. return sql.OrderByField(FieldWindow5hStart, opts...).ToFunc()
  264. }
  265. // ByWindow1dStart orders the results by the window_1d_start field.
  266. func ByWindow1dStart(opts ...sql.OrderTermOption) OrderOption {
  267. return sql.OrderByField(FieldWindow1dStart, opts...).ToFunc()
  268. }
  269. // ByWindow7dStart orders the results by the window_7d_start field.
  270. func ByWindow7dStart(opts ...sql.OrderTermOption) OrderOption {
  271. return sql.OrderByField(FieldWindow7dStart, opts...).ToFunc()
  272. }
  273. // ByUserField orders the results by user field.
  274. func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
  275. return func(s *sql.Selector) {
  276. sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
  277. }
  278. }
  279. // ByGroupField orders the results by group field.
  280. func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption {
  281. return func(s *sql.Selector) {
  282. sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...))
  283. }
  284. }
  285. // ByUsageLogsCount orders the results by usage_logs count.
  286. func ByUsageLogsCount(opts ...sql.OrderTermOption) OrderOption {
  287. return func(s *sql.Selector) {
  288. sqlgraph.OrderByNeighborsCount(s, newUsageLogsStep(), opts...)
  289. }
  290. }
  291. // ByUsageLogs orders the results by usage_logs terms.
  292. func ByUsageLogs(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
  293. return func(s *sql.Selector) {
  294. sqlgraph.OrderByNeighborTerms(s, newUsageLogsStep(), append([]sql.OrderTerm{term}, terms...)...)
  295. }
  296. }
  297. func newUserStep() *sqlgraph.Step {
  298. return sqlgraph.NewStep(
  299. sqlgraph.From(Table, FieldID),
  300. sqlgraph.To(UserInverseTable, FieldID),
  301. sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
  302. )
  303. }
  304. func newGroupStep() *sqlgraph.Step {
  305. return sqlgraph.NewStep(
  306. sqlgraph.From(Table, FieldID),
  307. sqlgraph.To(GroupInverseTable, FieldID),
  308. sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn),
  309. )
  310. }
  311. func newUsageLogsStep() *sqlgraph.Step {
  312. return sqlgraph.NewStep(
  313. sqlgraph.From(Table, FieldID),
  314. sqlgraph.To(UsageLogsInverseTable, FieldID),
  315. sqlgraph.Edge(sqlgraph.O2M, false, UsageLogsTable, UsageLogsColumn),
  316. )
  317. }