@@ -2,19 +2,69 @@ package main
22
33import (
44 "database/sql"
5+ "fmt"
56 "github.com/folospace/go-mysql-orm/orm"
67 _ "github.com/go-sql-driver/mysql"
78 "testing"
9+ "time"
810)
911
1012var tdb , _ = sql .Open ("mysql" , "rfamro@tcp(mysql-rfam-public.ebi.ac.uk:4497)/Rfam?parseTime=true&charset=utf8mb4&loc=Asia%2FShanghai" )
1113
14+ var FamilyTable2 = orm .NewQuery (Family2 {}, tdb )
15+
16+ type Family2 struct {
17+ RfamAcc string `json:"rfam_acc" orm:"rfam_acc,varchar(7),primary,unique"`
18+ RfamId string `json:"rfam_id" orm:"rfam_id,varchar(40),index"`
19+ AutoWiki uint `json:"auto_wiki" orm:"auto_wiki,int(10) unsigned,index"`
20+ Description * string `json:"description" orm:"description,varchar(75),null" default:"NULL"`
21+ Author * string `json:"author" orm:"author,tinytext,null"`
22+ SeedSource * string `json:"seed_source" orm:"seed_source,tinytext,null"`
23+ GatheringCutoff * float64 `json:"gathering_cutoff" orm:"gathering_cutoff,double(5,2),null" default:"NULL"`
24+ TrustedCutoff * float64 `json:"trusted_cutoff" orm:"trusted_cutoff,double(5,2),null" default:"NULL"`
25+ NoiseCutoff * float64 `json:"noise_cutoff" orm:"noise_cutoff,double(5,2),null" default:"NULL"`
26+ Comment * string `json:"comment" orm:"comment,longtext,null"`
27+ PreviousId * string `json:"previous_id" orm:"previous_id,tinytext,null"`
28+ Cmbuild * string `json:"cmbuild" orm:"cmbuild,tinytext,null"`
29+ Cmcalibrate * string `json:"cmcalibrate" orm:"cmcalibrate,tinytext,null"`
30+ Cmsearch * string `json:"cmsearch" orm:"cmsearch,tinytext,null"`
31+ NumSeed * int64 `json:"num_seed" orm:"num_seed,bigint(20),null" default:"NULL"`
32+ NumFull * int64 `json:"num_full" orm:"num_full,bigint(20),null" default:"NULL"`
33+ NumGenomeSeq * int64 `json:"num_genome_seq" orm:"num_genome_seq,bigint(20),null" default:"NULL"`
34+ NumRefseq * int64 `json:"num_refseq" orm:"num_refseq,bigint(20),null" default:"NULL"`
35+ Type * string `json:"type" orm:"type,varchar(50),null" default:"NULL"`
36+ StructureSource * string `json:"structure_source" orm:"structure_source,tinytext,null"`
37+ NumberOfSpecies * int64 `json:"number_of_species" orm:"number_of_species,bigint(20),null" default:"NULL"`
38+ Number3dStructures * int `json:"number_3d_structures" orm:"number_3d_structures,int(11),null" default:"NULL"`
39+ NumPseudonokts * int `json:"num_pseudonokts" orm:"num_pseudonokts,int(11),null" default:"NULL"`
40+ TaxSeed * string `json:"tax_seed" orm:"tax_seed,mediumtext,null"`
41+ EcmliLambda * float64 `json:"ecmli_lambda" orm:"ecmli_lambda,double(10,5),null" default:"NULL"`
42+ EcmliMu * float64 `json:"ecmli_mu" orm:"ecmli_mu,double(10,5),null" default:"NULL"`
43+ EcmliCalDb * int `json:"ecmli_cal_db" orm:"ecmli_cal_db,mediumint(9),null" default:"0"`
44+ EcmliCalHits * int `json:"ecmli_cal_hits" orm:"ecmli_cal_hits,mediumint(9),null" default:"0"`
45+ Maxl * int `json:"maxl" orm:"maxl,mediumint(9),null" default:"0"`
46+ Clen * int `json:"clen" orm:"clen,mediumint(9),null" default:"0"`
47+ MatchPairNode * int8 `json:"match_pair_node" orm:"match_pair_node,tinyint(1),null" default:"0"`
48+ HmmTau * float64 `json:"hmm_tau" orm:"hmm_tau,double(10,5),null" default:"NULL"`
49+ HmmLambda * float64 `json:"hmm_lambda" orm:"hmm_lambda,double(10,5),null" default:"NULL"`
50+ Created time.Time `json:"created" orm:"created,datetime"`
51+ Updated time.Time `json:"updated" orm:"updated,timestamp" default:"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"`
52+ }
53+
54+ func (Family2 ) TableName () string {
55+ return "family"
56+ }
57+
58+ func (Family2 ) DatabaseName () string {
59+ return "Rfam"
60+ }
61+
1262func TestSelect (t * testing.T ) {
1363 t .Run ("query_raw" , func (t * testing.T ) {
1464
15- var data map [string ][]string
16- query := orm . NewQueryRaw ( "family" , tdb ). Select ("type" , "author" ).Limit (5 ).GetTo (& data )
17- t .Log (data )
65+ var data map [string ][]Family
66+ query := FamilyTable2 . Select ("type" , FamilyTable2 . AllCols () ).Limit (5 ).GetTo (& data )
67+ t .Log (fmt . Sprintf ( "%+v" , data ) )
1868 t .Log (query .Sql ())
1969 t .Log (query .Error ())
2070 })
0 commit comments