volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Please add custom tag (specially hash) #485

Closed ernestdolog closed 5 years ago

ernestdolog commented 5 years ago

If you're having a generation problem please answer these questions before submitting your issue. Thanks!

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v3.2.0

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

CREATE TABLE if not exists test_regis_schema.company_value
(
        regis_id                        varchar(255)    not null,
        type                            varchar(255)    default NULL :: character varying,
        value                       varchar(255)    default NULL :: character varying,

        hash_value                              varchar(255)    not null,
        time_stamp                              timestamp       default '1970-01-01 12:00:00' :: timestamp without time zone,
        version_id                              varchar(255)    not null,

    CONSTRAINT regis_id PRIMARY KEY (regis_id)
        INCLUDE(regis_id),
    CONSTRAINT company_value_regis_id_fkey FOREIGN KEY (regis_id)
        REFERENCES test_regis_schema.company (regis_id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE test_regis_schema.company_value
    OWNER to postgres;

Further information. What did you do, what did you expect?

Hi,

As it's not a rare thing to create a hash from a go struct, and most of go hashing libraries provide functionality for excluding a field with giving it a hash:"-" or hash:exclude tag it would be nice to have a configuration to set several columns of several fields with this tag. It would be the best if i could configure it at the .toml config file on the root.

from this:

type CompanyValue struct {
    RegisID   string      `boil:"regis_id" json:"regis_id" toml:"regis_id" yaml:"regis_id"`
    Type      null.String `boil:"type" json:"type,omitempty" toml:"type" yaml:"type,omitempty"`
    Value     null.String `boil:"value" json:"value,omitempty" toml:"value" yaml:"value,omitempty"`
    HashValue string      `boil:"hash_value" json:"hash_value" toml:"hash_value" yaml:"hash_value"`
    TimeStamp null.Time   `boil:"time_stamp" json:"time_stamp,omitempty" toml:"time_stamp" yaml:"time_stamp,omitempty"`
    VersionID string      `boil:"version_id" json:"version_id" toml:"version_id" yaml:"version_id"`

    R *companyValueR `boil:"-" json:"-" toml:"-" yaml:"-"`
    L companyValueL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

I would like to magic this:

type CompanyValue struct {
    RegisID   string      `boil:"regis_id" json:"regis_id" toml:"regis_id" yaml:"regis_id"`
    Type      null.String `boil:"type" json:"type,omitempty" toml:"type" yaml:"type,omitempty"`
    Value     null.String `boil:"value" json:"value,omitempty" toml:"value" yaml:"value,omitempty"`
    HashValue string      `hash:"-" boil:"hash_value" json:"hash_value" toml:"hash_value" yaml:"hash_value"`
    TimeStamp null.Time   `hash:"-" boil:"time_stamp" json:"time_stamp,omitempty" toml:"time_stamp" yaml:"time_stamp,omitempty"`
    VersionID string      `hash:"-" boil:"version_id" json:"version_id" toml:"version_id" yaml:"version_id"`

    R *companyValueR `boil:"-" json:"-" toml:"-" yaml:"-"`
    L companyValueL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
aarondl commented 5 years ago

I don't disagree, but it becomes hard because the values can be so varied for each field that we'd have to make a templating language inside the toml file which is just gross. The fear of that complexity has left us with the current solution: You can override the templates for this functionality if you need it badly enough.