From d4ab013301b8167a0d4e0e7101b8dba355067223 Mon Sep 17 00:00:00 2001 From: Tanner Nelson Date: Thu, 20 Jul 2017 14:17:45 -0400 Subject: [PATCH] build --- build/2.0/fluent/getting-started/index.html | 4 +- build/2.0/fluent/model/index.html | 2 +- build/2.0/mkdocs/search_index.json | 10 +- build/2.0/sitemap.xml | 144 ++++++++++---------- 4 files changed, 80 insertions(+), 80 deletions(-) diff --git a/build/2.0/fluent/getting-started/index.html b/build/2.0/fluent/getting-started/index.html index 55e210b1..eb3978d8 100644 --- a/build/2.0/fluent/getting-started/index.html +++ b/build/2.0/fluent/getting-started/index.html @@ -1822,7 +1822,7 @@

Note

Don't forget to add import FluentProvider (or your other database provider) to the top of your Swift files.

-

Fluent ships with SQLite by default. You can use SQLite to quickly scaffolding your application with the in-memory database it provides. This is enabled by default in Vapor's default template. To learn more about configuring your database, check out the available drivers.

+

Fluent ships with SQLite by default. You can use SQLite to quickly scaffold your application with the in-memory database it provides. This is enabled by default in Vapor's default template. To learn more about configuring your database, check out the available drivers.

Creating a Model

Models are the Swift representations of the data in your database. As such, they are central to most of Fluent's APIs.

Let's take a look at what a simple model looks like.

@@ -1922,7 +1922,7 @@

Add to Droplet

-

Now you can add your model to the config's prearations so the database is prepared when your application boots.

+

Now you can add your model to the config's preparations so the database is prepared when your application boots.

import Vapor
 import FluentProvider
 
diff --git a/build/2.0/fluent/model/index.html b/build/2.0/fluent/model/index.html
index a5ee317e..c718fc55 100644
--- a/build/2.0/fluent/model/index.html
+++ b/build/2.0/fluent/model/index.html
@@ -2212,7 +2212,7 @@ database or query may need when saving, fetching, or deleting your models.

Example: uuid, integer, etc.

This value should be overriden if a particular model in your database uses a different ID type.

final class Pet: Model {
-    static let idType = .uuid
+    static let idType: IdentifierType = .uuid
 }
 
diff --git a/build/2.0/mkdocs/search_index.json b/build/2.0/mkdocs/search_index.json index 903ef4cf..f2837ad8 100644 --- a/build/2.0/mkdocs/search_index.json +++ b/build/2.0/mkdocs/search_index.json @@ -1012,12 +1012,12 @@ }, { "location": "/fluent/getting-started/", - "text": "Getting Started with Fluent\n\n\nFluent provides an easy, simple, and safe API for working with your persisted data. Each database table/collection is represented by a \nModel\n that can be used to interact with the data. Fluent supports common operations like creating, reading, updating, and deleting models. It also supports more advanced operations like joining, relating, and soft deleting. \n\n\n\n\nNote\n\n\nDon't forget to add \nimport FluentProvider\n (or your other database provider) to the top of your Swift files.\n\n\n\n\nFluent ships with SQLite by default. You can use SQLite to quickly scaffolding your application with the in-memory database it provides. This is enabled by default in Vapor's default template. To learn more about configuring your database, check out the available \ndrivers\n.\n\n\nCreating a Model\n\n\nModels are the Swift representations of the data in your database. As such, they are central to most of Fluent's APIs.\n\n\nLet's take a look at what a simple model looks like.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nvar\n \nname\n:\n \nString\n\n \nvar\n \nage\n:\n \nInt\n\n \nlet\n \nstorage\n \n=\n \nStorage\n()\n\n\n \ninit\n(\nrow\n:\n \nRow\n)\n \nthrows\n \n{\n\n \nname\n \n=\n \ntry\n \nrow\n.\nget\n(\nname\n)\n\n \nage\n \n=\n \ntry\n \nrow\n.\nget\n(\nage\n)\n\n \n}\n\n\n \ninit\n(\nname\n:\n \nString\n,\n \nage\n:\n \nInt\n)\n \n{\n\n \nself\n.\nname\n \n=\n \nname\n\n \nself\n.\nage\n \n=\n \nage\n\n \n}\n\n\n \nfunc\n \nmakeRow\n()\n \nthrows\n \n-\n \nRow\n \n{\n\n \nvar\n \nrow\n \n=\n \nRow\n()\n\n \ntry\n \nrow\n.\nset\n(\nname\n,\n \nname\n)\n\n \ntry\n \nrow\n.\nset\n(\nage\n,\n \nage\n)\n\n \nreturn\n \nrow\n\n \n}\n\n\n}\n\n\n\n\n\n\nHere we are creating a simple class \nPet\n with a name and an age. We will add a simple init method for creating new pets.\n\n\nStorage\n\n\nThe \nstorage\n property is there to allow Fluent to store extra information on your model--things like the model's database id. \n\n\nRow\n\n\nThe \nRow\n struct represents a database row. Your models should be able to parse from and serialize to database rows.\n\n\nParse\n\n\nHere's the code for parsing the Pet from the database.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \n...\n\n\n \ninit\n(\nrow\n:\n \nRow\n)\n \nthrows\n \n{\n\n \nname\n \n=\n \ntry\n \nrow\n.\nget\n(\nname\n)\n\n \nage\n \n=\n \ntry\n \nrow\n.\nget\n(\nage\n)\n\n \n}\n\n\n}\n\n\n\n\n\n\nSerialize\n\n\nHere's the code for serializing the Pet to the database.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \n...\n\n\n \nfunc\n \nmakeRow\n()\n \nthrows\n \n-\n \nRow\n \n{\n\n \nvar\n \nrow\n \n=\n \nRow\n()\n\n \ntry\n \nrow\n.\nset\n(\nname\n,\n \nname\n)\n\n \ntry\n \nrow\n.\nset\n(\nage\n,\n \nage\n)\n\n \nreturn\n \nrow\n\n \n}\n\n\n}\n\n\n\n\n\n\nPreparing the Database\n\n\nIn order to use your model, you may need to prepare your database with an appropriate schema.\n\n\nPreparation\n\n\nYou can do this by conforming your model to \nPreparation\n.\n\n\nextension\n \nPet\n:\n \nPreparation\n \n{\n\n \nstatic\n \nfunc\n \nprepare\n(\n_\n \ndatabase\n:\n \nDatabase\n)\n \nthrows\n \n{\n\n \ntry\n \ndatabase\n.\ncreate\n(\nself\n)\n \n{\n \npets\n \nin\n\n \npets\n.\nid\n()\n\n \npets\n.\nstring\n(\nname\n)\n\n \npets\n.\nint\n(\nage\n)\n\n \n}\n\n \n}\n \n\n \nstatic\n \nfunc\n \nrevert\n(\n_\n \ndatabase\n:\n \nDatabase\n)\n \nthrows\n \n{\n\n \ntry\n \ndatabase\n.\ndelete\n(\nself\n)\n\n \n}\n\n\n}\n\n\n\n\n\n\nHere we are creating a simple table that will look like this:\n\n\n\n\n\n\n\n\nid\n\n\nname\n\n\nage\n\n\n\n\n\n\n\n\n\n\ndatabase id type\n\n\nstring\n\n\nint\n\n\n\n\n\n\n\n\nAdd to Droplet\n\n\nNow you can add your model to the config's prearations so the database is prepared when your application boots.\n\n\nimport\n \nVapor\n\n\nimport\n \nFluentProvider\n\n\n\nlet\n \nconfig\n \n=\n \ntry\n \nConfig\n()\n\n\nconfig\n.\npreparations\n.\nappend\n(\nPet\n.\nself\n)\n\n\nlet\n \ndrop\n \n=\n \ntry\n \nDroplet\n(\nconfig\n)\n\n\n\n...\n\n\n\n\n\n\nUsing Models\n\n\nNow that we have created our model and prepared the database, we can use it to save and fetch data from the database.\n\n\nSave\n\n\nTo save a model, call \n.save()\n. A new identifier for the model will automatically be created.\n\n\nlet\n \ndog\n \n=\n \nPet\n(\nname\n:\n \nSpud\n,\n \nage\n:\n \n5\n)\n\n\ntry\n \ndog\n.\nsave\n()\n\n\nprint\n(\ndog\n.\nid\n)\n \n// the newly saved pet\ns id\n\n\n\n\n\n\nFind\n\n\nYou can fetch a model from the database using it's ID.\n\n\nguard\n \nlet\n \ndog\n \n=\n \ntry\n \nPet\n.\nfind\n(\n42\n)\n \nelse\n \n{\n\n \nthrow\n \nAbort\n.\nnotFound\n\n\n}\n\n\n\nprint\n(\ndog\n.\nname\n)\n \n// the name of the dog with id 42\n\n\n\n\n\n\nFilter\n\n\nYou can also search for models using filters.\n\n\nlet\n \ndogs\n \n=\n \ntry\n \nPet\n.\nmakeQuery\n().\nfilter\n(\nage\n,\n \n.\ngreaterThan\n,\n \n2\n).\nall\n()\n\n\nprint\n(\ndogs\n)\n \n// all dogs older than 2\n\n\n\n\n\n\nDrivers\n\n\nCheck out the \ndatabase\n section for more information about different database drivers you can use with Fluent.", + "text": "Getting Started with Fluent\n\n\nFluent provides an easy, simple, and safe API for working with your persisted data. Each database table/collection is represented by a \nModel\n that can be used to interact with the data. Fluent supports common operations like creating, reading, updating, and deleting models. It also supports more advanced operations like joining, relating, and soft deleting. \n\n\n\n\nNote\n\n\nDon't forget to add \nimport FluentProvider\n (or your other database provider) to the top of your Swift files.\n\n\n\n\nFluent ships with SQLite by default. You can use SQLite to quickly scaffold your application with the in-memory database it provides. This is enabled by default in Vapor's default template. To learn more about configuring your database, check out the available \ndrivers\n.\n\n\nCreating a Model\n\n\nModels are the Swift representations of the data in your database. As such, they are central to most of Fluent's APIs.\n\n\nLet's take a look at what a simple model looks like.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nvar\n \nname\n:\n \nString\n\n \nvar\n \nage\n:\n \nInt\n\n \nlet\n \nstorage\n \n=\n \nStorage\n()\n\n\n \ninit\n(\nrow\n:\n \nRow\n)\n \nthrows\n \n{\n\n \nname\n \n=\n \ntry\n \nrow\n.\nget\n(\nname\n)\n\n \nage\n \n=\n \ntry\n \nrow\n.\nget\n(\nage\n)\n\n \n}\n\n\n \ninit\n(\nname\n:\n \nString\n,\n \nage\n:\n \nInt\n)\n \n{\n\n \nself\n.\nname\n \n=\n \nname\n\n \nself\n.\nage\n \n=\n \nage\n\n \n}\n\n\n \nfunc\n \nmakeRow\n()\n \nthrows\n \n-\n \nRow\n \n{\n\n \nvar\n \nrow\n \n=\n \nRow\n()\n\n \ntry\n \nrow\n.\nset\n(\nname\n,\n \nname\n)\n\n \ntry\n \nrow\n.\nset\n(\nage\n,\n \nage\n)\n\n \nreturn\n \nrow\n\n \n}\n\n\n}\n\n\n\n\n\n\nHere we are creating a simple class \nPet\n with a name and an age. We will add a simple init method for creating new pets.\n\n\nStorage\n\n\nThe \nstorage\n property is there to allow Fluent to store extra information on your model--things like the model's database id. \n\n\nRow\n\n\nThe \nRow\n struct represents a database row. Your models should be able to parse from and serialize to database rows.\n\n\nParse\n\n\nHere's the code for parsing the Pet from the database.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \n...\n\n\n \ninit\n(\nrow\n:\n \nRow\n)\n \nthrows\n \n{\n\n \nname\n \n=\n \ntry\n \nrow\n.\nget\n(\nname\n)\n\n \nage\n \n=\n \ntry\n \nrow\n.\nget\n(\nage\n)\n\n \n}\n\n\n}\n\n\n\n\n\n\nSerialize\n\n\nHere's the code for serializing the Pet to the database.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \n...\n\n\n \nfunc\n \nmakeRow\n()\n \nthrows\n \n-\n \nRow\n \n{\n\n \nvar\n \nrow\n \n=\n \nRow\n()\n\n \ntry\n \nrow\n.\nset\n(\nname\n,\n \nname\n)\n\n \ntry\n \nrow\n.\nset\n(\nage\n,\n \nage\n)\n\n \nreturn\n \nrow\n\n \n}\n\n\n}\n\n\n\n\n\n\nPreparing the Database\n\n\nIn order to use your model, you may need to prepare your database with an appropriate schema.\n\n\nPreparation\n\n\nYou can do this by conforming your model to \nPreparation\n.\n\n\nextension\n \nPet\n:\n \nPreparation\n \n{\n\n \nstatic\n \nfunc\n \nprepare\n(\n_\n \ndatabase\n:\n \nDatabase\n)\n \nthrows\n \n{\n\n \ntry\n \ndatabase\n.\ncreate\n(\nself\n)\n \n{\n \npets\n \nin\n\n \npets\n.\nid\n()\n\n \npets\n.\nstring\n(\nname\n)\n\n \npets\n.\nint\n(\nage\n)\n\n \n}\n\n \n}\n \n\n \nstatic\n \nfunc\n \nrevert\n(\n_\n \ndatabase\n:\n \nDatabase\n)\n \nthrows\n \n{\n\n \ntry\n \ndatabase\n.\ndelete\n(\nself\n)\n\n \n}\n\n\n}\n\n\n\n\n\n\nHere we are creating a simple table that will look like this:\n\n\n\n\n\n\n\n\nid\n\n\nname\n\n\nage\n\n\n\n\n\n\n\n\n\n\ndatabase id type\n\n\nstring\n\n\nint\n\n\n\n\n\n\n\n\nAdd to Droplet\n\n\nNow you can add your model to the config's preparations so the database is prepared when your application boots.\n\n\nimport\n \nVapor\n\n\nimport\n \nFluentProvider\n\n\n\nlet\n \nconfig\n \n=\n \ntry\n \nConfig\n()\n\n\nconfig\n.\npreparations\n.\nappend\n(\nPet\n.\nself\n)\n\n\nlet\n \ndrop\n \n=\n \ntry\n \nDroplet\n(\nconfig\n)\n\n\n\n...\n\n\n\n\n\n\nUsing Models\n\n\nNow that we have created our model and prepared the database, we can use it to save and fetch data from the database.\n\n\nSave\n\n\nTo save a model, call \n.save()\n. A new identifier for the model will automatically be created.\n\n\nlet\n \ndog\n \n=\n \nPet\n(\nname\n:\n \nSpud\n,\n \nage\n:\n \n5\n)\n\n\ntry\n \ndog\n.\nsave\n()\n\n\nprint\n(\ndog\n.\nid\n)\n \n// the newly saved pet\ns id\n\n\n\n\n\n\nFind\n\n\nYou can fetch a model from the database using it's ID.\n\n\nguard\n \nlet\n \ndog\n \n=\n \ntry\n \nPet\n.\nfind\n(\n42\n)\n \nelse\n \n{\n\n \nthrow\n \nAbort\n.\nnotFound\n\n\n}\n\n\n\nprint\n(\ndog\n.\nname\n)\n \n// the name of the dog with id 42\n\n\n\n\n\n\nFilter\n\n\nYou can also search for models using filters.\n\n\nlet\n \ndogs\n \n=\n \ntry\n \nPet\n.\nmakeQuery\n().\nfilter\n(\nage\n,\n \n.\ngreaterThan\n,\n \n2\n).\nall\n()\n\n\nprint\n(\ndogs\n)\n \n// all dogs older than 2\n\n\n\n\n\n\nDrivers\n\n\nCheck out the \ndatabase\n section for more information about different database drivers you can use with Fluent.", "title": "Getting Started" }, { "location": "/fluent/getting-started/#getting-started-with-fluent", - "text": "Fluent provides an easy, simple, and safe API for working with your persisted data. Each database table/collection is represented by a Model that can be used to interact with the data. Fluent supports common operations like creating, reading, updating, and deleting models. It also supports more advanced operations like joining, relating, and soft deleting. Note Don't forget to add import FluentProvider (or your other database provider) to the top of your Swift files. Fluent ships with SQLite by default. You can use SQLite to quickly scaffolding your application with the in-memory database it provides. This is enabled by default in Vapor's default template. To learn more about configuring your database, check out the available drivers .", + "text": "Fluent provides an easy, simple, and safe API for working with your persisted data. Each database table/collection is represented by a Model that can be used to interact with the data. Fluent supports common operations like creating, reading, updating, and deleting models. It also supports more advanced operations like joining, relating, and soft deleting. Note Don't forget to add import FluentProvider (or your other database provider) to the top of your Swift files. Fluent ships with SQLite by default. You can use SQLite to quickly scaffold your application with the in-memory database it provides. This is enabled by default in Vapor's default template. To learn more about configuring your database, check out the available drivers .", "title": "Getting Started with Fluent" }, { @@ -1057,7 +1057,7 @@ }, { "location": "/fluent/getting-started/#add-to-droplet", - "text": "Now you can add your model to the config's prearations so the database is prepared when your application boots. import Vapor import FluentProvider let config = try Config () config . preparations . append ( Pet . self ) let drop = try Droplet ( config ) ...", + "text": "Now you can add your model to the config's preparations so the database is prepared when your application boots. import Vapor import FluentProvider let config = try Config () config . preparations . append ( Pet . self ) let drop = try Droplet ( config ) ...", "title": "Add to Droplet" }, { @@ -1087,7 +1087,7 @@ }, { "location": "/fluent/model/", - "text": "Model\n\n\nModels are the Swift representations of the data in your database. As such, they are central to most of Fluent's APIs. \n\n\nThis guide is an overview of the protocol requirements and methods associated with models.\n\n\n\n\nSeealso\n\n\nCheck out the \ngetting started\n guide for an introductory overview on using models.\n\n\n\n\nCRUD\n\n\nModels have several basic methods for creating, reading, updating, and deleting.\n\n\nSave\n\n\nPersists the entity into the data store and sets the \nid\n property.\n\n\nlet\n \npet\n \n=\n \nPet\n(\nname\n:\n \nSpud\n,\n \nage\n:\n \n2\n)\n\n\ntry\n \npet\n.\nsave\n()\n\n\n\n\n\n\nFind\n\n\nFinds the model with the supplied identifier or returns \nnil\n.\n\n\nguard\n \nlet\n \npet\n \n=\n \ntry\n \nPets\n.\nfind\n(\n42\n)\n \nelse\n \n{\n\n \nthrow\n \nAbort\n.\nnotFound\n\n\n}\n\n\nprint\n(\npet\n.\nname\n)\n\n\n\n\n\n\nDelete\n\n\nDeletes the entity from the data store if the entity has previously been fetched or saved.\n\n\ntry\n \npet\n.\ndelete\n()\n\n\n\n\n\n\nAll\n\n\nReturns all entities for this model.\n\n\nfor\n \npet\n \nin\n \ntry\n \nPets\n.\nall\n()\n \n{\n\n \nprint\n(\npet\n.\nname\n)\n\n\n}\n\n\n\n\n\n\nCount\n\n\nReturns a count of all entities for this model.\n\n\nlet\n \ncount\n \n=\n \ntry\n \nPets\n.\ncount\n()\n\n\n\n\n\n\nChunk\n\n\nReturns chunked arrays of a supplied size for all of the entities for this model.\n\n\nThis is a great way to parse through all models of a large data set.\n\n\ntry\n \nPets\n.\nchunk\n(\n20\n)\n \n{\n \npets\n \nin\n\n \n//\n\n\n}\n\n\n\n\n\n\nQuery\n\n\nCreates a \nQuery\n instance for this \nModel\n.\n\n\nlet\n \nquery\n \n=\n \ntry\n \nPet\n.\nmakeQuery\n()\n\n\n\n\n\n\nTo learn more about crafting complex queries, see the \nquery\n section.\n\n\nTimestamps\n\n\nTo add timestamps to your model, simply conform it to \nTimestampable\n.\n\n\nextension\n \nUser\n:\n \nTimestampable\n \n{\n \n}\n\n\n\n\n\n\nYou can access the updated at and created at times on any model instance.\n\n\nuser\n.\nupdatedAt\n \n// Date?\n\n\nuser\n.\ncreatedAt\n \n// Date?\n\n\n\n\n\n\nWhen filtering or sorting on the timestamp data, you can use the timestamp keys from the class.\n\n\nlet\n \nnewUsers\n \n=\n \ntry\n \nUser\n\n \n.\nmakeQuery\n()\n\n \n.\nfilter\n(\nUser\n.\ncreatedAtKey\n,\n \n.\ngreaterThan\n,\n \n...)\n\n \n.\nall\n()\n\n\n\n\n\n\nYou can also override the timestamp keys if you have custom needs.\n\n\nextension\n \nUser\n:\n \nTimestampable\n \n{\n\n \nstatic\n \nvar\n \nupdatedAtKey\n:\n \nString\n \n{\n \nreturn\n \ncustom_updated_at\n \n}\n\n \nstatic\n \nvar\n \ncreatedAtKey\n:\n \nString\n \n{\n \nreturn\n \ncustom_created_at\n \n}\n\n\n}\n\n\n\n\n\n\nMigration\n\n\nTimestampable\n models will automatically have created at and updated at keys added during\n\ndatabase create\n calls.\n\n\nShould you need to manually add \nTimestampable\n to an existing model, you can use the \ndate()\n method\nin a \nmigration\n.\n\n\ndatabase\n.\nmodify\n(\nUser\n.\nself\n)\n \n{\n \nbuilder\n \nin\n\n \nbuilder\n.\ndate\n(\nUser\n.\ncreatedAtKey\n)\n\n \nbuilder\n.\ndate\n(\nUser\n.\nupdatedAtKey\n)\n\n\n}\n\n\n\n\n\n\nSoft Delete\n\n\nSoft delete is a way of \"deleting\" a model from all fetch and update queries to Fluent but not actually deleting the model from the database. Soft deleted models can also be restored. \n\n\nTo make your model soft deletable, simply conform it to \nSoftDeletable\n.\n\n\nextension\n \nUser\n:\n \nSoftDeletable\n \n{\n \n}\n\n\n\n\n\n\nOnce your model is soft deletable, all calls to \ndelete()\n will set the deleted at flag instead of actually\ndeleting the model.\n\n\nTo restore a model, call \n.restore()\n. To actually delete a model from the database, call \n.forceDelete()\n.\n\n\nYou can also override the soft delete key if you have custom needs.\n\n\nextension\n \nUser\n:\n \nSoftDeletable\n \n{\n\n \nstatic\n \nvar\n \ndeletedAtKey\n:\n \nString\n \n{\n \nreturn\n \ncustom_deleted_at\n \n}\n\n\n}\n\n\n\n\n\n\nIncluding Deleted\n\n\nWhen a model is soft deleted, it will not be affected by any queries made with the Fluent query builder.\n\n\nTo include soft deleted models, for instance if you want to restore them, use the \n.withSoftDeleted()\n method\non the query builder.\n\n\nlet\n \nallUsers\n \n=\n \ntry\n \nUser\n.\nmakeQuery\n().\nwithSoftDeleted\n().\nall\n()\n\n\n\n\n\n\nLifecycle\n\n\nYou can hook into the soft delete events of a model.\n\n\nextension\n \nUser\n:\n \nSoftDeletable\n \n{\n\n \nfunc\n \nwillSoftDelete\n()\n \nthrows\n \n{\n \n...\n \n}\n\n \nfunc\n \ndidSoftDelete\n()\n \n{\n \n...\n \n}\n\n \nfunc\n \nwillForceDelete\n()\n \nthrows\n \n{\n \n...\n \n}\n\n \nfunc\n \ndidForceDelete\n()\n \n{\n \n...\n \n}\n\n \nfunc\n \nwillRestore\n()\n \nthrows\n \n{\n \n...\n \n}\n\n \nfunc\n \ndidRestore\n()\n \n{\n \n...\n \n}\n\n\n}\n\n\n\n\n\n\n\n\nNote\n\n\nThrowing during a \nwill\n hook will prevent the action from happening.\n\n\n\n\nMigration\n\n\nSoftDeletable\n models will automatically have a deleted at key added during\n\ndatabase create\n calls.\n\n\nShould you need to manually add \nSoftDeletable\n to an existing model, you can use the \ndate()\n method\nin a \nmigration\n.\n\n\ndatabase\n.\nmodify\n(\nUser\n.\nself\n)\n \n{\n \nbuilder\n \nin\n\n \nbuilder\n.\ndate\n(\nUser\n.\ndeletedAtKey\n,\n \noptional\n:\n \ntrue\n)\n\n\n}\n\n\n\n\n\n\nConvenience\n\n\nAssert Exists\n\n\nThe identifier property of a model is optional since models may not have been saved yet.\n\n\nYou can get the identifier or throw an error if the model has not been saved yet by calling \nassertExists()\n.\n\n\nlet\n \nid\n \n=\n \ntry\n \npet\n.\nassertExists\n()\n\n\nprint\n(\nid\n)\n \n// not optional\n\n\n\n\n\n\nLife Cycle\n\n\nThe following life-cycle methods can be implemented on your model to hook into internal operations.\n\n\n/// Called before the entity will be created.\n\n\n/// Throwing will cancel the creation.\n\n\nfunc\n \nwillCreate\n()\n \nthrows\n\n\n\n/// Called after the entity has been created.\n\n\nfunc\n \ndidCreate\n()\n\n\n\n/// Called before the entity will be updated.\n\n\n/// Throwing will cancel the update.\n\n\nfunc\n \nwillUpdate\n()\n \nthrows\n\n\n\n/// Called after the entity has been updated.\n\n\nfunc\n \ndidUpdate\n()\n\n\n\n/// Called before the entity will be deleted.\n\n\n/// Throwing will cancel the deletion.\n\n\nfunc\n \nwillDelete\n()\n \nthrows\n\n\n\n/// Called after the entity has been deleted.\n\n\nfunc\n \ndidDelete\n()\n\n\n\n\n\n\n\n\nNote\n\n\nThrowing in a \nwillFoo()\n method will cancel the operation.\n\n\n\n\nHere's an example of implementing the \ndidDelete\n method.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \n...\n \n\n \nfunc\n \ndidDelete\n()\n \n{\n\n \nprint\n(\nDeleted \n\\(\nname\n)\n)\n\n \n}\n\n\n}\n\n\n\n\n\n\nEntity\n\n\nEntity is the base Fluent protocol that Model conforms to. It is responsible for providing all information the \ndatabase or query may need when saving, fetching, or deleting your models.\n\n\nName\n\n\nThe singular relational name of this model. Also used for internal storage. Example: Pet = \"pet\".\n\n\nThis value should usually not be overriden. \n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nname\n \n=\n \npet\n\n\n}\n\n\n\n\n\n\nEntity\n\n\nThe plural relational name of this model. Used as the collection or table name. \n\n\nExample: Pet = \"pets\".\n\n\nThis value should be overriden if the table name for your model is non-standard.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nentity\n \n=\n \npets\n\n\n}\n\n\n\n\n\n\nID Type\n\n\nThe type of identifier used for both the local and foreign id keys. \n\n\nExample: uuid, integer, etc.\n\n\nThis value should be overriden if a particular model in your database uses a different ID type.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nidType\n \n=\n \n.\nuuid\n\n\n}\n\n\n\n\n\n\nThis can also be overridden at the database level using config.\n\n\nConfig/fluent.json\n\n\n{\n\n \nidType\n:\n \nuuid\n\n\n}\n\n\n\n\n\n\nOr programatically.\n\n\ndrop\n.\ndatabase\n?.\nidType\n \n=\n \n.\nuuid\n\n\n\n\n\n\nKey Naming Convention\n\n\nThe naming convetion to use for foreign id keys, table names, etc.\n\n\nExample: snake_case vs. camelCase.\n\n\nThis value should be overridden if a particular model in your database uses a different key naming convention.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nkeyNamingConvention\n \n=\n \n.\nsnake_case\n\n\n}\n\n\n\n\n\n\nThis can also be overridden at the database level using config.\n\n\nConfig/fluent.json\n\n\n{\n\n \nkeyNamingConvention\n:\n \nsnake_case\n\n\n}\n\n\n\n\n\n\nOr programatically.\n\n\ndrop\n.\ndatabase\n?.\nkeyNamingConvention\n \n=\n \n.\nsnake_case\n\n\n\n\n\n\nID Key\n\n\nThe name of the column that corresponds to this entity's identifying key.\n\n\nThe default is 'database.driver.idKey', and then \"id\"\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nidKey\n \n=\n \nid\n\n\n}\n\n\n\n\n\n\nForeign ID Key\n\n\nThe name of the column that points to this entity's id when referenced from other tables or collections.\n\n\nExample: \"foo_id\".\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nforeignIdKey\n \n=\n \npet_id\n\n\n}", + "text": "Model\n\n\nModels are the Swift representations of the data in your database. As such, they are central to most of Fluent's APIs. \n\n\nThis guide is an overview of the protocol requirements and methods associated with models.\n\n\n\n\nSeealso\n\n\nCheck out the \ngetting started\n guide for an introductory overview on using models.\n\n\n\n\nCRUD\n\n\nModels have several basic methods for creating, reading, updating, and deleting.\n\n\nSave\n\n\nPersists the entity into the data store and sets the \nid\n property.\n\n\nlet\n \npet\n \n=\n \nPet\n(\nname\n:\n \nSpud\n,\n \nage\n:\n \n2\n)\n\n\ntry\n \npet\n.\nsave\n()\n\n\n\n\n\n\nFind\n\n\nFinds the model with the supplied identifier or returns \nnil\n.\n\n\nguard\n \nlet\n \npet\n \n=\n \ntry\n \nPets\n.\nfind\n(\n42\n)\n \nelse\n \n{\n\n \nthrow\n \nAbort\n.\nnotFound\n\n\n}\n\n\nprint\n(\npet\n.\nname\n)\n\n\n\n\n\n\nDelete\n\n\nDeletes the entity from the data store if the entity has previously been fetched or saved.\n\n\ntry\n \npet\n.\ndelete\n()\n\n\n\n\n\n\nAll\n\n\nReturns all entities for this model.\n\n\nfor\n \npet\n \nin\n \ntry\n \nPets\n.\nall\n()\n \n{\n\n \nprint\n(\npet\n.\nname\n)\n\n\n}\n\n\n\n\n\n\nCount\n\n\nReturns a count of all entities for this model.\n\n\nlet\n \ncount\n \n=\n \ntry\n \nPets\n.\ncount\n()\n\n\n\n\n\n\nChunk\n\n\nReturns chunked arrays of a supplied size for all of the entities for this model.\n\n\nThis is a great way to parse through all models of a large data set.\n\n\ntry\n \nPets\n.\nchunk\n(\n20\n)\n \n{\n \npets\n \nin\n\n \n//\n\n\n}\n\n\n\n\n\n\nQuery\n\n\nCreates a \nQuery\n instance for this \nModel\n.\n\n\nlet\n \nquery\n \n=\n \ntry\n \nPet\n.\nmakeQuery\n()\n\n\n\n\n\n\nTo learn more about crafting complex queries, see the \nquery\n section.\n\n\nTimestamps\n\n\nTo add timestamps to your model, simply conform it to \nTimestampable\n.\n\n\nextension\n \nUser\n:\n \nTimestampable\n \n{\n \n}\n\n\n\n\n\n\nYou can access the updated at and created at times on any model instance.\n\n\nuser\n.\nupdatedAt\n \n// Date?\n\n\nuser\n.\ncreatedAt\n \n// Date?\n\n\n\n\n\n\nWhen filtering or sorting on the timestamp data, you can use the timestamp keys from the class.\n\n\nlet\n \nnewUsers\n \n=\n \ntry\n \nUser\n\n \n.\nmakeQuery\n()\n\n \n.\nfilter\n(\nUser\n.\ncreatedAtKey\n,\n \n.\ngreaterThan\n,\n \n...)\n\n \n.\nall\n()\n\n\n\n\n\n\nYou can also override the timestamp keys if you have custom needs.\n\n\nextension\n \nUser\n:\n \nTimestampable\n \n{\n\n \nstatic\n \nvar\n \nupdatedAtKey\n:\n \nString\n \n{\n \nreturn\n \ncustom_updated_at\n \n}\n\n \nstatic\n \nvar\n \ncreatedAtKey\n:\n \nString\n \n{\n \nreturn\n \ncustom_created_at\n \n}\n\n\n}\n\n\n\n\n\n\nMigration\n\n\nTimestampable\n models will automatically have created at and updated at keys added during\n\ndatabase create\n calls.\n\n\nShould you need to manually add \nTimestampable\n to an existing model, you can use the \ndate()\n method\nin a \nmigration\n.\n\n\ndatabase\n.\nmodify\n(\nUser\n.\nself\n)\n \n{\n \nbuilder\n \nin\n\n \nbuilder\n.\ndate\n(\nUser\n.\ncreatedAtKey\n)\n\n \nbuilder\n.\ndate\n(\nUser\n.\nupdatedAtKey\n)\n\n\n}\n\n\n\n\n\n\nSoft Delete\n\n\nSoft delete is a way of \"deleting\" a model from all fetch and update queries to Fluent but not actually deleting the model from the database. Soft deleted models can also be restored. \n\n\nTo make your model soft deletable, simply conform it to \nSoftDeletable\n.\n\n\nextension\n \nUser\n:\n \nSoftDeletable\n \n{\n \n}\n\n\n\n\n\n\nOnce your model is soft deletable, all calls to \ndelete()\n will set the deleted at flag instead of actually\ndeleting the model.\n\n\nTo restore a model, call \n.restore()\n. To actually delete a model from the database, call \n.forceDelete()\n.\n\n\nYou can also override the soft delete key if you have custom needs.\n\n\nextension\n \nUser\n:\n \nSoftDeletable\n \n{\n\n \nstatic\n \nvar\n \ndeletedAtKey\n:\n \nString\n \n{\n \nreturn\n \ncustom_deleted_at\n \n}\n\n\n}\n\n\n\n\n\n\nIncluding Deleted\n\n\nWhen a model is soft deleted, it will not be affected by any queries made with the Fluent query builder.\n\n\nTo include soft deleted models, for instance if you want to restore them, use the \n.withSoftDeleted()\n method\non the query builder.\n\n\nlet\n \nallUsers\n \n=\n \ntry\n \nUser\n.\nmakeQuery\n().\nwithSoftDeleted\n().\nall\n()\n\n\n\n\n\n\nLifecycle\n\n\nYou can hook into the soft delete events of a model.\n\n\nextension\n \nUser\n:\n \nSoftDeletable\n \n{\n\n \nfunc\n \nwillSoftDelete\n()\n \nthrows\n \n{\n \n...\n \n}\n\n \nfunc\n \ndidSoftDelete\n()\n \n{\n \n...\n \n}\n\n \nfunc\n \nwillForceDelete\n()\n \nthrows\n \n{\n \n...\n \n}\n\n \nfunc\n \ndidForceDelete\n()\n \n{\n \n...\n \n}\n\n \nfunc\n \nwillRestore\n()\n \nthrows\n \n{\n \n...\n \n}\n\n \nfunc\n \ndidRestore\n()\n \n{\n \n...\n \n}\n\n\n}\n\n\n\n\n\n\n\n\nNote\n\n\nThrowing during a \nwill\n hook will prevent the action from happening.\n\n\n\n\nMigration\n\n\nSoftDeletable\n models will automatically have a deleted at key added during\n\ndatabase create\n calls.\n\n\nShould you need to manually add \nSoftDeletable\n to an existing model, you can use the \ndate()\n method\nin a \nmigration\n.\n\n\ndatabase\n.\nmodify\n(\nUser\n.\nself\n)\n \n{\n \nbuilder\n \nin\n\n \nbuilder\n.\ndate\n(\nUser\n.\ndeletedAtKey\n,\n \noptional\n:\n \ntrue\n)\n\n\n}\n\n\n\n\n\n\nConvenience\n\n\nAssert Exists\n\n\nThe identifier property of a model is optional since models may not have been saved yet.\n\n\nYou can get the identifier or throw an error if the model has not been saved yet by calling \nassertExists()\n.\n\n\nlet\n \nid\n \n=\n \ntry\n \npet\n.\nassertExists\n()\n\n\nprint\n(\nid\n)\n \n// not optional\n\n\n\n\n\n\nLife Cycle\n\n\nThe following life-cycle methods can be implemented on your model to hook into internal operations.\n\n\n/// Called before the entity will be created.\n\n\n/// Throwing will cancel the creation.\n\n\nfunc\n \nwillCreate\n()\n \nthrows\n\n\n\n/// Called after the entity has been created.\n\n\nfunc\n \ndidCreate\n()\n\n\n\n/// Called before the entity will be updated.\n\n\n/// Throwing will cancel the update.\n\n\nfunc\n \nwillUpdate\n()\n \nthrows\n\n\n\n/// Called after the entity has been updated.\n\n\nfunc\n \ndidUpdate\n()\n\n\n\n/// Called before the entity will be deleted.\n\n\n/// Throwing will cancel the deletion.\n\n\nfunc\n \nwillDelete\n()\n \nthrows\n\n\n\n/// Called after the entity has been deleted.\n\n\nfunc\n \ndidDelete\n()\n\n\n\n\n\n\n\n\nNote\n\n\nThrowing in a \nwillFoo()\n method will cancel the operation.\n\n\n\n\nHere's an example of implementing the \ndidDelete\n method.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \n...\n \n\n \nfunc\n \ndidDelete\n()\n \n{\n\n \nprint\n(\nDeleted \n\\(\nname\n)\n)\n\n \n}\n\n\n}\n\n\n\n\n\n\nEntity\n\n\nEntity is the base Fluent protocol that Model conforms to. It is responsible for providing all information the \ndatabase or query may need when saving, fetching, or deleting your models.\n\n\nName\n\n\nThe singular relational name of this model. Also used for internal storage. Example: Pet = \"pet\".\n\n\nThis value should usually not be overriden. \n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nname\n \n=\n \npet\n\n\n}\n\n\n\n\n\n\nEntity\n\n\nThe plural relational name of this model. Used as the collection or table name. \n\n\nExample: Pet = \"pets\".\n\n\nThis value should be overriden if the table name for your model is non-standard.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nentity\n \n=\n \npets\n\n\n}\n\n\n\n\n\n\nID Type\n\n\nThe type of identifier used for both the local and foreign id keys. \n\n\nExample: uuid, integer, etc.\n\n\nThis value should be overriden if a particular model in your database uses a different ID type.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nidType\n:\n \nIdentifierType\n \n=\n \n.\nuuid\n\n\n}\n\n\n\n\n\n\nThis can also be overridden at the database level using config.\n\n\nConfig/fluent.json\n\n\n{\n\n \nidType\n:\n \nuuid\n\n\n}\n\n\n\n\n\n\nOr programatically.\n\n\ndrop\n.\ndatabase\n?.\nidType\n \n=\n \n.\nuuid\n\n\n\n\n\n\nKey Naming Convention\n\n\nThe naming convetion to use for foreign id keys, table names, etc.\n\n\nExample: snake_case vs. camelCase.\n\n\nThis value should be overridden if a particular model in your database uses a different key naming convention.\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nkeyNamingConvention\n \n=\n \n.\nsnake_case\n\n\n}\n\n\n\n\n\n\nThis can also be overridden at the database level using config.\n\n\nConfig/fluent.json\n\n\n{\n\n \nkeyNamingConvention\n:\n \nsnake_case\n\n\n}\n\n\n\n\n\n\nOr programatically.\n\n\ndrop\n.\ndatabase\n?.\nkeyNamingConvention\n \n=\n \n.\nsnake_case\n\n\n\n\n\n\nID Key\n\n\nThe name of the column that corresponds to this entity's identifying key.\n\n\nThe default is 'database.driver.idKey', and then \"id\"\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nidKey\n \n=\n \nid\n\n\n}\n\n\n\n\n\n\nForeign ID Key\n\n\nThe name of the column that points to this entity's id when referenced from other tables or collections.\n\n\nExample: \"foo_id\".\n\n\nfinal\n \nclass\n \nPet\n:\n \nModel\n \n{\n\n \nstatic\n \nlet\n \nforeignIdKey\n \n=\n \npet_id\n\n\n}", "title": "Model" }, { @@ -1197,7 +1197,7 @@ }, { "location": "/fluent/model/#id-type", - "text": "The type of identifier used for both the local and foreign id keys. Example: uuid, integer, etc. This value should be overriden if a particular model in your database uses a different ID type. final class Pet : Model { \n static let idType = . uuid } This can also be overridden at the database level using config. Config/fluent.json { \n idType : uuid } Or programatically. drop . database ?. idType = . uuid", + "text": "The type of identifier used for both the local and foreign id keys. Example: uuid, integer, etc. This value should be overriden if a particular model in your database uses a different ID type. final class Pet : Model { \n static let idType : IdentifierType = . uuid } This can also be overridden at the database level using config. Config/fluent.json { \n idType : uuid } Or programatically. drop . database ?. idType = . uuid", "title": "ID Type" }, { diff --git a/build/2.0/sitemap.xml b/build/2.0/sitemap.xml index 581a14b0..56ee23fb 100644 --- a/build/2.0/sitemap.xml +++ b/build/2.0/sitemap.xml @@ -4,7 +4,7 @@ / - 2017-07-19 + 2017-07-20 daily @@ -13,37 +13,37 @@ /getting-started/install-on-macos/ - 2017-07-19 + 2017-07-20 daily /getting-started/install-on-ubuntu/ - 2017-07-19 + 2017-07-20 daily /getting-started/toolbox/ - 2017-07-19 + 2017-07-20 daily /getting-started/hello-world/ - 2017-07-19 + 2017-07-20 daily /getting-started/manual/ - 2017-07-19 + 2017-07-20 daily /getting-started/xcode/ - 2017-07-19 + 2017-07-20 daily @@ -53,49 +53,49 @@ /vapor/folder-structure/ - 2017-07-19 + 2017-07-20 daily /vapor/droplet/ - 2017-07-19 + 2017-07-20 daily /vapor/views/ - 2017-07-19 + 2017-07-20 daily /vapor/controllers/ - 2017-07-19 + 2017-07-20 daily /vapor/provider/ - 2017-07-19 + 2017-07-20 daily /vapor/hash/ - 2017-07-19 + 2017-07-20 daily /vapor/log/ - 2017-07-19 + 2017-07-20 daily /vapor/commands/ - 2017-07-19 + 2017-07-20 daily @@ -105,7 +105,7 @@ /configs/config/ - 2017-07-19 + 2017-07-20 daily @@ -115,13 +115,13 @@ /json/package/ - 2017-07-19 + 2017-07-20 daily /json/overview/ - 2017-07-19 + 2017-07-20 daily @@ -131,31 +131,31 @@ /routing/package/ - 2017-07-19 + 2017-07-20 daily /routing/overview/ - 2017-07-19 + 2017-07-20 daily /routing/parameters/ - 2017-07-19 + 2017-07-20 daily /routing/group/ - 2017-07-19 + 2017-07-20 daily /routing/collection/ - 2017-07-19 + 2017-07-20 daily @@ -165,37 +165,37 @@ /fluent/package/ - 2017-07-19 + 2017-07-20 daily /fluent/getting-started/ - 2017-07-19 + 2017-07-20 daily /fluent/model/ - 2017-07-19 + 2017-07-20 daily /fluent/database/ - 2017-07-19 + 2017-07-20 daily /fluent/query/ - 2017-07-19 + 2017-07-20 daily /fluent/relations/ - 2017-07-19 + 2017-07-20 daily @@ -205,13 +205,13 @@ /cache/package/ - 2017-07-19 + 2017-07-20 daily /cache/overview/ - 2017-07-19 + 2017-07-20 daily @@ -221,19 +221,19 @@ /mysql/package/ - 2017-07-19 + 2017-07-20 daily /mysql/provider/ - 2017-07-19 + 2017-07-20 daily /mysql/driver/ - 2017-07-19 + 2017-07-20 daily @@ -243,13 +243,13 @@ /redis/package/ - 2017-07-19 + 2017-07-20 daily /redis/provider/ - 2017-07-19 + 2017-07-20 daily @@ -259,37 +259,37 @@ /auth/package/ - 2017-07-19 + 2017-07-20 daily /auth/provider/ - 2017-07-19 + 2017-07-20 daily /auth/getting-started/ - 2017-07-19 + 2017-07-20 daily /auth/helper/ - 2017-07-19 + 2017-07-20 daily /auth/password/ - 2017-07-19 + 2017-07-20 daily /auth/persist/ - 2017-07-19 + 2017-07-20 daily @@ -299,13 +299,13 @@ /sessions/package/ - 2017-07-19 + 2017-07-20 daily /sessions/sessions/ - 2017-07-19 + 2017-07-20 daily @@ -315,61 +315,61 @@ /http/package/ - 2017-07-19 + 2017-07-20 daily /http/request/ - 2017-07-19 + 2017-07-20 daily /http/response/ - 2017-07-19 + 2017-07-20 daily /http/middleware/ - 2017-07-19 + 2017-07-20 daily /http/body/ - 2017-07-19 + 2017-07-20 daily /http/response-representable/ - 2017-07-19 + 2017-07-20 daily /http/responder/ - 2017-07-19 + 2017-07-20 daily /http/client/ - 2017-07-19 + 2017-07-20 daily /http/server/ - 2017-07-19 + 2017-07-20 daily /http/cors/ - 2017-07-19 + 2017-07-20 daily @@ -379,19 +379,19 @@ /leaf/package/ - 2017-07-19 + 2017-07-20 daily /leaf/provider/ - 2017-07-19 + 2017-07-20 daily /leaf/leaf/ - 2017-07-19 + 2017-07-20 daily @@ -401,13 +401,13 @@ /validation/package/ - 2017-07-19 + 2017-07-20 daily /validation/overview/ - 2017-07-19 + 2017-07-20 daily @@ -417,13 +417,13 @@ /node/package/ - 2017-07-19 + 2017-07-20 daily /node/getting-started/ - 2017-07-19 + 2017-07-20 daily @@ -433,13 +433,13 @@ /core/package/ - 2017-07-19 + 2017-07-20 daily /core/overview/ - 2017-07-19 + 2017-07-20 daily @@ -449,13 +449,13 @@ /bits/package/ - 2017-07-19 + 2017-07-20 daily /bits/overview/ - 2017-07-19 + 2017-07-20 daily @@ -465,13 +465,13 @@ /debugging/package/ - 2017-07-19 + 2017-07-20 daily /debugging/overview/ - 2017-07-19 + 2017-07-20 daily @@ -481,13 +481,13 @@ /deploy/nginx/ - 2017-07-19 + 2017-07-20 daily /deploy/supervisor/ - 2017-07-19 + 2017-07-20 daily @@ -497,19 +497,19 @@ /version/1_5/ - 2017-07-19 + 2017-07-20 daily /version/2_0/ - 2017-07-19 + 2017-07-20 daily /version/support/ - 2017-07-19 + 2017-07-20 daily