New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pgsql-deparser

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pgsql-deparser - npm Package Compare versions

Comparing version 13.13.0 to 13.14.0

6

package.json
{
"name": "pgsql-deparser",
"version": "13.13.0",
"version": "13.14.0",
"description": "PostgreSQL AST Deparser",

@@ -77,3 +77,3 @@ "author": "Dan Lynch <pyramation@gmail.com>",

"jest": "^29.7.0",
"pgsql-parser": "^13.14.0",
"pgsql-parser": "^13.15.0",
"prettier": "^2.8.7",

@@ -90,3 +90,3 @@ "rimraf": "5.0.5",

},
"gitHead": "453a53729df906c6eb5a095dc0fa985babab4d51"
"gitHead": "1358b34422c45c2111dc0b1764155a720ab7fd73"
}

@@ -33,15 +33,32 @@ # pgsql-deparser

The deparser functionality is provided as a standalone module, enabling you to serialize AST (Abstract Syntax Tree) objects back to SQL statements without the need for the full parsing engine. This separation is particularly beneficial for environments where the native dependencies of the full parser are problematic or unnecessary. For instance, if you already have an AST representation of your SQL query and merely need to convert it back to a SQL string, you can use the pgsql-deparser module directly. This module is implemented in pure TypeScript, avoiding the need for native bindings and thereby simplifying deployment and compatibility across different environments.
The `pgsql-deparser` module serializes ASTs to SQL in pure TypeScript, avoiding the full parser's native dependencies. It's useful when only SQL string conversion from ASTs is needed, and is written in pure TypeScript for easy cross-environment deployment.
Here's how you can use the deparser in your TypeScript code:
Here's how you can use the deparser in your TypeScript code, using [`@pgsql/utils`](https://github.com/launchql/pgsql-parser/tree/main/packages/utils) to create an AST for `deparse`:
```ts
import ast, { SelectStmt } from '@pgsql/utils';
import { deparse } from 'pgsql-deparser';
// Assuming `stmts` is an AST object for the query 'SELECT * FROM test_table'
// This could have been obtained from any source, not necessarily the pgsql-parser
const stmts = getAstFromSomewhere();
// This could have been obtained from any JSON or AST, not necessarily @pgsql/utils
const stmt: SelectStmt = ast.selectStmt({
targetList: [
ast.resTarget({
val: ast.columnRef({
fields: [ast.aStar()]
})
})
],
fromClause: [
ast.rangeVar({
relname: 'some_table',
inh: true,
relpersistence: 'p'
})
],
limitOption: 'LIMIT_OPTION_DEFAULT',
op: 'SETOP_NONE'
});
// Modify the AST as needed
stmts[0].RawStmt.stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table';
// Modify the AST if needed
stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table';

@@ -51,4 +68,3 @@ // Deparse the modified AST back to a SQL string

// Output: SELECT * FROM "another_table"
// Output: SELECT * FROM another_table
```

@@ -55,0 +71,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc