gorm和xorm tag对比

Field Tag

gorm xorm gorm说明 xorm说明
column name or 'name' column db name Column Name, optional
type support over 30 kinds of column types, details in Column Types column data type, prefer to use compatible general type, e.g: bool, int, uint, float, string, time, bytes, which works for all databases, and can be used with other tags together, like not null, size, autoIncrement… specified database data type like varbinary(8) also supported, when using specified database data type, it needs to be a full database data type, for example: MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT column type
serializer specifies serializer for how to serialize and deserialize data into db, e.g: serializer:json/gob/unixtime
size specifies column data size/length, e.g: size:256
primaryKey specifies column as primary key
unique specifies column as unique
default default 0 | default 'name' specifies column default value column default value
precision specifies column precision
scale specifies column scale
not null [not ]null | notnull specifies column as NOT NULL if column could be blank
autoIncrement autoincr specifies column auto incrementable If autoincrement column
autoIncrementIncrement auto increment step, controls the interval between successive column values
embedded extends embed the field use for anonymous field, map the struct in anonymous field to database
embeddedPrefix column name prefix for embedded fields
autoCreateTime created track current time when creating, for int fields, it will track unix seconds, use value nano/milli to track unix nano/milli seconds, e.g: autoCreateTime:nano This field will be filled in current time on insert
autoUpdateTime updated track current time when creating/updating, for int fields, it will track unix seconds, use value nano/milli to track unix nano/milli seconds, e.g: autoUpdateTime:milli This field will be filled in current time on insert or update
index index/index(indexname) create index with options, use same name for multiple fields creates composite indexes, refer Indexes for details column is index. if add (indexname), the column is used for combined index with the field that defining same indexname
uniqueIndex unique/unique(uniquename) same as index, but create uniqued index column is Unique index; if add (uniquename), the column is used for combined unique index with the field that defining same uniquename.
check creates check constraint, eg: check:age > 13, refer Constraints
<- -> set field’s write permission, <-:create create-only field, <-:update update-only field, <-:false no write permission, <- create and update permission only write into database
-> <- set field’s read permission, ->:false no read permission only read from database
- - ignore this field, - no read/write permission, -:migration no migrate permission, -:all no read/write/migrate permission This field will not be mapping
comment comment add comment for field when migration set field comment (currently only supports mysql)
version This field will be filled 1 on insert and autoincrement on update

你可能感兴趣的:(gorm和xorm tag对比)