Back to Sails

Available database adapters

docs/concepts/extending-sails/Adapters/adapterList.md

12.12.200013.9 KB
Original Source

Available database adapters

This page is meant to be an up-to-date, comprehensive list of all of the core adapters available for the Sails.js framework, and a reference of a few of the most robust community adapters out there.

All supported adapters can be configured in roughly the same way: by passing in a Sails/Waterline adapter (adapter), as well as a connection URL (url). For more information on configuring datastores, see sails.config.datastores.

Having trouble connecting? Be sure to check your connection URL for typos. If that doesn't work, review the documentation for your database provider, or get help.

Officially-supported database adapters

The following core adapters are maintained, tested, and used by the Sails.js core team.

Want to help out with a core adapter? Get started by reading the Sails project contribution guide.

Database technologyAdapterConnection URL structureFor production?
MySQLrequire('sails-mysql')mysql://user:password@host:port/databaseYes
PostgreSQLrequire('sails-postgresql')postgresql://user:password@host:port/databaseYes
MongoDBrequire('sails-mongo')mongodb://user:password@host:port/databaseYes
Local disk / memory(built-in, see sails-disk)n/aNo!

sails-mysql

MySQL is the world's most popular relational database.

 

bash
npm install sails-mysql --save
javascript
adapter: 'sails-mysql',
url: 'mysql://user:password@host:port/database',
  • The default port for MySQL is 3306.
  • If you plan on saving special characters—like emojis—in your data, you may need to set the charset configuration option for your datastore. To allow emojis, use charset: 'utf8mb4'. You may use the columnType setting in a model attribute to set the character set.
  • For relational database servers like MySQL and PostgreSQL, you may have to create a "database" first using a free tool like SequelPro or in the MySQL REPL on the command-line (if you're an experience SQL user). It's customary to make a database specifically for your app to use.
  • The sails-mysql adapter is also 100% compatible with Amazon Aurora databases.
Handshake inactivity timeout errors

If you find yourself encountering a "Handshake inactivity timeout" error when your Sails app interacts with MySQL, you can increase the timeout using the connectTimeout option. This is usually only necessary when queries are running side-by-side with computationally expensive operations (for example, compiling client-side typescript files or running webpack during development).

For example, you might extend the timeout to 20 seconds:

javascript
adapter: 'sails-mysql',
url: 'mysql://user:password@host:port/database',
connectTimeout: 20000

sails-postgresql

PostgreSQL is a modern relational database with powerful features.

 

bash
npm install sails-postgresql --save
javascript
adapter: 'sails-postgresql',
url: 'postgresql://user:password@host:port/database',
  • The default port for PostgreSQL is 5432.
  • In addition to adapter and url, you might also need to set ssl: true. This depends on where your PostgreSQL database server is hosted. For example, ssl: true is required when connecting to Heroku's hosted PostgreSQL service.
  • Note that in pg version 8.0, the syntax was updated to ssl: { rejectUnauthorized: false }.
  • Compatible with most versions of Postgres. See this issue to learn more about compatability with Postgres >12

sails-mongo

MongoDB is the leading NoSQL database.

 

bash
npm install sails-mongo --save
javascript
adapter: 'sails-mongo',
url: 'mongodb://user:password@host:port/database',
  • The default port for MongoDB is 27017.
  • If your Mongo deployment keeps track of its internal credentials in a separate database, then you may need to name that database by tacking on ?authSource=theotherdb to the end of the connection URL.
  • Other Mongo configuration settings provided via querystring in the connection URL are passed through to the underlying Mongo driver.

sails-disk

Write to your computer's hard disk, or a mounted network drive. Not suitable for at-scale production deployments, but great for a small project, and essential for developing in environments where you may not always have a database set up. This adapter is bundled with Sails and works out of the box with zero configuration.

You can also operate sails-disk in memory-only mode. See the settings table below for details.

 

Available out of the box in every Sails app.

Configured as the default database, by default.

Optional datastore settings for sails-disk
SettingDescriptionTypeDefault
dirThe directory to place database files in. The adapter creates one file per model.((string)).tmp/localDiskDb
inMemoryOnlyIf true, no database files will be written to disk. Instead, all data will be stored in memory (and will be lost when the app stops running).((boolean))false
  • You can configure the default sails-disk adapter by adding settings to the default datastore in config/datastores.js.

Community-supported database adapters

Is your database not supported by one of the core adapters? Good news! There are many different community database adapters for Sails.js and Waterline available on NPM.

Here are a few highlights:

Database technologyAdapterMaintainerInterfaces implementedStable release
Redissails-redisRyan Clough / Solnet SolutionsSemantic, Queryable
MS SQL Serversails-MSSQLservermisterGFSemantic, Queryable
OrientDBsails-orientDBappscotSemantic, Queryable, Associations, Migratable
Oraclesails-oracleDBatiertantSemantic, Queryable
Oracle (AnyPresence)waterline-oracle-adapterAnyPresenceSemantic, Queryable
Oracle (stored procedures)sails-oracle-SPButo and nethonchoSemantic, Queryable
SAP HANA DBsails-HANAEnrico BattistellaSemantic, Queryable
SAP HANA (AnyPresence)waterline-SAP-HANA-adapterAnyPresenceSemantic, Queryable
IBM DB2sails-DB2ibuildings Italia & Vincenzo FerrariSemantic, Queryable
ServiceNow SOAPwaterline-ServiceNow-SOAPSungard Availability ServicesSemantic, Queryable
Cassandrasails-cassandradtoubelisSemantic, Migratable, Iterable
Solrsails-solrsajovSemantic, Migratable, Queryable
FileMaker Databasesails-FileMakerGeist InteractiveSemantic
Apache Derbysails-derbydash-Semantic, Queryable, Associations, SQL
REST API (Generic)sails-RESTzohararadSemantic
Add your custom adapter to this list

If you see out of date information on this page, or if you want to add an adapter you made, please submit a pull request to this file updating the table of community adapters above.

Note that, to be listed on this page, an adapter must:

  1. Be free and open source (libre and gratis), preferably under the MIT license.
  2. Pass all of the Waterline adapter tests for the interface layers declared in its package.json file.
  3. Support configuration via a connection URL, as url (if applicable).

If you find that any of these conventions are not true for any of the community adapters above (i.e. for latest stable release published on NPM, not for the code on GitHub), then please reach out to the maintainer of the adapter. If you can't reach them or need further assistance, then please get in touch with a member of the Sails core team.

<docmeta name="displayName" value="Available adapters">