Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #935

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ $ npm install postgres
```

### Usage
There are two ways of importing the library in your code; either in ECMAScript or CommonJS module system

Create your `sql` database instance

##### ECMAScript
```js
// db.js
import postgres from 'postgres'
Expand All @@ -30,11 +34,19 @@ const sql = postgres({ /* options */ }) // will use psql environment variables

export default sql
```
##### CommonJS
```js
const postgres = require('postgres')

const sql = postgres({ /* options */ }) // will use psql environment variables
module.exports = sql
Copy link
Author

@elhananjair elhananjair Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed export syntax for CommonJS

```

Simply import for use elsewhere
```js
// users.js
import sql from './db.js'
// const sql = require('./db.js')
import sql from './db.js'

async function getUsersOver(age) {
const users = await sql`
Expand Down