-
Notifications
You must be signed in to change notification settings - Fork 14
Model
An ActiveRecord-esque type used for modeling a table in a relational database. Contains many extensions for making database queries, supporting relationships & much more.
public protocol Model: Identifiable, ModelMaybeOptional
Identifiable
, ModelMaybeOptional
The identifier / primary key of this type.
var id: Self.Identifier?
The table with which this object is associated. Defaults to
String(describing: Self.self)
aka the name of the type. Can
be overridden for custom table names.
var tableName: String
struct User: Model {
static var tableName: String = "my_user_table"
var id: Int?
let name: String
let email: String
}
How should the Swift CodingKey
s be mapped to database
columns? Defaults to .convertToSnakeCase
. Can be
overridden on a per-type basis.
var keyMappingStrategy: DatabaseKeyMappingStrategy
When mapping a Model
to an SQL table, @BelongsTo
properties will have their property names suffixed by this
String
. Defaults to Id
. This value is affected by
keyMappingStrategy
, so if the keyMappingStrategy
of the
database is .convertToSnakeCase
, the default suffix will
effectively be _id
.
var belongsToColumnSuffix: String
Usage:
struct User: Model {
...
@BelongsTo
var parent: User // will map to column `parentId` of type
// `User.ID`.
}
The JSONDecoder
to use when decoding any JSON fields of this
type. A JSON field is any Codable
field that doesn't have a
corresponding DatabaseValue
.
var jsonDecoder: JSONDecoder
Defaults to JSONDecoder()
.
The JSONEncoder
to use when decoding any JSON fields of this
type. A JSON field is any Codable
field on this type that
doesn't have a corresponding DatabaseValue
.
var jsonEncoder: JSONEncoder
Defaults to JSONEncoder()
.
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