Meta tags:
description= Lightweight WASM Postgres;
Headings (most frequently used words):
usage, options, using, pglite, socket, cli, tips, server, example, methods, events, about, docs, extensions, reference, installation, api, llm, limitations, and, framework, hooks, tools, pglitesocketserver, pglitesockethandler, development, integration, in, npm, scripts, unix, support, connecting, to, the, prompt, general, psql, node, js, clients,
Text of the page (most frequently used words):
pglite (62), the (52), #server (52), socket (40), database (31), run (25), postgres (24), and (23), for (23), dev (20), using (18), with (18), when (15), host (15), this (15), npm (15), start (15), sql (14), postgresql (13), port (13), electric (12), default (12), path (11), 5432 (11), from (10), development (10), include (10), use (9), const (9), url (9), handler (9), connection (8), create (8), console (7), data (7), error (7), can (7), import (7), await (7), unix (7), instance (7), emitted (7), connections (6), debug (6), memory (6), single (6), process (6), app (6), connect (6), client (6), bash (6), your (6), package (6), pglitesockethandler (6), subprocess (5), will (5), tmp (5), install (5), database_url (5), you (5), 127 (5), options (5), close (5), boolean (5), sync (4), shutdown (4), are (4), env (4), psql (4), should (4), backend (4), both (4), concurrently (4), typescript (4), new (4), node (4), tcp (4), cli (4), command (4), starts (4), string (4), that (4), level (4), bind (4), false (4), pglitesocketserver (4), page (3), graceful (3), timeout (3), protocol (3), pgsslmode (3), disable (3), not (3), multiple (3), through (3), over (3), like (3), vite (3), list (3), simple (3), used (3), usage (3), environment (3), localhost (3), clients (3), support (3), 5433 (3), scripts (3), add (3), installation (3), allows (3), listen (3), log (3), attach (3), inspect (3), closed (3), promise (3), stop (3), tools (2), next (2), automatically (2), down (2), exits (2), zero (2), allow (2), set (2), persistent (2), file (2), mydb (2), after (2), stopped (2), tips (2), ssl (2), supported (2), all (2), cases (2), multiplexer (2), limitations (2), max (2), use_pglite (2), something (2), tsx (2), frontend (2), true (2), npx (2), pgsql (2), want (2), its (2), please (2), react (2), end (2), show (2), where (2), wish (2), have (2), adding (2), there (2), prompt (2), one (2), example (2), drop (2), replacement (2), builders (2), need (2), manage (2), locally (2), remote (2), variable (2), clean (2), json (2), integration (2), worker (2), takes (2), precedence (2), help (2), custom (2), quickly (2), starting (2), err (2), async (2), createserver (2), closeondetach (2), net (2), occurs (2), events (2), detach (2), methods (2), print (2), incoming (2), outgoing (2), low (2), class (2), handles (2), raw (2), communication (2), between (2), listening (2), void (2), api (2), started (2), main (2), extensions (2), repl (2), docs (2), about (2), navigation (2), dual, licensed, under, license, apache, previous, pager, adjust, how, long, wait, termination, seconds, shut, non, code, other, machines, mode, higher, additional, information, displayed, storage, specify, purposes, fastest, but, won, persist, general, var, concurrent, conn, therefore, might, covered, important, node_env, production, connectionstring, connect_timeout, password, username, export, config, look, watch, index, match, these, versions, same, time, side, express, lib, template, literal, syntax, front, messages, inline, fails, make, screen, items, input, text, item, keep, minimal, shot, working, bolt, environments, combined, coding, agents, significantly, simplify, removes, llm, javascript, once, running, any, connecting, better, performance, local, sockets, instead, then, convenient, execution, shuts, gracefully, automatic, cleanup, application, simplified, setup, each, project, own, isolated, databases, instantly, compared, faster, startup, benefits, receive, correct, enables, seamless, applications, expect, services, manager, option, particularly, useful, workflows, wrap, provide, pointing, 5000, short, settings, globally, provides, line, interface, attaching, catch, connected, try, uses, processed, check, currently, attached, isattached, current, hex, ascii, whether, detached, connects, number, creates, exit, sigint, handle, pnpm, yarn, although, possible, open, simultaneous, achieved, implemented, see, parameter, different, normal, guaranteed, work, info, also, includes, two, components, implementation, enabling, wrapper, around, module, debugging, benchmarks, examples, reference, extension, catalog, upgrade, locale, prepopulated, pgdump, orms, query, component, multi, tab, bundler, vue, framework, hooks, filesystems, live, queries, getting, videos, what, sidebar, return, top, menu, github, home, search, skip, content,
Text of the page (random words):
pglite socket pglite skip to content search k main navigation home about docs repl electric github npm menu return to top sidebar navigation about what is pglite videos docs getting started pglite api live queries filesystems framework hooks react vue bundler support multi tab worker repl component orms query builders sync using postgres sync pglite socket pglite tools package pgdump prepopulated fs locale support upgrade path extensions extensions catalog extension development reference examples benchmarks debugging on this page pglite socket a socket implementation for pglite enabling remote connections this package is a simple wrapper around the net module to allow pglite to be used as a postgresql server there are two main components to this package pglitesocketserver a tcp server that allows postgresql clients to connect to a pglite database instance pglitesockethandler a low level handler for a single socket connection to pglite this class handles the raw protocol communication between a socket and pglite and can be used to create a custom server the package also includes a cli for quickly starting a pglite socket server info although pglite is a single connection database it is possible to open and use multiple simultaneous connections with pglite server this is achieved through a multiplexer implemented in the server see the parameter m max connections this is different from a normal postgres installation so not all use cases are guaranteed to work installation bash npm install electric sql pglite socket or yarn add electric sql pglite socket or pnpm add electric sql pglite socket usage typescript import pglite from electric sql pglite import pglitesocketserver from electric sql pglite socket create a pglite instance const db await pglite create create and start a socket server const server new pglitesocketserver db port 5432 host 127 0 0 1 await server start console log server started on 127 0 0 1 5432 handle graceful shutdown process on sigint async await server stop await db close console log server stopped and database closed process exit 0 api pglitesocketserver creates a tcp server that allows postgresql clients to connect to a pglite database instance options db pglite the pglite database instance port number the port to listen on default 5432 host string the host to bind to default 127 0 0 1 path string unix socket path to bind to takes precedence over host port inspect boolean print the incoming and outgoing data to the console default false methods start promise void start the socket server stop promise void stop the socket server events listening emitted when the server starts listening connection emitted when a client connects error emitted when an error occurs close emitted when the server is closed pglitesockethandler low level handler for a single socket connection to pglite this class handles the raw protocol communication between a socket and pglite options db pglite the pglite database instance closeondetach boolean whether to close the socket when detached default false inspect boolean print the incoming and outgoing data to the console in hex and ascii default false methods attach socket socket promise pglitesockethandler attach a socket to this handler detach close boolean pglitesockethandler detach the current socket from this handler isattached boolean check if a socket is currently attached events data emitted when data is processed through the handler error emitted when an error occurs close emitted when the socket is closed example typescript import pglite from electric sql pglite import pglitesockethandler from electric sql pglite socket import createserver socket from net create a pglite instance const db await pglite create create a handler const handler new pglitesockethandler db closeondetach true inspect false create a server that uses the handler const server createserver async socket socket try await handler attach socket console log client connected catch err console error error attaching socket err socket end server listen 5432 127 0 0 1 cli usage this package provides a command line interface for quickly starting a pglite socket server bash install globally npm install g electric sql pglite socket start a server with default settings in memory database port 5432 pglite server start a server with custom options pglite server db path to database port 5433 host 0 0 0 0 debug 1 using short options pglite server d path to database p 5433 h 0 0 0 0 v 1 show help pglite server help cli options d db path database path default memory p port port port to listen on default 5432 h host host host to bind to default 127 0 0 1 u path unix unix socket to bind to takes precedence over host port v debug level debug level 0 5 default 0 r run command command to run after server starts include database url include database_url in subprocess environment shutdown timeout ms timeout for graceful subprocess shutdown in ms default 5000 development server integration the run option is particularly useful for development workflows where you want to use pglite as a drop in replacement for postgresql this allows you to wrap your development server and automatically provide it with a database_url pointing to your pglite instance bash start your next js dev server with pglite pglite server run npm run dev include database url start a node js app with pglite pglite server db dev db run node server js include database url start multiple services using a process manager like concurrently pglite server run npx concurrently npm run dev npm run worker include database url when using run with include database url the subprocess will receive a database_url environment variable with the correct connection string for your pglite server this enables seamless integration with applications that expect a postgresql connection string benefits for development zero postgresql installation no need to install and manage postgresql locally faster startup pglite starts instantly compared to postgresql isolated databases each project can have its own database file simplified setup one command starts both database and application automatic cleanup server shuts down gracefully when your app exits using in npm scripts you can add the cli to your package json scripts for convenient execution json scripts db start pglite server db data mydb port 5433 db dev pglite server db memory debug 1 dev pglite server db dev db run npm run start dev include database url dev clean pglite server run npm run start dev include database url then run with bash npm run dev start with persistent database npm run dev clean start with in memory database unix socket support for better performance in local development you can use unix sockets instead of tcp bash start server on a unix socket pglite server path tmp s pgsql 5432 run npm run dev include database url the database_url will be postgresql postgres postgres postgres host tmp connecting to the server once the server is running you can connect to it using any postgresql client using psql bash tcp connection pgsslmode disable psql h localhost p 5432 d postgres unix socket connection if using path pgsslmode disable psql h tmp d postgres using node js clients javascript using node postgres import pg from pg const client new pg client host localhost port 5432 database postgres await client connect using postgres js import postgres from postgres const sql postgres host localhost port 5432 database postgres using environment variable when using include database url const sql postgres process env database_url llm usage pglite with the socket server can be used as a drop in replacement for postgresql in development environments and when combined with ai coding agents or app builders can significantly simplify development it removes the need to install and manage postgresql locally or to connect to a remote database example prompt this prompt will one shot a working wish list app with pglite in bolt new please make a simple wish list app it should have a single screen for adding items there should be a single input for adding the text for the item keep it simple and minimal show error messages inline in the ui where the list is when the backend fails to connect to the database use typescript react and vite for the front end app the server side should use typescript tsx and express with a postgres database using the postgres js lib and it s sql template literal syntax please use concurrently to run both vite and the backend at the same time i want to use pglite and its socket server for development match these versions electric sql pglite 0 3 2 electric sql pglite socket 0 0 7 do something like this to run it dev use_pglite true npx pglite server u tmp s pgsql 5432 r npm run dev both dev both concurrently npm run dev frontend npm run dev backend dev frontend vite dev backend tsx watch server index ts and the postgres js config should look something like this export const sql process env use_pglite postgres host tmp username postgres password postgres database postgres max 1 connect_timeout 0 postgres connectionstring ssl process env node_env production limitations and tips important limitations multiple concurrent connections are supported through a multiplexer over the single conn therefore not all cases might be covered ssl connections are not supported for psql set env var pgsslmode disable general tips for development purposes using an in memory database db memory is fastest but data won t persist after the server is stopped for persistent storage specify a file path for the database e g db data mydb when using debug mode debug 1 or higher additional protocol information will be displayed in the console to allow connections from other machines set the host to 0 0 0 0 with host 0 0 0 0 when using run the server will automatically shut down if the subprocess exits with a non zero code use shutdown timeout to adjust how long to wait for graceful subprocess termination default 5 seconds pager previous page sync using postgres sync next page pglite tools dual licensed under apache 2 0 and the postgresql license electric
|