This commit is contained in:
tanner0101 2018-07-16 20:26:39 -04:00
parent 89a6594549
commit 87ebdba1c7
2 changed files with 13 additions and 14 deletions

View File

@ -2022,12 +2022,12 @@
},
{
"location": "/sqlite/getting-started/",
"text": "SQLite\n\n\nSQLite (\nvapor/sqlite\n) is a wrapper around the \nlibsqlite\n C-library.\n\n\n\n\nSeealso\n\n\nThe higher-level, Fluent ORM guide is located at \nFluent \n Getting Started\n\n\n\n\nUsing just the SQLite package for your project may be a good idea if any of the following are true.\n\n\n\n\nYou have an existing DB with non-standard structure.\n\n\nYou rely heavily on custom or complex SQL queries.\n\n\nYou just plain don't like ORMs.\n\n\n\n\nSQLite core is built on top of DatabaseKit which provides some conveniences like connection pooling and integrations with Vapor's \nServices\n architecture.\n\n\n\n\nTip\n\n\nEven if you do choose to use \nFluent SQLite\n, all of the features of SQLite core will be available to you.\n\n\n\n\nGetting Started\n\n\nLet's take a look at how you can get started using SQLite core.\n\n\nPackage\n\n\nThe first step to using SQLite core is adding it as a dependency to your project in your SPM package manifest file.\n\n\n// swift-tools-version:4.0\n\n\nimport\n \nPackageDescription\n\n\n\nlet\n \npackage\n \n=\n \nPackage\n(\n\n \nname\n:\n \nMyApp\n,\n\n \ndependencies\n:\n \n[\n\n \n/// Any other dependencies ...\n\n\n \n// \ud83d\udd35 SQLite 3 wrapper for Swift.\n\n \n.\npackage\n(\nurl\n:\n \nhttps://github.com/vapor/sqlite.git\n,\n \nfrom\n:\n \n3.0.0\n),\n\n \n],\n\n \ntargets\n:\n \n[\n\n \n.\ntarget\n(\nname\n:\n \nApp\n,\n \ndependencies\n:\n \n[\nSQLite\n,\n \n...]),\n\n \n.\ntarget\n(\nname\n:\n \nRun\n,\n \ndependencies\n:\n \n[\nApp\n]),\n\n \n.\ntestTarget\n(\nname\n:\n \nAppTests\n,\n \ndependencies\n:\n \n[\nApp\n]),\n\n \n]\n\n\n)\n\n\n\n\n\n\nDon't forget to add the module as a dependency in the \ntargets\n array. Once you have added the dependency, regenerate your Xcode project with the following command:\n\n\nvapor xcode\n\n\n\n\n\nConfig\n\n\nThe next step is to configure the database in \nconfigure.swift\n. SQLite's default database identifier is \n.sqlite\n. You can create a custom identifier if you want by extending \nDatabaseIdentifier\n. \n\n\nimport\n \nSQLite\n\n\n\n/// ...\n\n\n\n/// Register providers first\n\n\ntry\n \nservices\n.\nregister\n(\nSQLiteProvider\n())\n\n\n\n\n\n\nRegistering the provider will add all of the services required for SQLite to work properly. It also includes a default database config struct that uses an in-memory DB.\n\n\nYou can of course override this if you'd like to use a different configuration. SQLite supports in-memory and file-based db persistance. \n\n\n// Configure a SQLite database\n\n\nlet\n \nsqlite\n \n=\n \ntry\n \nSQLiteDatabase\n(\nstorage\n:\n \n.\nfile\n(\npath\n:\n \ndb.sqlite\n))\n\n\n\n/// Register the configured SQLite database to the database config.\n\n\nvar\n \ndatabases\n \n=\n \nDatabasesConfig\n()\n\n\ndatabases\n.\nadd\n(\ndatabase\n:\n \nsqlite\n,\n \nas\n:\n \n.\nsqlite\n)\n\n\nservices\n.\nregister\n(\ndatabases\n)\n\n\n\n\n\n\nQuery\n\n\nNow that the database is configured, you can make your first query.\n\n\nstruct\n \nSQLiteVersion\n:\n \nCodable\n \n{\n\n \nlet\n \nversion\n:\n \nString\n\n\n}\n\n\n\nrouter\n.\nget\n(\nsql\n)\n \n{\n \nreq\n \nin\n\n \nreturn\n \nreq\n.\nwithPooledConnection\n(\nto\n:\n \n.\nsqlite\n)\n \n{\n \nconn\n \nin\n\n \nreturn\n \nconn\n.\nselect\n()\n\n \n.\ncolumn\n(\nfunction\n:\n \nsqlite_version\n,\n \nas\n:\n \nversion\n)\n\n \n.\nall\n(\ndecoding\n:\n \nSQLiteVersion\n.\nself\n)\n\n \n}.\nmap\n \n{\n \nrows\n \nin\n\n \nreturn\n \nrows\n[\n0\n].\nversion\n\n \n}\n\n\n}\n\n\n\n\n\n\nVisiting this route should display your SQLite version. \n\n\nThe first step is to create a connection--here we are making use of database connection pooling. You can learn more about creating connections in \nDatabaseKit \n Getting Started\n.\n\n\nOnce we have a connection, we can use \nselect()\n to create a \nSELECT\n query builder. Learn more about building queries in \nSQL \n Getting Started\n.",
"text": "SQLite\n\n\nSQLite (\nvapor/sqlite\n) is a wrapper around the \nlibsqlite\n C-library.\n\n\nThe higher-level, Fluent ORM guide is located at \nFluent \n Getting Started\n. Using just the SQLite package directly for your project may be a good idea if any of the following are true:\n\n\n\n\nYou have an existing DB with non-standard structure.\n\n\nYou rely heavily on custom or complex SQL queries.\n\n\nYou just plain don't like ORMs.\n\n\n\n\nSQLite core is built on top of \nDatabaseKit\n which provides some conveniences like connection pooling and integrations with Vapor's \nServices\n architecture.\n\n\n\n\nTip\n\n\nEven if you do choose to use \nFluent SQLite\n, all of the features of SQLite core will be available to you.\n\n\n\n\nGetting Started\n\n\nLet's take a look at how you can get started using SQLite core.\n\n\nPackage\n\n\nThe first step to using SQLite core is adding it as a dependency to your project in your SPM package manifest file.\n\n\n// swift-tools-version:4.0\n\n\nimport\n \nPackageDescription\n\n\n\nlet\n \npackage\n \n=\n \nPackage\n(\n\n \nname\n:\n \nMyApp\n,\n\n \ndependencies\n:\n \n[\n\n \n/// Any other dependencies ...\n\n\n \n// \ud83d\udd35 SQLite 3 wrapper for Swift.\n\n \n.\npackage\n(\nurl\n:\n \nhttps://github.com/vapor/sqlite.git\n,\n \nfrom\n:\n \n3.0.0\n),\n\n \n],\n\n \ntargets\n:\n \n[\n\n \n.\ntarget\n(\nname\n:\n \nApp\n,\n \ndependencies\n:\n \n[\nSQLite\n,\n \n...]),\n\n \n.\ntarget\n(\nname\n:\n \nRun\n,\n \ndependencies\n:\n \n[\nApp\n]),\n\n \n.\ntestTarget\n(\nname\n:\n \nAppTests\n,\n \ndependencies\n:\n \n[\nApp\n]),\n\n \n]\n\n\n)\n\n\n\n\n\n\nDon't forget to add the module as a dependency in the \ntargets\n array. Once you have added the dependency, regenerate your Xcode project with the following command:\n\n\nvapor xcode\n\n\n\n\n\nConfig\n\n\nThe next step is to configure the database in \nconfigure.swift\n.\n\n\nimport\n \nSQLite\n\n\n\n/// ...\n\n\n\n/// Register providers first\n\n\ntry\n \nservices\n.\nregister\n(\nSQLiteProvider\n())\n\n\n\n\n\n\nRegistering the provider will add all of the services required for SQLite to work properly. It also includes a default database config struct that uses an in-memory DB.\n\n\nYou can of course override this if you'd like to use a different configuration. SQLite supports in-memory and file-based db persistance.\n\n\n// Configure a SQLite database\n\n\nlet\n \nsqlite\n \n=\n \ntry\n \nSQLiteDatabase\n(\nstorage\n:\n \n.\nfile\n(\npath\n:\n \ndb.sqlite\n))\n\n\n\n/// Register the configured SQLite database to the database config.\n\n\nvar\n \ndatabases\n \n=\n \nDatabasesConfig\n()\n\n\ndatabases\n.\nadd\n(\ndatabase\n:\n \nsqlite\n,\n \nas\n:\n \n.\nsqlite\n)\n\n\nservices\n.\nregister\n(\ndatabases\n)\n\n\n\n\n\n\nSee \nSQLiteDatabase\n and \nSQLiteStorage\n for more information.\n\n\nSQLite's default database identifier is \n.sqlite\n. You can create a custom identifier if you want by extending \nDatabaseIdentifier\n. \n\n\nQuery\n\n\nNow that the database is configured, you can make your first query.\n\n\nstruct\n \nSQLiteVersion\n:\n \nCodable\n \n{\n\n \nlet\n \nversion\n:\n \nString\n\n\n}\n\n\n\nrouter\n.\nget\n(\nsql\n)\n \n{\n \nreq\n \nin\n\n \nreturn\n \nreq\n.\nwithPooledConnection\n(\nto\n:\n \n.\nsqlite\n)\n \n{\n \nconn\n \nin\n\n \nreturn\n \nconn\n.\nselect\n()\n\n \n.\ncolumn\n(\nfunction\n:\n \nsqlite_version\n,\n \nas\n:\n \nversion\n)\n\n \n.\nall\n(\ndecoding\n:\n \nSQLiteVersion\n.\nself\n)\n\n \n}.\nmap\n \n{\n \nrows\n \nin\n\n \nreturn\n \nrows\n[\n0\n].\nversion\n\n \n}\n\n\n}\n\n\n\n\n\n\nVisiting this route should display your SQLite version. \n\n\nHere we are making use database connection pooling. You can learn more about creating connections in \nDatabaseKit \n Getting Started\n.\n\n\nOnce we have a connection, we can use \nselect()\n to create a \nSELECT\n query builder. Learn more about building queries in \nSQL \n Getting Started\n.\n\n\nVisit SQLite's \nAPI docs\n for detailed information about all available types and methods.",
"title": "Getting Started"
},
{
"location": "/sqlite/getting-started/#sqlite",
"text": "SQLite ( vapor/sqlite ) is a wrapper around the libsqlite C-library. Seealso The higher-level, Fluent ORM guide is located at Fluent Getting Started Using just the SQLite package for your project may be a good idea if any of the following are true. You have an existing DB with non-standard structure. You rely heavily on custom or complex SQL queries. You just plain don't like ORMs. SQLite core is built on top of DatabaseKit which provides some conveniences like connection pooling and integrations with Vapor's Services architecture. Tip Even if you do choose to use Fluent SQLite , all of the features of SQLite core will be available to you.",
"text": "SQLite ( vapor/sqlite ) is a wrapper around the libsqlite C-library. The higher-level, Fluent ORM guide is located at Fluent Getting Started . Using just the SQLite package directly for your project may be a good idea if any of the following are true: You have an existing DB with non-standard structure. You rely heavily on custom or complex SQL queries. You just plain don't like ORMs. SQLite core is built on top of DatabaseKit which provides some conveniences like connection pooling and integrations with Vapor's Services architecture. Tip Even if you do choose to use Fluent SQLite , all of the features of SQLite core will be available to you.",
"title": "SQLite"
},
{
@ -2042,12 +2042,12 @@
},
{
"location": "/sqlite/getting-started/#config",
"text": "The next step is to configure the database in configure.swift . SQLite's default database identifier is .sqlite . You can create a custom identifier if you want by extending DatabaseIdentifier . import SQLite /// ... /// Register providers first try services . register ( SQLiteProvider ()) Registering the provider will add all of the services required for SQLite to work properly. It also includes a default database config struct that uses an in-memory DB. You can of course override this if you'd like to use a different configuration. SQLite supports in-memory and file-based db persistance. // Configure a SQLite database let sqlite = try SQLiteDatabase ( storage : . file ( path : db.sqlite )) /// Register the configured SQLite database to the database config. var databases = DatabasesConfig () databases . add ( database : sqlite , as : . sqlite ) services . register ( databases )",
"text": "The next step is to configure the database in configure.swift . import SQLite /// ... /// Register providers first try services . register ( SQLiteProvider ()) Registering the provider will add all of the services required for SQLite to work properly. It also includes a default database config struct that uses an in-memory DB. You can of course override this if you'd like to use a different configuration. SQLite supports in-memory and file-based db persistance. // Configure a SQLite database let sqlite = try SQLiteDatabase ( storage : . file ( path : db.sqlite )) /// Register the configured SQLite database to the database config. var databases = DatabasesConfig () databases . add ( database : sqlite , as : . sqlite ) services . register ( databases ) See SQLiteDatabase and SQLiteStorage for more information. SQLite's default database identifier is .sqlite . You can create a custom identifier if you want by extending DatabaseIdentifier .",
"title": "Config"
},
{
"location": "/sqlite/getting-started/#query",
"text": "Now that the database is configured, you can make your first query. struct SQLiteVersion : Codable { \n let version : String } router . get ( sql ) { req in \n return req . withPooledConnection ( to : . sqlite ) { conn in \n return conn . select () \n . column ( function : sqlite_version , as : version ) \n . all ( decoding : SQLiteVersion . self ) \n }. map { rows in \n return rows [ 0 ]. version \n } } Visiting this route should display your SQLite version. The first step is to create a connection--here we are making use of database connection pooling. You can learn more about creating connections in DatabaseKit Getting Started . Once we have a connection, we can use select() to create a SELECT query builder. Learn more about building queries in SQL Getting Started .",
"text": "Now that the database is configured, you can make your first query. struct SQLiteVersion : Codable { \n let version : String } router . get ( sql ) { req in \n return req . withPooledConnection ( to : . sqlite ) { conn in \n return conn . select () \n . column ( function : sqlite_version , as : version ) \n . all ( decoding : SQLiteVersion . self ) \n }. map { rows in \n return rows [ 0 ]. version \n } } Visiting this route should display your SQLite version. Here we are making use database connection pooling. You can learn more about creating connections in DatabaseKit Getting Started . Once we have a connection, we can use select() to create a SELECT query builder. Learn more about building queries in SQL Getting Started . Visit SQLite's API docs for detailed information about all available types and methods.",
"title": "Query"
},
{

View File

@ -1980,17 +1980,13 @@
<h1 id="sqlite">SQLite<a class="headerlink" href="#sqlite" title="Permanent link">&para;</a></h1>
<p>SQLite (<a href="https://github.com/vapor/sqlite">vapor/sqlite</a>) is a wrapper around the <code>libsqlite</code> C-library.</p>
<div class="admonition seealso">
<p class="admonition-title">Seealso</p>
<p>The higher-level, Fluent ORM guide is located at <a href="../../fluent/getting-started/">Fluent &rarr; Getting Started</a></p>
</div>
<p>Using just the SQLite package for your project may be a good idea if any of the following are true.</p>
<p>The higher-level, Fluent ORM guide is located at <a href="../../fluent/getting-started/">Fluent &rarr; Getting Started</a>. Using just the SQLite package directly for your project may be a good idea if any of the following are true:</p>
<ul>
<li>You have an existing DB with non-standard structure.</li>
<li>You rely heavily on custom or complex SQL queries.</li>
<li>You just plain don't like ORMs.</li>
</ul>
<p>SQLite core is built on top of DatabaseKit which provides some conveniences like connection pooling and integrations with Vapor's <a href="../../getting-started/services/">Services</a> architecture.</p>
<p>SQLite core is built on top of <a href="../../database-kit/getting-started/">DatabaseKit</a> which provides some conveniences like connection pooling and integrations with Vapor's <a href="../../getting-started/services/">Services</a> architecture.</p>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>Even if you do choose to use <a href="../../fluent/getting-started/">Fluent SQLite</a>, all of the features of SQLite core will be available to you.</p>
@ -2025,7 +2021,7 @@
<h3 id="config">Config<a class="headerlink" href="#config" title="Permanent link">&para;</a></h3>
<p>The next step is to configure the database in <a href="../../getting-started/structure/#configureswift"><code>configure.swift</code></a>. SQLite's default database identifier is <code>.sqlite</code>. You can create a custom identifier if you want by extending <a href="#fixme"><code>DatabaseIdentifier</code></a>. </p>
<p>The next step is to configure the database in <a href="../../getting-started/structure/#configureswift"><code>configure.swift</code></a>.</p>
<div class="codehilite"><pre><span></span><span class="kd">import</span> <span class="nc">SQLite</span>
<span class="c1">/// ...</span>
@ -2036,7 +2032,7 @@
<p>Registering the provider will add all of the services required for SQLite to work properly. It also includes a default database config struct that uses an in-memory DB.</p>
<p>You can of course override this if you'd like to use a different configuration. SQLite supports in-memory and file-based db persistance. </p>
<p>You can of course override this if you'd like to use a different configuration. SQLite supports in-memory and file-based db persistance.</p>
<div class="codehilite"><pre><span></span><span class="c1">// Configure a SQLite database</span>
<span class="kd">let</span> <span class="nv">sqlite</span> <span class="p">=</span> <span class="k">try</span> <span class="n">SQLiteDatabase</span><span class="p">(</span><span class="n">storage</span><span class="p">:</span> <span class="p">.</span><span class="n">file</span><span class="p">(</span><span class="n">path</span><span class="p">:</span> <span class="s">&quot;db.sqlite&quot;</span><span class="p">))</span>
@ -2047,6 +2043,8 @@
</pre></div>
<p>See <a href="https://api.vapor.codes/sqlite/latest/SQLite/Classes/SQLiteDatabase.html"><code>SQLiteDatabase</code></a> and <a href="https://api.vapor.codes/sqlite/latest/SQLite/Enums/SQLiteStorage.html"><code>SQLiteStorage</code></a> for more information.</p>
<p>SQLite's default database identifier is <code>.sqlite</code>. You can create a custom identifier if you want by extending <a href="https://api.vapor.codes/database-kit/latest/DatabaseKit/Structs/DatabaseIdentifier.html"><code>DatabaseIdentifier</code></a>. </p>
<h3 id="query">Query<a class="headerlink" href="#query" title="Permanent link">&para;</a></h3>
<p>Now that the database is configured, you can make your first query.</p>
<div class="codehilite"><pre><span></span><span class="kd">struct</span> <span class="nc">SQLiteVersion</span><span class="p">:</span> <span class="n">Codable</span> <span class="p">{</span>
@ -2066,8 +2064,9 @@
<p>Visiting this route should display your SQLite version. </p>
<p>The first step is to create a connection--here we are making use of database connection pooling. You can learn more about creating connections in <a href="../../database-kit/getting-started/">DatabaseKit &rarr; Getting Started</a>.</p>
<p>Once we have a connection, we can use <a href="#fixme"><code>select()</code></a> to create a <code>SELECT</code> query builder. Learn more about building queries in <a href="../../sql/getting-started/">SQL &rarr; Getting Started</a>.</p>
<p>Here we are making use database connection pooling. You can learn more about creating connections in <a href="../../database-kit/getting-started/">DatabaseKit &rarr; Getting Started</a>.</p>
<p>Once we have a connection, we can use <a href="https://api.vapor.codes/sql/latest/SQL/Protocols/SQLConnection.html#/s:3SQL13SQLConnectionPAAE6selectAA16SQLSelectBuilderCyxGyF"><code>select()</code></a> to create a <code>SELECT</code> query builder. Learn more about building queries in <a href="../../sql/getting-started/">SQL &rarr; Getting Started</a>.</p>
<p>Visit SQLite's <a href="https://api.vapor.codes/sqlite/latest/SQLite/index.html">API docs</a> for detailed information about all available types and methods.</p>