The SQLite configuration automatically enables foreign key constraints on all created connections, but does not alter foreign key configurations in the database itself. If you use an in-memory database, make sure to set Fluent to migrate automatically using -auto-migrate or run app.autoMigrate() after adding migrations. You can also configure SQLite to store the database ephemerally in memory. import FluentĪpp.e(.sqlite(.file("db.sqlite")), as. Once the dependencies are added, configure the database with Fluent using in configure.swift. product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver") To use SQLite, add the following dependencies to your package.package(url: "", from: "4.0.0") Its simplistic nature makes it a great candidate for prototyping and testing. SQLite is an open source, embedded SQL database. You can also parse the credentials from a database connection string. import FluentĪpp.e(.postgres(hostname: "localhost", username: "vapor", password: "vapor", database: "vapor"), as. Once the dependencies are added, configure the database's credentials with Fluent using in configure.swift. product(name: "FluentPostgresDriver", package: "fluent-postgres-driver") To use PostgreSQL, add the following dependencies to your package.package(url: "", from: "2.0.0") This is Fluent's recommended database driver. It is easily configurable on most cloud hosting providers. PostgreSQL is an open source, standards compliant SQL database. You can search GitHub for the tag fluent-driver for a full list of official and third-party Fluent database drivers. Drivers ¶įluent currently has four officially supported drivers. import FluentĮach of the Fluent drivers below has more specific instructions for configuration. Once the packages are added as dependencies, you can configure your databases using app.databases in configure.swift. product(name: "Vapor", package: "vapor"), product(name: "FluentDriver", package: "fluent-driver"), product(name: "Fluent", package: "fluent"), One (or more) Fluent driver(s) of your choice.If you have an existing project that you want to add Fluent to, you will need to add two dependencies to your package: This will automatically add the dependencies to your new project as well as example configuration code. When creating a project using vapor new, answer "yes" to including Fluent and choose which database driver you want to use. These models are then used to perform create, read, update, and delete operations instead of writing raw queries. Using Fluent centers around the creation of model types which represent data structures in your database. It takes advantage of Swift's strong type system to provide an easy-to-use interface for your database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |