Skip to content

Commit

Permalink
docs: refactor misc migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoepics committed Apr 28, 2024
1 parent 4abf80b commit cc09e0e
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions docs/src/migrations/misc.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
# Miscellaneous Operations

### `pgm.sql( sql )`
## Operation `pgm.sql`

> Run raw sql -- with some optional _[very basic](http://mir.aculo.us/2011/03/09/little-helpers-a-tweet-sized-javascript-templating-engine/)_ mustache templating
#### `pgm.sql( sql )`

**Arguments:**
> [!IMPORTANT]
> Run raw sql—with some optional
> _[very basic](http://mir.aculo.us/2011/03/09/little-helpers-a-tweet-sized-javascript-templating-engine/)_ mustache templating
- `sql` _[string]_ - SQL query to run
- `args` _[object]_ - (optional) key/val of arguments to replace
### Arguments

---
| Name | Type | Description |
|--------|----------|--------------------------------------------------------------------------|
| `sql` | `string` | SQL query to run |
| `args` | `object` | (optional) key/val of arguments to replace in the SQL query (templating) |

### `pgm.func( sql )`

> Inserts raw string, which is not escaped

e.g. `pgm.func('CURRENT_TIMESTAMP')` to use in `default` option for column definition
## Operation `pgm.func`

#### `pgm.func( sql )`

**Arguments:**
> [!IMPORTANT]
> Inserts raw string, which is not escaped
> e.g. `pgm.func('CURRENT_TIMESTAMP')` to use in `default` option for column definition
- `sql` _[string]_ - string to not be escaped
### Arguments

---
| Name | Type | Description |
|--------|----------|--------------------------|
| `sql` | `string` | String to not be escaped |

### `pgm.db.query` and `pgm.db.select`
## Operation `pgm.db`

> Allows to run DB queries with same DB connection migration is running
#### `pgm.db.query` and `pgm.db.select`

> [!IMPORTANT]
> Allows running DB queries with the same DB connection migration is running
> See [pg.Client.query](https://node-postgres.com/api/client#client-query)
Returns promise with either result of query or returned rows of query (in case of `select`).
Returns promise with either result of query or returned rows of a query (in case of `select`).


---
## Operation `pgm.noTransaction`

### `pgm.noTransaction`
#### `pgm.noTransaction`

By default, all migrations are run in one transaction, but some DB operations like add type value (`pgm.addTypeValue`)
does not work if the type is not created in the same transaction. E.g. if it is created in previous migration. You need to
run specific migration outside a transaction (`pgm.noTransaction`). Be aware that this means that you can have
does not work if the type is not created in the same transaction.
E.g., if it is created in previous migration.
You need to run specific migration outside a transaction (`pgm.noTransaction`).
Be aware that this means that you can have
some migrations applied and some not applied, if there is some error during migrating (leading to `ROLLBACK`)

0 comments on commit cc09e0e

Please sign in to comment.