Skip to content

Latest commit

History

History
194 lines (128 loc) 路 6.77 KB

CHANGELOG.md

File metadata and controls

194 lines (128 loc) 路 6.77 KB

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

[3.0.0] - 2023-09-16

Changed

  • Added an exports section to package.json, so you can no longer import internal Possu modules ( e.g. import SqlQuery from "possu/dist/SqlQuery"). Technically, this should not be a breaking change, since the internal functions are not a part of the public API.

[2.0.0] - 2023-08-01

Added

Changed

  • Drop support for Node 14.x

[1.0.0] - 2022-09-22

Added

Changed

  • Drop support for Node 12.x

[0.12.0] - 2022-03-30

Changed

  • Bump the minimum required version of pg and @types/pg to 8.6.0.
  • Change sql`...`.prepare('query-name') to return a new copy of the query instead of mutating it.
  • Bump minimum Node.js version to 12.x
  • Change the signature of the shouldRetry option of withTransaction from (error: Error) => boolean to (error: unknown) => boolean. This matches the default error type of catch clauses in TypeScript 4.4.
  • Catch any errors emitted by the client in withTransaction. A pg.Client is an EventEmitter, which will crash the Node.js process if it emits an error an if there are no error listeners. Possu will now automatically install an error handler that catches any errors emitted by the client during the transaction. Any errors are returned in the promise.

[0.11.0] - 2021-04-10

Added

  • Added an sql`...`.prepare('query-name') method for creating prepared statements. This can sometimes have measurable performance benefits, especially if the query is very complex to parse and plan.
  • Added a Connection type alias for pg.Pool | pg.PoolClient. It is designed to be used in your query functions as a generic connection type.
import { Connection, query, sql } from 'possu'

export function getUsers(conn: Connection) {
  return query(conn, sql`SELECT * FROM users`)
}
  • Added Transaction type. It is just a regular pg.PoolClient with a type-level brand, which indicates that the connection has an active transaction. It can be used as additional type safety in functions that must be called within a transaction.
import { Transaction, query, sql } from 'possu'

export async function insertTwoUsers(tx: Transaction) {
  await execute(tx, sql`INSERT INTO users (name) VALUES ('Alice')`)
  await execute(tx, sql`INSERT INTO users (name) VALUES ('Bob')`)
}

Changed

  • Changed withTransaction to only take a connection pool as the first argument.
  • Changed withSavePoint to take a Transaction as the first parameter.

[0.10.0] - 2021-03-31

Changed

  • Improve the error message of queryMaybeOne in cases where the query returns an unexpected amount of rows.
  • Make private properties of SqlQuery non-enumerable
  • Improve documentation

Removed

  • Removed sql.values. The existing implementation suffered from problems with the ordering of object keys. In most cases, the use of VALUES lists may be replaced with functions like jsonb_to_recordset, so I'm removing sql.values for now. If it proves to be useful in the future, it may come back in some form.

[0.9.0] - 2021-01-26

Added

  • Added a new sql.values query builder for creating VALUES lists. Useful as a data source to INSERT queries or when writing complex subqueries.

[0.8.0] - 2020-11-04

Added

  • Added automatic transaction retrying in withTransaction for PostgreSQL's 40001 (serialization failure) and 40P01 (deadlock detected) error codes.
  • Added an optional options object to withTransaction, which can be used to configure the access mode, isolation level and retry logic of a transaction.
  • The set of queries in withSavepoint now receives a PoolClient as an argument. With the change, one may supply the same function to both withTransaction and withSavepoint.

Removed

  • withTransactionMode and withTransactionLevel have been removed, since withTransaction now encompasses their functionality.

[0.7.0] - 2020-10-22

Changed

  • Documentation improvements

[0.6.0] - 2020-10-21

Added

  • Added a withSavepoint function for creating savepoints. Savepoints can be used to simulate nested transactions.

[0.5.0] - 2020-10-19

Added

  • Added a sql.json function for serializing values as JSON in queries. Strictly speaking, this isn't necessary, since it is mostly just equivalent to JSON.stringify, but I'm including it since it might be more readable.
  • Added an optional row parser parameter to query, queryOne and queryMaybeOne.

Changed

  • Changed the default type variable in query, queryOne and queryMaybeOne from any to unknown. Now the user must explicitly cast the result rows to another type or to use a validating row parser.

[0.4.0] - 2020-10-09

Fixed

  • Fixed the files and types entries in package.json. With them, the project should actually be usable 馃檪.

[0.3.0] - 2020-10-09

Changed

  • Changed withTransactionLevel and withTransactionMode to take the isolation level and access mode as the first argument. This allows the user to fix them more easily with e.g. Function.prototype.bind.
  • Replaced TooManyRowsReturnedError and NoRowsReturnedError with a generic ResultError, which signifies that a query returned an unexpected result.

[0.2.0] - 2020-10-08

Added

Changed

[0.1.0] - 2020-10-07

  • Initial public release