Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
fastify-atdatabase-pg
Advanced tools
This module provides a way to connect to PostgreSQL database using @databases/pg
npm i fastify-atdatabase-pg
Add it to you project with register
and you are done!
const fastify = require('fastify')()
fastify.register(require('fastify-atdatabase-pg'), {
connectionString: 'postgres://postgres:postgres@localhost:5432/postgres',
bigIntMode: 'string'
})
fastify.get('/', async (req, reply) => {
const result = await fastify.pg.db.query(fastify.pg.sql`SELECT NOW()`)
return reply.send(result)
})
fastify.listen({ port: 3000 }, err => {
if (err) throw err
})
You can also connect with different databases using namespaces to differentiate each other:
const fastify = require('fastify')()
fastify.register(require('fastify-atdatabase-pg'), {
namespace: 'primary',
connectionString: 'postgres://postgres:postgres@primary:5432/primary',
bigIntMode: 'string'
})
fastify.register(require('fastify-atdatabase-pg'), {
namespace: 'secondary',
connectionString: 'postgres://postgres:postgres@secondary:5432/secondary',
bigIntMode: 'string'
})
fastify.get('/primary', async (req, reply) => {
const result = await fastify.pg.primary.db.query(fastify.pg.primary.sql`SELECT NOW()`)
return reply.send(result)
})
fastify.get('/secondary', async (req, reply) => {
const result = await fastify.pg.secondary.db.query(fastify.pg.secondary.sql`SELECT NOW()`)
return reply.send(result)
})
fastify.listen({ port: 3000 }, err => {
if (err) throw err
})
Bulk insert is also available:
const fastify = require('fastify')()
fastify.register(require('fastify-atdatabase-pg'), {
connectionString: 'postgres://postgres:postgres@localhost:5432/postgres',
bigIntMode: 'string'
})
fastify.get('/:text', async (req, reply) => {
const {text} = req.params
const options = {
tableName: 'samples',
columnTypes: {
sample_data: fastify.pg.sql`TEXT`
}
}
const columnsToInsert = [
'sample_data'
]
const records = [
{ sample_data: text },
]
await fastify.pg.bulkInsert(options, columnsToInsert, records)
const results = await fastify.pg.db.query(fastify.pg.sql`SELECT * FROM samples`)
return reply.send(results)
})
fastify.listen({ port: 3000 }, err => {
if (err) throw err
})
More details about @databases/pg
documentation, see @databases/pg
FAQs
This module provides a way to use postgressql database.
We found that fastify-atdatabase-pg demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.