pokemon-showdown/test/lib/postgres.js
Guangcong Luo 78439b4a02
Update to ESLint 9 (#10926)
ESLint has a whole new config format, so I figure it's a good time to
make the config system saner.

- First, we no longer have separate eslint-no-types configs. Lint
  performance shouldn't be enough of a problem to justify the
  relevant maintenance complexity.

- Second, our base config should work out-of-the-box now. `npx eslint`
  will work as expected, without any CLI flags. You should still use
  `npm run lint` which adds the `--cached` flag for performance.

- Third, whatever updates I did fixed style linting, which apparently
  has been bugged for quite some time, considering all the obvious
  mixed-tabs-and-spaces issues I found in the upgrade.

Also here are some changes to our style rules. In particular:

- Curly brackets (for objects etc) now have spaces inside them. Sorry
  for the huge change. ESLint doesn't support our old style, and most
  projects use Prettier style, so we might as well match them in this way.
  See https://github.com/eslint-stylistic/eslint-stylistic/issues/415

- String + number concatenation is no longer allowed. We now
  consistently use template strings for this.
2025-02-25 20:03:46 -08:00

48 lines
1.4 KiB
JavaScript

"use strict";
const assert = require('assert').strict;
const { PostgresDatabase } = require('../../dist/lib');
function testMod(mod) {
try {
require(mod);
} catch {
return it.skip;
}
return it;
}
// only run these if you already have postgres configured
describe.skip("Postgres features", () => {
it("Should be able to connect to a database", async () => {
this.database = new PostgresDatabase();
});
it("Should be able to insert data", async () => {
await assert.doesNotThrowAsync(async () => {
await this.database.query(`CREATE TABLE test (col TEXT, col2 TEXT)`);
await this.database.query(
`INSERT INTO test (col, col2) VALUES ($1, $2)`,
['foo', 'bar']
);
});
});
testMod('sql-template-strings')('Should support sql-template-strings', async () => {
await assert.doesNotThrowAsync(async () => {
const SQL = require('sql-template-strings');
await this.database.query(SQL`INSERT INTO test (col1, col2) VALUES (${'a'}, ${'b'})`);
});
});
it("Should be able to run multiple statements in transaction", async () => {
await assert.doesNotThrowAsync(async () => {
await this.database.transaction(async worker => {
const tables = await worker.query(
`SELECT tablename FROM pg_catalog.pg_tables ` +
`WHERE tablename = 'test' LIMIT 1;`
);
for (const { tablename } of tables) {
await worker.query(`DROP TABLE ` + tablename);
}
});
});
});
});