Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jul 24, 2019
1 parent 85039b4 commit fd36c42
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions typescript/README.MD
Expand Up @@ -11,13 +11,9 @@ Typescript should be able to pick up the definitions without any manual configur
```ts
import * as pgPromise from 'pg-promise';

const pgp = pgPromise({
// Initialization Options
});
const pgp = pgPromise({/* Initialization Options */});

const cn = 'postgres://username:password@host:port/database';

const db = pgp(cn);
const db = pgp('postgres://username:password@host:port/database');
```

#### With Extensions
Expand All @@ -26,7 +22,6 @@ The library supports dynamic protocol extensions, via event [extend], which requ
explicit extension interface to be declared, and parameterized as shown below.

```ts
import {IInitOptions} from 'pg-promise';
import * as pgPromise from 'pg-promise';

// your protocol extensions:
Expand All @@ -35,27 +30,25 @@ interface IExtensions {
}

// pg-promise initialization options:
const options: IInitOptions<IExtensions> = {
const options = {
extend(obj) {
obj.findUser = userId => {
return obj.one('SELECT * FROM Users WHERE id = $1', userId);
}
}
};

const cn = 'postgres://username:password@host:port/database';

// initializing the library:
const pgp = pgPromise(options);

// database object with extensions:
const db = pgp<IExtensions>(cn);
const db = pgp<IExtensions>('postgres://username:password@host:port/database');

// now you can use the extensions everywhere (including tasks and transactions):
db.findUser(123).then(...);
```

For a more complete example, check out [pg-promise-demo].
For a complete and comprehensive example, check out [pg-promise-demo].

[pg-promise-demo]:https://github.com/vitaly-t/pg-promise-demo
[extend]:http://vitaly-t.github.io/pg-promise/global.html#event:extend
Expand Down

0 comments on commit fd36c42

Please sign in to comment.