Importing data, realized need to handle NULLs.

This commit is contained in:
Matthew Dillon 2014-10-30 16:24:15 -08:00
parent df95dfc930
commit 58344b82a5
4 changed files with 33 additions and 25 deletions

View file

@ -3,9 +3,9 @@
CREATE TABLE strains ( CREATE TABLE strains (
id BIGSERIAL NOT NULL, id BIGSERIAL NOT NULL,
species_id BIGINT, species_id BIGINT NOT NULL,
strain_name CHARACTER VARYING(100), strain_name CHARACTER VARYING(100) NOT NULL,
strain_type CHARACTER VARYING(100), strain_type CHARACTER VARYING(100) NOT NULL,
etymology CHARACTER VARYING(500), etymology CHARACTER VARYING(500),
accession_banks CHARACTER VARYING(100), accession_banks CHARACTER VARYING(100),
genbank_embl_ddb CHARACTER VARYING(100), genbank_embl_ddb CHARACTER VARYING(100),

View file

@ -6,16 +6,17 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/lib/pq"
"github.com/thermokarst/bactdb/router" "github.com/thermokarst/bactdb/router"
) )
// A Genus is a high-level classifier in bactdb. // A Genus is a high-level classifier in bactdb.
type Genus struct { type Genus struct {
Id int64 `json:"id,omitempty"` Id int64 `json:"id,omitempty"`
GenusName string `db:"genus_name" json:"genus_name"` GenusName string `db:"genus_name" json:"genus_name"`
CreatedAt time.Time `db:"created_at" json:"created_at"` CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
DeletedAt time.Time `db:"deleted_at" json:"deleted_at"` DeletedAt pq.NullTime `db:"deleted_at" json:"deleted_at"`
} }
func NewGenus() *Genus { func NewGenus() *Genus {

View file

@ -6,17 +6,18 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/lib/pq"
"github.com/thermokarst/bactdb/router" "github.com/thermokarst/bactdb/router"
) )
// A Species is a high-level classifier in bactdb. // A Species is a high-level classifier in bactdb.
type Species struct { type Species struct {
Id int64 `json:"id,omitempty"` Id int64 `json:"id,omitempty"`
GenusId int64 `db:"genus_id" json:"genus_id"` GenusId int64 `db:"genus_id" json:"genus_id"`
SpeciesName string `db:"species_name" json:"species_name"` SpeciesName string `db:"species_name" json:"species_name"`
CreatedAt time.Time `db:"created_at" json:"created_at"` CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
DeletedAt time.Time `db:"deleted_at" json:"deleted_at"` DeletedAt pq.NullTime `db:"deleted_at" json:"deleted_at"`
} }
func NewSpecies() *Species { func NewSpecies() *Species {

View file

@ -6,25 +6,31 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/lib/pq"
"github.com/thermokarst/bactdb/router" "github.com/thermokarst/bactdb/router"
) )
// A Strain is a subclass of species // A Strain is a subclass of species
type Strain struct { type Strain struct {
Id int64 `json:"id,omitempty"` Id int64 `json:"id,omitempty"`
SpeciesId int64 `db:"species_id" json:"species_id"` SpeciesId int64 `db:"species_id" json:"species_id"`
StrainName string `db:"strain_name" json:"strain_name"` StrainName string `db:"strain_name" json:"strain_name"`
StrainType string `db:"strain_type" json:"strain_type"` StrainType string `db:"strain_type" json:"strain_type"`
Etymology string `db:"etymology" json:"etymology"` Etymology string `db:"etymology" json:"etymology"`
AccessionBanks string `db:"accession_banks" json:"accession_banks"` AccessionBanks string `db:"accession_banks" json:"accession_banks"`
GenbankEmblDdb string `db:"genbank_embl_ddb" json:"genbank_embl_ddb"` GenbankEmblDdb string `db:"genbank_embl_ddb" json:"genbank_embl_ddb"`
CreatedAt time.Time `db:"created_at" json:"created_at"` CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
DeletedAt time.Time `db:"deleted_at" json:"deleted_at"` DeletedAt pq.NullTime `db:"deleted_at" json:"deleted_at"`
} }
func NewStrain() *Strain { func NewStrain() *Strain {
return &Strain{StrainName: "Test Strain", StrainType: "Test Type", Etymology: "Test Etymology", AccessionBanks: "Test Accession", GenbankEmblDdb: "Test Genbank"} return &Strain{
StrainName: "Test Strain",
StrainType: "Test Type",
Etymology: "Test Etymology",
AccessionBanks: "Test Accession",
GenbankEmblDdb: "Test Genbank"}
} }
// StrainService interacts with the strain-related endpoints in bactdb's API // StrainService interacts with the strain-related endpoints in bactdb's API