nuxt-neon
v0.1.2
Published
Nuxt framework integration with Neon database
Downloads
12
Readme
Nuxt-Neon
A simple Nuxt module alowing smooth integration with Neon database.
How to use?
Install the module to your Nuxt application with one command:
npx nuxi module add nuxt-neon
Provide connection details to your Neon DB instance through a set of Nuxt runtime config variables:
NUXT_PUBLIC_NEON_HOST
NUXT_PUBLIC_NEON_USER
NUXT_PUBLIC_NEON_PASS
NUXT_PUBLIC_NEON_DB
Nuxt-Neon will construct a PostgreSQL connection string based on given values:
`postgresql://${NUXT_PUBLIC_NEON_USER}:${NUXT_PUBLIC_NEON_PASS}@${NUXT_PUBLIC_NEON_HOST}.neon.tech/${NUXT_PUBLIC_NEON_DB}`
It will be used to initialize the Neon serverless driver object exposed via useNeon
composable:
const { neonClient } = useNeon()
Provided Neon client object is capable of making direct SQL queries to connected database.
You can use either tagged template syntax:
neonClient`SELECT * FROM playing_with_neon`
Or the traditional function syntax:
neonClient('SELECT * FROM playing_with_neon')
That's it! Your Nuxt app is now connected to a Neon database instance ✨
Health check
Current status of the connection can be quickly checked by calling async function isOk
provided by useNeon
composable:
const { isOk } = useNeon()
The return value true/false
is based on more complex probe function neonStatus
which is also available:
const { neonStatus } = useNeon()
The test is performed by firing a SELECT 1=1
query to the current neonClient
.
The function takes two optional parameters:
anonymous: boolean = true
- if set tofalse
, it will disclose username and password [WARNING: may expose sensitive data! Use with caution]debug: boolean = false
- if set totrue
, if will append the root cause returned by Neon driver [WARNING: may expose sensitive data! Use with caution]
Value returned is a NeonStatusResult
promise:
connectionString: string
- connection string that was used to initialize currentneonClient
(USER and PASS are anonymized, ifanonymous = true
)status: 'OK' | 'ERR'
-OK
if connection works,ERR
if error occureddebug?: string
- Neon driver error, ifstatus = 'ERR'
anddebug = true
Module options
Nuxt-Neon can be configured by overriding the default options values using key neon
inside nuxt.config.ts
.
Existing options:
sslMode
- allows setting secure connection mode when constructing the DB connection string by addingsslmode
parameter to URL. Values can be:require
(default)verify-ca
verify-full
none
(sslmode is not inclued in the connection string)
Example:
// nuxt.config.ts
export default defineNuxtConfig({
neon: {
sslMode: 'verify-full',
},
// other configuration
})
See also
- Neon serverless driver for the full reference of provided features like the
transaction()
function.
Contribution
Contributions welcome! Let's make this module better together.
Contact https://github.com/AloisSeckar for more info.
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release