From 33ba36c3bf6299b71e7ef2dbda89f82ffed165f7 Mon Sep 17 00:00:00 2001 From: flodlc Date: Fri, 17 Mar 2023 00:53:31 +0100 Subject: [PATCH] improved doc --- README.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7b97548..4c4ee70 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ - Fully written in TypeScript
-## Installation +## Getting Started ```sh npm install pg-mate @@ -17,10 +17,60 @@ npm install pg-mate yarn add pg-mate ``` -Then +Next, create a `pg-mate.(js|ts)` file at the root of your project as follows:: -```sh -npx pg-mate init +```typescript +import { pgMate, PgMateConfig } from "../dist/index"; +import { migrations } from "./migrations/index"; + +export const config: PgMateConfig = { + connexionUrl: "postgresql://postgres:password@localhost:5432/postgres", + migrationImports: migrations, + migrationDir: "migrations", + esm: false, + ts: true, +}; + +pgMate.initCli(config); +``` + +> Note that `pgMate.initCli(config);` enables the use of this file as a CLI + +## Config + +Here is the Config definition with default values: + +```typescript +type PgMateConfig = { + /** + * Exemple: "postgresql://postgres:password@localhost:5432/postgres" + */ + connexionUrl: string; + /** + * Allows injecting a custom db client in migration functions. + * Default: native pg driver + * Exemple: () => knexClient + */ + getClient?: () => Promise; + /** + * Default: "migrations" + */ + migrationDir?: string; + /** + * Must be the migrations import (required) + */ + migrationImports: MigrationFiles; + /** + * If type: "module" in package.json => true + * Default: false + */ + esm?: boolean; + /** + * Used to use the correction extension in migrations directory. + * Default: false + */ + ts?: boolean; +}; ``` ## Usage @@ -92,8 +142,4 @@ node pg-mate.js --refreshIndex ts-node pg-mate.ts --refreshIndex ``` -### Basic - -... - That's it! You can now use pg-mate to manage your Postgresql database migrations.