-
Notifications
You must be signed in to change notification settings - Fork 14
DatabaseKeyMappingStrategy
Represents the mapping between your type's property names and their corresponding database column.
public enum DatabaseKeyMappingStrategy
For example, you might be using a PostgreSQL
database which has
a snake_case naming convention. Your users
table might have
fields id
, email
, first_name
, and last_name
.
Since Swift's naming convention is camelCase, your corresponding database model will probably look like this:
struct User: Model {
var id: Int?
let email: String
let firstName: String // doesn't match database field of `first_name`
let lastName: String // doesn't match database field of `last_name`
}
By overriding the keyMappingStrategy
on User
, you can
customize the mapping between the property names and
database columns. Note that in the example above you
won't need to override, since keyMappingStrategy is,
by default, convertToSnakeCase.
Use the literal name for all properties on an object as its corresponding database column.
case useDefaultKeys
Convert property names from camelCase to snake_case for the database columns.
case convertToSnakeCase
e.g. someGreatString
-> some_great_string
A custom mapping of property name to database column name.
case custom(: (String) -> String)
Given the strategy, map from an input string to an output string.
public func map(input: String) -> String
- input: The input string, representing the name of the swift type's property
The output string, representing the column of the database's table.
Generated at 2021-01-13T22:24:59-0800 using swift-doc 1.0.0-beta.5.
Alchemy
Types
- AlterTableBuilder
- BCryptDigest
- BasicAuthMiddleware
- BcryptError
- BelongsToRelationship
- CORSMiddleware
- CORSMiddleware.AllowOriginSetting
- CORSMiddleware.Configuration
- ColumnType
- CreateColumn
- CreateColumnBuilder
- CreateIndex
- CreateTableBuilder
- DatabaseConfig
- DatabaseError
- DatabaseField
- DatabaseKeyMappingStrategy
- DatabaseValue
- DayUnit
- Env
- FrequencyTyped
- Grammar
- HTTPAuth
- HTTPAuth.Basic
- HTTPAuth.Bearer
- HTTPBody
- HTTPError
- HasManyRelationship
- HasOneRelationship
- HasRelationship
- HourUnit
- JoinClause
- JoinType
- Launch
- Log
- MIMEType
- MinuteUnit
- ModelQuery
- MySQLDatabase
- Operator
- OrderClause
- OrderClause.Sort
- OrderedDictionary
- PapyrusClientError
- PathParameter
- PathParameter.DecodingError
- PostgresDatabase
- Query
- Request
- Response
- Router
- RuneError
- SQL
- SQLJSON
- Scheduler
- Schema
- SecondUnit
- Services
- Socket
- StaticFileMiddleware
- StringLength
- Thread
- TokenAuthMiddleware
- WeekUnit
- Weekday
- WhereBoolean
- WhereColumn
- WhereIn
- WhereIn.InType
- WhereNested
- WhereRaw
- WhereValue