Registry / database / lc-pg-dao

lc-pg-dao

JSON →
library1.1.12jsnpmunverified

lc-pg-dao is a lightweight PostgreSQL DAO utility for Node.js, wrapping pg-pool to provide simple table creation, auto-ID generation, and CRUD operations. Version 1.1.12 is the latest stable release. The library is primarily used in Chinese-speaking developer communities, as documented in Chinese. It differentiates itself by offering a simple configuration object for database connection and a chainable API for table creation with support for unique keys, auto-increment IDs, and operator ID fields.

npm install lc-pg-dao
INSTALL
IMPORT
SIG · LC-PG-DAO
L
lc-pg-dao
databasejavascriptv1.1.12
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const dao = require('lc-pg-dao')
import dao from 'lc-pg-dao'
This package is CommonJS only and does not support ESM imports.
client
const { client } = dao(config)
dao.client(config)
client is a property on the object returned by the default export, not a method on the require result.
create
const { create } = dao(config)
dao.create(config)
create is a method on the returned object, used for table creation.

Initializes a PostgreSQL connection using lc-pg-dao, connects to the database, and creates a simple table with auto-generated ID.

const dao = require('lc-pg-dao'); const config = { config: { user: 'postgres', password: '123123', host: '127.0.0.1', port: '5432', database: 'test' } }; const { client, create } = dao(config); client().then(() => { console.log('Connected'); create({ isAutoCreateId: true, tableName: 'example', fields: [{ name: 'name', type: 'varchar', isNotNull: true }] }).then(() => console.log('Table created')); }).catch(err => console.error(err));
Debug
Known issues
gotchaThe function dao() returns an object with client and create methods. It must be called before using those methods.
fix
Always assign the result of dao(config) to a variable before accessing client or create.
affects: all
gotchaThe config object must be nested under a 'config' key, as shown in the example.
fix
Pass an object with a top-level 'config' property containing your connection parameters.
affects: all
gotchaNo built-in connection validation. The client() promise may resolve even with invalid credentials if the pool is created successfully.
fix
Test the connection by executing a simple query after client() resolves.
affects: all
deprecatedThe library does not support ESM imports. Attempting 'import dao from 'lc-pg-dao'' will fail.
fix
Use require() or wrap it in a dynamic import with a module that supports CommonJS.
affects: all
Errors
Common errors & fixes
TypeError: dao is not a function
Using import statement on a CommonJS-only package.
fix
Replace 'import dao from 'lc-pg-dao'' with 'const dao = require('lc-pg-dao')'.
Cannot read properties of undefined (reading 'client')
Calling dao() without storing its return value, then trying to access client on the function.
fix
Call dao(config) and store the result: const { client } = dao(config);
error: relation "<table_name>" does not exist
The create method was not called or the table creation failed silently.
fix
Ensure you call create() after client() resolves and handle the promise properly.
Upgrade
Version history
1.1.12latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client for Node.js
pg-poolrequiredConnection pool for pg
Agent activity
2 hits · last 30 days
node
2
Resources
lc-pg-dao — npm install lc-pg-dao · libregistry