This part of the spec describes directives that are used to control details like names and concrete types in the underlying database. See the issue #3408 to learn about the other parts of the spec.
db directiveExamples
A type omitting the directive and therefore using the defaults.
type Blog {
id: ID! @id
name: String!
}
A type changing the name of the underlying database table or collection.
type Blog @db(name: "blog") {
id: ID! @id
name: String!
}
String maps to text in PostgresExamples
A field omitting the directive and therefore using the defaults.
type Blog {
id: ID! @id
name: String!
}
A field using the directive to change the name of the underlying database field or column.
type Blog {
id: ID! @id
name: String! @db(name: "title_column")
}
A field using the directive to change the type of the underlying column in the database to use varchar(20) instead of the default text for the String type. (This example assumes Postgres)
type Blog {
id: ID! @id
name: String! @db(type: "varchar(20)")
}
I would really like two options to set a default naming strategy for columns and table names. For example:
namingStrategy: "default"|"snake_case"
tableNamingStrategy: "singular"|"plural"
type Blog { => Maps to "blogs" with tableNamingStrategy "plural"
id: ID! @id
publishedAt: DateTime! => Maps to "published_at" using namingStrategy "snake_case"
}
In a model I use camelCase properties, but in the database (postgres) I always use snakeCase columns and plural table names.
Allow per field naming using the annotations.
Most helpful comment
I would really like two options to set a default naming strategy for columns and table names. For example:
In a model I use
camelCaseproperties, but in the database (postgres) I always usesnakeCasecolumns and plural table names.Allow per field naming using the annotations.