jmoiron / modl

golang database modelling library
MIT License
480 stars 48 forks source link

create Postgres columns of type 'text' #21

Closed medovina closed 10 years ago

medovina commented 10 years ago

Currently if a Go field has type 'string', modl gives the corresponding column the type 'varchar' with a fixed character limit that comes from the column's MaxSize, or 255 if MaxSize is unspecified.

Postgres has a type 'text' which stores strings of any length. In the interest of avoiding arbitrary limits, I think 'text' should be the default column type for a Go string field.

jmoiron commented 10 years ago

I'd like there to be a much more generic and powerful approach towards the creation of a column, beyond just allowing for a type to be set; perhaps the ability to set some arbitrary SQL.

jmoiron commented 10 years ago

You can override just the type like this:

table := dbm.TableFor(myobj)
column := table.ColMap("column_name")
column.SetSqlType("text")

You can now also do, eg:

column.SetSqlCreate("foo text NOT NULL DEFAULT md5sum(some_other_column)")
ferhatelmas commented 9 years ago

Please correct me if I'm wrong. We can only specify column name as a field tag and it's not possible to specify sql as a field tag. In addition to current way, having it might be more convenient. If you think so, I'm eager to help you.

Btw, thank you for the library.