Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
658a671b
authored
2013-10-09 11:37:16 +0800
by
slene
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
all panic use Error
1 parent
aaf1490f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
38 additions
and
37 deletions
orm/db.go
orm/db_tables.go
orm/models_boot.go
orm/orm.go
orm/orm_conds.go
orm/orm_object.go
orm/orm_queryset.go
orm/orm_raw.go
orm/db.go
View file @
658a671
...
...
@@ -58,7 +58,7 @@ func (d *dbBase) collectValues(mi *modelInfo, ind reflect.Value, cols []string,
if
fi
,
_
=
mi
.
fields
.
GetByAny
(
column
);
fi
!=
nil
{
column
=
fi
.
column
}
else
{
panic
(
fmt
.
Sprint
f
(
"wrong db field/column name `%s` for model `%s`"
,
column
,
mi
.
fullName
))
panic
(
fmt
.
Error
f
(
"wrong db field/column name `%s` for model `%s`"
,
column
,
mi
.
fullName
))
}
if
fi
.
dbcol
==
false
||
fi
.
auto
&&
skipAuto
{
continue
...
...
@@ -360,7 +360,7 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
values
:=
make
([]
interface
{},
0
,
len
(
params
))
for
col
,
val
:=
range
params
{
if
fi
,
ok
:=
mi
.
fields
.
GetByAny
(
col
);
ok
==
false
||
fi
.
dbcol
==
false
{
panic
(
fmt
.
Sprint
f
(
"wrong field/column name `%s`"
,
col
))
panic
(
fmt
.
Error
f
(
"wrong field/column name `%s`"
,
col
))
}
else
{
columns
=
append
(
columns
,
fi
.
column
)
values
=
append
(
values
,
val
)
...
...
@@ -368,7 +368,7 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
}
if
len
(
columns
)
==
0
{
panic
(
"update params cannot empty"
)
panic
(
fmt
.
Errorf
(
"update params cannot empty"
)
)
}
tables
:=
newDbTables
(
mi
,
d
.
ins
)
...
...
@@ -438,7 +438,7 @@ func (d *dbBase) DeleteBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
}
if
cond
==
nil
||
cond
.
IsEmpty
()
{
panic
(
"delete operation cannot execute without condition"
)
panic
(
fmt
.
Errorf
(
"delete operation cannot execute without condition"
)
)
}
Q
:=
d
.
ins
.
TableQuote
()
...
...
@@ -533,9 +533,9 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
if
errTyp
{
if
one
{
panic
(
fmt
.
Sprint
f
(
"wrong object type `%s` for rows scan, need *%s"
,
val
.
Type
(),
mi
.
fullName
))
panic
(
fmt
.
Error
f
(
"wrong object type `%s` for rows scan, need *%s"
,
val
.
Type
(),
mi
.
fullName
))
}
else
{
panic
(
fmt
.
Sprint
f
(
"wrong object type `%s` for rows scan, need *[]*%s or *[]%s"
,
val
.
Type
(),
mi
.
fullName
,
mi
.
fullName
))
panic
(
fmt
.
Error
f
(
"wrong object type `%s` for rows scan, need *[]*%s or *[]%s"
,
val
.
Type
(),
mi
.
fullName
,
mi
.
fullName
))
}
}
...
...
@@ -559,7 +559,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
maps
[
fi
.
column
]
=
true
}
}
else
{
panic
(
fmt
.
Sprint
f
(
"wrong field/column name `%s`"
,
col
))
panic
(
fmt
.
Error
f
(
"wrong field/column name `%s`"
,
col
))
}
}
if
hasRel
{
...
...
@@ -717,7 +717,7 @@ func (d *dbBase) GenerateOperatorSql(mi *modelInfo, fi *fieldInfo, operator stri
params
:=
getFlatParams
(
fi
,
args
,
tz
)
if
len
(
params
)
==
0
{
panic
(
fmt
.
Sprint
f
(
"operator `%s` need at least one args"
,
operator
))
panic
(
fmt
.
Error
f
(
"operator `%s` need at least one args"
,
operator
))
}
arg
:=
params
[
0
]
...
...
@@ -729,7 +729,7 @@ func (d *dbBase) GenerateOperatorSql(mi *modelInfo, fi *fieldInfo, operator stri
sql
=
fmt
.
Sprintf
(
"IN (%s)"
,
strings
.
Join
(
marks
,
", "
))
}
else
{
if
len
(
params
)
>
1
{
panic
(
fmt
.
Sprint
f
(
"operator `%s` need 1 args not %d"
,
operator
,
len
(
params
)))
panic
(
fmt
.
Error
f
(
"operator `%s` need 1 args not %d"
,
operator
,
len
(
params
)))
}
sql
=
d
.
ins
.
OperatorSql
(
operator
)
switch
operator
{
...
...
@@ -758,7 +758,7 @@ func (d *dbBase) GenerateOperatorSql(mi *modelInfo, fi *fieldInfo, operator stri
}
params
=
nil
}
else
{
panic
(
fmt
.
Sprint
f
(
"operator `%s` need a bool value not `%T`"
,
operator
,
arg
))
panic
(
fmt
.
Error
f
(
"operator `%s` need a bool value not `%T`"
,
operator
,
arg
))
}
}
}
...
...
@@ -779,13 +779,13 @@ func (d *dbBase) setColsValues(mi *modelInfo, ind *reflect.Value, cols []string,
value
,
err
:=
d
.
convertValueFromDB
(
fi
,
val
,
tz
)
if
err
!=
nil
{
panic
(
fmt
.
Sprint
f
(
"Raw value: `%v` %s"
,
val
,
err
.
Error
()))
panic
(
fmt
.
Error
f
(
"Raw value: `%v` %s"
,
val
,
err
.
Error
()))
}
_
,
err
=
d
.
setFieldValue
(
fi
,
value
,
field
)
if
err
!=
nil
{
panic
(
fmt
.
Sprint
f
(
"Raw value: `%v` %s"
,
val
,
err
.
Error
()))
panic
(
fmt
.
Error
f
(
"Raw value: `%v` %s"
,
val
,
err
.
Error
()))
}
}
}
...
...
@@ -1034,7 +1034,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
case
*
ParamsList
:
typ
=
3
default
:
panic
(
fmt
.
Sprint
f
(
"unsupport read values type `%T`"
,
container
))
panic
(
fmt
.
Error
f
(
"unsupport read values type `%T`"
,
container
))
}
tables
:=
newDbTables
(
mi
,
d
.
ins
)
...
...
@@ -1117,7 +1117,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
value
,
err
:=
d
.
convertValueFromDB
(
fi
,
val
,
tz
)
if
err
!=
nil
{
panic
(
fmt
.
Sprint
f
(
"db value convert failed `%v` %s"
,
val
,
err
.
Error
()))
panic
(
fmt
.
Error
f
(
"db value convert failed `%v` %s"
,
val
,
err
.
Error
()))
}
params
[
columns
[
i
]]
=
value
...
...
@@ -1132,7 +1132,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
value
,
err
:=
d
.
convertValueFromDB
(
fi
,
val
,
tz
)
if
err
!=
nil
{
panic
(
fmt
.
Sprint
f
(
"db value convert failed `%v` %s"
,
val
,
err
.
Error
()))
panic
(
fmt
.
Error
f
(
"db value convert failed `%v` %s"
,
val
,
err
.
Error
()))
}
params
=
append
(
params
,
value
)
...
...
@@ -1146,7 +1146,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
value
,
err
:=
d
.
convertValueFromDB
(
fi
,
val
,
tz
)
if
err
!=
nil
{
panic
(
fmt
.
Sprint
f
(
"db value convert failed `%v` %s"
,
val
,
err
.
Error
()))
panic
(
fmt
.
Error
f
(
"db value convert failed `%v` %s"
,
val
,
err
.
Error
()))
}
list
=
append
(
list
,
value
)
...
...
orm/db_tables.go
View file @
658a671
...
...
@@ -126,7 +126,7 @@ func (t *dbTables) parseRelated(rels []string, depth int) {
jtl
=
jt
}
else
{
panic
(
fmt
.
Sprint
f
(
"unknown model/table name `%s`"
,
ex
))
panic
(
fmt
.
Error
f
(
"unknown model/table name `%s`"
,
ex
))
}
}
}
...
...
orm/models_boot.go
View file @
658a671
...
...
@@ -14,7 +14,7 @@ func registerModel(model interface{}, prefix string) {
typ
:=
ind
.
Type
()
if
val
.
Kind
()
!=
reflect
.
Ptr
{
panic
(
fmt
.
Sprint
f
(
"<orm.RegisterModel> cannot use non-ptr model struct `%s`"
,
getFullName
(
typ
)))
panic
(
fmt
.
Error
f
(
"<orm.RegisterModel> cannot use non-ptr model struct `%s`"
,
getFullName
(
typ
)))
}
table
:=
getTableName
(
val
)
...
...
@@ -177,7 +177,7 @@ func bootStrap() {
}
}
if
added
==
false
{
panic
(
fmt
.
Sprint
f
(
"cannot generate auto reverse field info `%s` to `%s`"
,
fi
.
fullName
,
ffi
.
fullName
))
panic
(
fmt
.
Error
f
(
"cannot generate auto reverse field info `%s` to `%s`"
,
fi
.
fullName
,
ffi
.
fullName
))
}
}
}
...
...
orm/orm.go
View file @
658a671
...
...
@@ -44,13 +44,13 @@ func (o *orm) getMiInd(md interface{}) (mi *modelInfo, ind reflect.Value) {
ind
=
reflect
.
Indirect
(
val
)
typ
:=
ind
.
Type
()
if
val
.
Kind
()
!=
reflect
.
Ptr
{
panic
(
fmt
.
Sprint
f
(
"<Ormer> cannot use non-ptr model struct `%s`"
,
getFullName
(
typ
)))
panic
(
fmt
.
Error
f
(
"<Ormer> cannot use non-ptr model struct `%s`"
,
getFullName
(
typ
)))
}
name
:=
getFullName
(
typ
)
if
mi
,
ok
:=
modelCache
.
getByFN
(
name
);
ok
{
return
mi
,
ind
}
panic
(
fmt
.
Sprint
f
(
"<Ormer> table: `%s` not found, maybe not RegisterModel"
,
name
))
panic
(
fmt
.
Error
f
(
"<Ormer> table: `%s` not found, maybe not RegisterModel"
,
name
))
}
func
(
o
*
orm
)
Read
(
md
interface
{},
cols
...
string
)
error
{
...
...
@@ -141,14 +141,14 @@ func (o *orm) QueryTable(ptrStructOrTableName interface{}) (qs QuerySeter) {
}
}
if
qs
==
nil
{
panic
(
fmt
.
Sprint
f
(
"<Ormer.QueryTable> table name: `%s` not exists"
,
name
))
panic
(
fmt
.
Error
f
(
"<Ormer.QueryTable> table name: `%s` not exists"
,
name
))
}
return
}
func
(
o
*
orm
)
Using
(
name
string
)
error
{
if
o
.
isTx
{
panic
(
"<Ormer.Using> transaction has been start, cannot change db"
)
panic
(
fmt
.
Errorf
(
"<Ormer.Using> transaction has been start, cannot change db"
)
)
}
if
al
,
ok
:=
dataBaseCache
.
get
(
name
);
ok
{
o
.
alias
=
al
...
...
@@ -158,7 +158,7 @@ func (o *orm) Using(name string) error {
o
.
db
=
al
.
DB
}
}
else
{
return
errors
.
New
(
fmt
.
Sprintf
(
"<Ormer.Using> unknown db alias name `%s`"
,
name
)
)
return
fmt
.
Errorf
(
"<Ormer.Using> unknown db alias name `%s`"
,
name
)
}
return
nil
}
...
...
orm/orm_conds.go
View file @
658a671
package
orm
import
(
"fmt"
"strings"
)
...
...
@@ -28,7 +29,7 @@ func NewCondition() *Condition {
func
(
c
Condition
)
And
(
expr
string
,
args
...
interface
{})
*
Condition
{
if
expr
==
""
||
len
(
args
)
==
0
{
panic
(
"<Condition.And> args cannot empty"
)
panic
(
fmt
.
Errorf
(
"<Condition.And> args cannot empty"
)
)
}
c
.
params
=
append
(
c
.
params
,
condValue
{
exprs
:
strings
.
Split
(
expr
,
ExprSep
),
args
:
args
})
return
&
c
...
...
@@ -36,7 +37,7 @@ func (c Condition) And(expr string, args ...interface{}) *Condition {
func
(
c
Condition
)
AndNot
(
expr
string
,
args
...
interface
{})
*
Condition
{
if
expr
==
""
||
len
(
args
)
==
0
{
panic
(
"<Condition.AndNot> args cannot empty"
)
panic
(
fmt
.
Errorf
(
"<Condition.AndNot> args cannot empty"
)
)
}
c
.
params
=
append
(
c
.
params
,
condValue
{
exprs
:
strings
.
Split
(
expr
,
ExprSep
),
args
:
args
,
isNot
:
true
})
return
&
c
...
...
@@ -45,7 +46,7 @@ func (c Condition) AndNot(expr string, args ...interface{}) *Condition {
func
(
c
*
Condition
)
AndCond
(
cond
*
Condition
)
*
Condition
{
c
=
c
.
clone
()
if
c
==
cond
{
panic
(
"cannot use self as sub cond"
)
panic
(
fmt
.
Errorf
(
"<Condition.AndCond> cannot use self as sub cond"
)
)
}
if
cond
!=
nil
{
c
.
params
=
append
(
c
.
params
,
condValue
{
cond
:
cond
,
isCond
:
true
})
...
...
@@ -55,7 +56,7 @@ func (c *Condition) AndCond(cond *Condition) *Condition {
func
(
c
Condition
)
Or
(
expr
string
,
args
...
interface
{})
*
Condition
{
if
expr
==
""
||
len
(
args
)
==
0
{
panic
(
"<Condition.Or> args cannot empty"
)
panic
(
fmt
.
Errorf
(
"<Condition.Or> args cannot empty"
)
)
}
c
.
params
=
append
(
c
.
params
,
condValue
{
exprs
:
strings
.
Split
(
expr
,
ExprSep
),
args
:
args
,
isOr
:
true
})
return
&
c
...
...
@@ -63,7 +64,7 @@ func (c Condition) Or(expr string, args ...interface{}) *Condition {
func
(
c
Condition
)
OrNot
(
expr
string
,
args
...
interface
{})
*
Condition
{
if
expr
==
""
||
len
(
args
)
==
0
{
panic
(
"<Condition.OrNot> args cannot empty"
)
panic
(
fmt
.
Errorf
(
"<Condition.OrNot> args cannot empty"
)
)
}
c
.
params
=
append
(
c
.
params
,
condValue
{
exprs
:
strings
.
Split
(
expr
,
ExprSep
),
args
:
args
,
isNot
:
true
,
isOr
:
true
})
return
&
c
...
...
@@ -72,7 +73,7 @@ func (c Condition) OrNot(expr string, args ...interface{}) *Condition {
func
(
c
*
Condition
)
OrCond
(
cond
*
Condition
)
*
Condition
{
c
=
c
.
clone
()
if
c
==
cond
{
panic
(
"cannot use self as sub cond"
)
panic
(
fmt
.
Errorf
(
"<Condition.OrCond> cannot use self as sub cond"
)
)
}
if
cond
!=
nil
{
c
.
params
=
append
(
c
.
params
,
condValue
{
cond
:
cond
,
isCond
:
true
,
isOr
:
true
})
...
...
orm/orm_object.go
View file @
658a671
...
...
@@ -23,10 +23,10 @@ func (o *insertSet) Insert(md interface{}) (int64, error) {
typ
:=
ind
.
Type
()
name
:=
getFullName
(
typ
)
if
val
.
Kind
()
!=
reflect
.
Ptr
{
panic
(
fmt
.
Sprint
f
(
"<Inserter.Insert> cannot use non-ptr model struct `%s`"
,
name
))
panic
(
fmt
.
Error
f
(
"<Inserter.Insert> cannot use non-ptr model struct `%s`"
,
name
))
}
if
name
!=
o
.
mi
.
fullName
{
panic
(
fmt
.
Sprint
f
(
"<Inserter.Insert> need model `%s` but found `%s`"
,
o
.
mi
.
fullName
,
name
))
panic
(
fmt
.
Error
f
(
"<Inserter.Insert> need model `%s` but found `%s`"
,
o
.
mi
.
fullName
,
name
))
}
id
,
err
:=
o
.
orm
.
alias
.
DbBaser
.
InsertStmt
(
o
.
stmt
,
o
.
mi
,
ind
,
o
.
orm
.
alias
.
TZ
)
if
err
!=
nil
{
...
...
orm/orm_queryset.go
View file @
658a671
...
...
@@ -67,7 +67,7 @@ func (o querySet) RelatedSel(params ...interface{}) QuerySeter {
case
int
:
o
.
relDepth
=
val
default
:
panic
(
fmt
.
Sprint
f
(
"<QuerySeter.RelatedSel> wrong param kind: %v"
,
val
))
panic
(
fmt
.
Error
f
(
"<QuerySeter.RelatedSel> wrong param kind: %v"
,
val
))
}
}
}
...
...
orm/orm_raw.go
View file @
658a671
...
...
@@ -314,7 +314,7 @@ func (o *rawSet) loopSetRefs(refs []interface{}, sIdxes [][]int, sInds []reflect
func
(
o
*
rawSet
)
QueryRow
(
containers
...
interface
{})
error
{
if
len
(
containers
)
==
0
{
panic
(
"<RawSeter.QueryRow> need at least one arg"
)
panic
(
fmt
.
Errorf
(
"<RawSeter.QueryRow> need at least one arg"
)
)
}
refs
:=
make
([]
interface
{},
0
,
len
(
containers
))
...
...
@@ -327,7 +327,7 @@ func (o *rawSet) QueryRow(containers ...interface{}) error {
ind
:=
reflect
.
Indirect
(
val
)
if
val
.
Kind
()
!=
reflect
.
Ptr
{
panic
(
"<RawSeter.QueryRow> all args must be use ptr"
)
panic
(
fmt
.
Errorf
(
"<RawSeter.QueryRow> all args must be use ptr"
)
)
}
etyp
:=
ind
.
Type
()
...
...
@@ -377,7 +377,7 @@ func (o *rawSet) QueryRows(containers ...interface{}) (int64, error) {
val
:=
reflect
.
ValueOf
(
container
)
sInd
:=
reflect
.
Indirect
(
val
)
if
val
.
Kind
()
!=
reflect
.
Ptr
||
sInd
.
Kind
()
!=
reflect
.
Slice
{
panic
(
"<RawSeter.QueryRows> all args must be use ptr slice"
)
panic
(
fmt
.
Errorf
(
"<RawSeter.QueryRows> all args must be use ptr slice"
)
)
}
etyp
:=
sInd
.
Type
()
.
Elem
()
...
...
@@ -440,7 +440,7 @@ func (o *rawSet) readValues(container interface{}) (int64, error) {
case
*
ParamsList
:
typ
=
3
default
:
panic
(
fmt
.
Sprint
f
(
"<RawSeter> unsupport read values type `%T`"
,
container
))
panic
(
fmt
.
Error
f
(
"<RawSeter> unsupport read values type `%T`"
,
container
))
}
query
:=
o
.
query
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment