ts-slonik-live-server-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.1.12 • Public • Published

ts-slonik-live-server-plugin

Typescript language server plugin for slonik.

This plugin tests slonik sql template tag queries, suggests table & column names and checks it's cost against a live database.

Installation

yarn add -D ts-slonik-live-server-plugin

or

npm i -D ts-slonik-live-server-plugin

Settings

Add to plugins section in tsconfig.json:

{
  "compilerOptions": {
    ...
    "plugins": [
      {
        "name": "ts-slonik-live-server-plugin",
        "dotEnv": "../.env",
        "pg": {
          "uri": "postgresql://localhost/postgres",
          "defaultSchema": "public",
          "infoTtl": 5000,
          "include": {
            "schema": ["public", "users"],
            "table": ["schema1.table1"]
          },
          "exclude": {
            "table": ["schema1.table1"]
          }
        },
        "cost": {
          "info": true,
          "threshold": {
            "error": 100,
            "warning": 50
          }
        }
      }
    ]
  }
}

VS Code

https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin#testing-locally

Note: If you're using Visual Studio Code, you'll have to use the first approach above, with a path to the module, or run the "TypeScript: Select TypeScript Version" command and choose "Use Workspace > Version", or click the version number between "TypeScript" and 😃 in the lower-right corner. Otherwise, VS Code will not be able to find your plugin.

Postgres connection

Connection settings can be defined by following options:

pg.uri

If pg.uri is set under plugin setting in tsconfig.json, any .env configuration will be ignored.

.env

The plugin will by default look for .env file in project root. If the file is located elsewhere (e.g. monorepo), you can add it's relative path to the project root with dotEnv setting.

You can use node-postgres environment variables in .env file, or you can define Postgres connection URI with PGURI environment variable. If PGURI is defined, any node-postgres environment variables will be ignored.

Schemas and tables

By default, any tables in public schema will be tested against. You can override this preset with include and exclude rules.

pg.defaultSchema

Default: public

If your default schema is other than public, add it's name to defaultSchema option.

pg.infoTtl

Default: 5000

TTL (in milliseconds) of DB information. The DB information (a.k.a. Database schema in broader RDBMS terminolgy) will be only refetched after the TTL have surpassed from last load time.

pg.include

pg.include.schema

Default: ["public"]

You can override default schema with this setting. Be adviced that default schema will not be added automatically.

pg.include.table

Default: []

If you wish to add tables which are not under any schemas in pg.include.schema setting, you can add them with pg.include.table setting.

If table is in schema other than the default schema, define the table name as schemaName.tableName (without double quotes).

pg.exclude

pg.exclude.table

Default: []

Just like pg.include.table, you can define any tables that you wish to explicitly omit to test against.

Cost

Cost is evaluated by explain query.

cost.info

Default: true

If set to true, all query costs will be advised via code suggestion.

cost.threshold.error

Default: 100

Any cost over this value will be code error.

cost.threshold.warning

Default: 50

Any cost over this value will be code warning.

Notes

This project was inspired by ts-sql-plugin

Package Sidebar

Install

npm i ts-slonik-live-server-plugin

Weekly Downloads

28

Version

1.1.12

License

MIT

Unpacked Size

303 kB

Total Files

114

Last publish

Collaborators

  • hoonoh