Data Source
Every model needs to include exactly one datasource
declaration, providing information on how to connect to the underlying database.
Syntax​
datasource NAME {
provider = PROVIDER
url = DB_URL
}
-
NAME:
Name of the data source. Must be a valid identifier. Name is only informational and serves no other purposes.
-
provider
:Name of database connector. Valid values:
- sqlite
- postgresql
-
url
:Database connection string. Either a plain string or an invocation of
env
function to fetch from an environment variable. For SQLite provider, the URL should be a file protocol, likefile:./dev.db
. For PostgreSQL provider, it should be a postgres connection string, likepostgresql://user:password@localhost:5432/dbname
.The
url
option is only used by the migration engine to connect to the database. The ORM runtime doesn't rely on it. Instead, you provide the connection information when constructing an ORM client.
Example​
datasource db {
provider = 'postgresql'
url = env('DATABASE_URL')
}
datasource db {
provider = 'sqlite'
url = 'file:./dev.db'
}