Skip to content

Commit 68adfa8

Browse files
committed
add test
1 parent 93b45e0 commit 68adfa8

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.idea/
22
.DS_Store
33
vendor/
4-
*test.go
4+
test.go

orm/create_struct_from_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func getTableDbColumns[T Table](query Query[T]) ([]dBColumn, error) {
212212
ret[existColumn[colName]].Indexs = append(ret[existColumn[colName]].Indexs, keyName)
213213
}
214214
}
215-
} else {
215+
} else if strings.HasPrefix(v, "`") {
216216
var col dBColumn
217217
col.Null = true
218218
temp := findCommentRegex.FindStringSubmatch(v)

orm_migrate_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package main
2+
3+
import (
4+
"github.com/folospace/go-mysql-orm/orm"
5+
"testing"
6+
"time"
7+
)
8+
9+
type Family struct {
10+
RfamAcc string `json:"rfam_acc" orm:"rfam_acc,varchar(7),primary,unique"`
11+
RfamId string `json:"rfam_id" orm:"rfam_id,varchar(40),index"`
12+
AutoWiki uint `json:"auto_wiki" orm:"auto_wiki,int(10) unsigned,index"`
13+
Description *string `json:"description" orm:"description,varchar(75),null" default:"NULL"`
14+
Author *string `json:"author" orm:"author,tinytext,null"`
15+
SeedSource *string `json:"seed_source" orm:"seed_source,tinytext,null"`
16+
GatheringCutoff *float64 `json:"gathering_cutoff" orm:"gathering_cutoff,double(5,2),null" default:"NULL"`
17+
TrustedCutoff *float64 `json:"trusted_cutoff" orm:"trusted_cutoff,double(5,2),null" default:"NULL"`
18+
NoiseCutoff *float64 `json:"noise_cutoff" orm:"noise_cutoff,double(5,2),null" default:"NULL"`
19+
Comment *string `json:"comment" orm:"comment,longtext,null"`
20+
PreviousId *string `json:"previous_id" orm:"previous_id,tinytext,null"`
21+
Cmbuild *string `json:"cmbuild" orm:"cmbuild,tinytext,null"`
22+
Cmcalibrate *string `json:"cmcalibrate" orm:"cmcalibrate,tinytext,null"`
23+
Cmsearch *string `json:"cmsearch" orm:"cmsearch,tinytext,null"`
24+
NumSeed *int64 `json:"num_seed" orm:"num_seed,bigint(20),null" default:"NULL"`
25+
NumFull *int64 `json:"num_full" orm:"num_full,bigint(20),null" default:"NULL"`
26+
NumGenomeSeq *int64 `json:"num_genome_seq" orm:"num_genome_seq,bigint(20),null" default:"NULL"`
27+
NumRefseq *int64 `json:"num_refseq" orm:"num_refseq,bigint(20),null" default:"NULL"`
28+
Type *string `json:"type" orm:"type,varchar(50),null" default:"NULL"`
29+
StructureSource *string `json:"structure_source" orm:"structure_source,tinytext,null"`
30+
NumberOfSpecies *int64 `json:"number_of_species" orm:"number_of_species,bigint(20),null" default:"NULL"`
31+
Number3dStructures *int `json:"number_3d_structures" orm:"number_3d_structures,int(11),null" default:"NULL"`
32+
NumPseudonokts *int `json:"num_pseudonokts" orm:"num_pseudonokts,int(11),null" default:"NULL"`
33+
TaxSeed *string `json:"tax_seed" orm:"tax_seed,mediumtext,null"`
34+
EcmliLambda *float64 `json:"ecmli_lambda" orm:"ecmli_lambda,double(10,5),null" default:"NULL"`
35+
EcmliMu *float64 `json:"ecmli_mu" orm:"ecmli_mu,double(10,5),null" default:"NULL"`
36+
EcmliCalDb *int `json:"ecmli_cal_db" orm:"ecmli_cal_db,mediumint(9),null" default:"0"`
37+
EcmliCalHits *int `json:"ecmli_cal_hits" orm:"ecmli_cal_hits,mediumint(9),null" default:"0"`
38+
Maxl *int `json:"maxl" orm:"maxl,mediumint(9),null" default:"0"`
39+
Clen *int `json:"clen" orm:"clen,mediumint(9),null" default:"0"`
40+
MatchPairNode *int8 `json:"match_pair_node" orm:"match_pair_node,tinyint(1),null" default:"0"`
41+
HmmTau *float64 `json:"hmm_tau" orm:"hmm_tau,double(10,5),null" default:"NULL"`
42+
HmmLambda *float64 `json:"hmm_lambda" orm:"hmm_lambda,double(10,5),null" default:"NULL"`
43+
Created time.Time `json:"created" orm:"created,datetime"`
44+
Updated time.Time `json:"updated" orm:"updated,timestamp" default:"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"`
45+
}
46+
type Family_2022_06_13_11_38_30 struct {
47+
}
48+
49+
func (Family) TableName() string {
50+
return "family"
51+
}
52+
53+
func (Family) DatabaseName() string {
54+
return "Rfam"
55+
}
56+
57+
func TestMigrate(t *testing.T) {
58+
t.Run("create_struct", func(t *testing.T) {
59+
FamilyTable := orm.NewQuery(Family{}, tdb)
60+
61+
err := orm.CreateStructFromTable(FamilyTable)
62+
63+
t.Log(err)
64+
})
65+
}

orm_select_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"database/sql"
5+
"github.com/folospace/go-mysql-orm/orm"
6+
"testing"
7+
)
8+
9+
var tdb, _ = sql.Open("mysql", "rfamro@tcp(mysql-rfam-public.ebi.ac.uk:4497)/Rfam?parseTime=true&charset=utf8mb4&loc=Asia%2FShanghai")
10+
11+
func TestSelect(t *testing.T) {
12+
t.Run("query_raw", func(t *testing.T) {
13+
data, query := orm.NewQueryRaw(tdb, "family").Limit(5).GetRows()
14+
t.Log(data)
15+
t.Log(query.Sql())
16+
t.Log(query.Error())
17+
})
18+
}

0 commit comments

Comments
 (0)