github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/databases/orm/invocation.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 orm 19 20 import ( 21 "context" 22 "time" 23 ) 24 25 // Invocation represents an "Orm" invocation 26 type Invocation struct { 27 Method string 28 // Md may be nil in some cases. It depends on method 29 Md interface{} 30 // the args are all arguments except context.Context 31 Args []interface{} 32 33 mi *modelInfo 34 // f is the Orm operation 35 f func(ctx context.Context) []interface{} 36 37 // insideTx indicates whether this is inside a transaction 38 InsideTx bool 39 TxStartTime time.Time 40 TxName string 41 } 42 43 func (inv *Invocation) GetTableName() string { 44 if inv.mi != nil { 45 return inv.mi.table 46 } 47 return "" 48 } 49 50 func (inv *Invocation) execute(ctx context.Context) []interface{} { 51 return inv.f(ctx) 52 } 53 54 // GetPkFieldName return the primary key of this table 55 // if not found, "" is returned 56 func (inv *Invocation) GetPkFieldName() string { 57 if inv.mi.fields.pk != nil { 58 return inv.mi.fields.pk.name 59 } 60 return "" 61 }