github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/databases/orm/hints/hints.go (about) 1 // The original package is migrated from beego and modified, you can find orignal from following link: 2 // "github.com/beego/beego/" 3 // 4 // Copyright 2023 IAC. All Rights Reserved. 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // 10 // http://www.apache.org/licenses/LICENSE-2.0 11 // 12 // Unless required by applicable law or agreed to in writing, software 13 // distributed under the License is distributed on an "AS IS" BASIS, 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 18 package hints 19 20 import ( 21 "github.com/mdaxf/iac/framework/utils" 22 ) 23 24 const ( 25 // query level 26 KeyForceIndex = iota 27 KeyUseIndex 28 KeyIgnoreIndex 29 KeyForUpdate 30 KeyLimit 31 KeyOffset 32 KeyOrderBy 33 KeyRelDepth 34 ) 35 36 type Hint struct { 37 key interface{} 38 value interface{} 39 } 40 41 var _ utils.KV = new(Hint) 42 43 // GetKey return key 44 func (s *Hint) GetKey() interface{} { 45 return s.key 46 } 47 48 // GetValue return value 49 func (s *Hint) GetValue() interface{} { 50 return s.value 51 } 52 53 var _ utils.KV = new(Hint) 54 55 // ForceIndex return a hint about ForceIndex 56 func ForceIndex(indexes ...string) *Hint { 57 return NewHint(KeyForceIndex, indexes) 58 } 59 60 // UseIndex return a hint about UseIndex 61 func UseIndex(indexes ...string) *Hint { 62 return NewHint(KeyUseIndex, indexes) 63 } 64 65 // IgnoreIndex return a hint about IgnoreIndex 66 func IgnoreIndex(indexes ...string) *Hint { 67 return NewHint(KeyIgnoreIndex, indexes) 68 } 69 70 // ForUpdate return a hint about ForUpdate 71 func ForUpdate() *Hint { 72 return NewHint(KeyForUpdate, true) 73 } 74 75 // DefaultRelDepth return a hint about DefaultRelDepth 76 func DefaultRelDepth() *Hint { 77 return NewHint(KeyRelDepth, true) 78 } 79 80 // RelDepth return a hint about RelDepth 81 func RelDepth(d int) *Hint { 82 return NewHint(KeyRelDepth, d) 83 } 84 85 // Limit return a hint about Limit 86 func Limit(d int64) *Hint { 87 return NewHint(KeyLimit, d) 88 } 89 90 // Offset return a hint about Offset 91 func Offset(d int64) *Hint { 92 return NewHint(KeyOffset, d) 93 } 94 95 // OrderBy return a hint about OrderBy 96 func OrderBy(s string) *Hint { 97 return NewHint(KeyOrderBy, s) 98 } 99 100 // NewHint return a hint 101 func NewHint(key interface{}, value interface{}) *Hint { 102 return &Hint{ 103 key: key, 104 value: value, 105 } 106 }