Postgres storage adapter for boardgame.io library
npm install bgio-postgresbgio-postgres - PostgreSQL storage adapter for boardgame.ioYou can use the PostgresStore in two ways.
Either provide credentials using a URI as the first argument, or by using an options object.
``typescript
import { Server } from "boardgame.io/server";
import { PostgresStore } from "bgio-postgres";
// EITHER provide a URI
const db = new PostgresStore("postgresql://
// OR provide options
const db = new PostgresStore({
database: "database",
username: "username",
password: "password",
host: "host",
});
const server = Server({
games: [...],
db,
});
`
This adapter uses [Sequelize][sequelize] as the ORM. Any additional options provided to PostgresStore will be passed to the initialization arguments of the underlying Sequelize instance.
`typescript
// EITHER provide options after the URI...
const db = new PostgresStore(
"postgresql://
{
logging: myLogger,
timezone: '+00:00',
}
);
// ...OR provide addition options with the credentials.
const db = new PostgresStore({
database: "database",
username: "username",
password: "password",
host: "host",
logging: myLogger,
timezone: '+00:00',
});
`
The full list of available options is documented in the [Sequelize API Docs][class-sequelize].
[sequelize]: https://sequelize.org/master/
[class-sequelize]: https://sequelize.readthedocs.io/en/latest/api/sequelize/#class-sequelize
In order to use this adapter with another database, first install a node client for that database as a dependency (for example, npm install mysql2 for mysql).
Second, either provide credentials using a URI as the first argument:
`typescript`
const db = new PostgresStore("mysql://
or by using an options object. In this case, the option dialect: " _must be included_.
`typescript``
const db = new PostgresStore({
database: "database",
username: "username",
password: "password",
host: "host",
dialect: "mysql",
});