1.0.1 • Published 8 months ago
pg-db-libs v1.0.1
pg-db-libs
A TypeScript library for calling PostgreSQL functions and procedures with entity mapping.
Installation
npm install pg-db-libs
Usage
1. Define an Entity Class
class User {
id: number = 0;
name: string = "";
email: string = "";
}
2. Call Functions or Procedures
import { PgFunctionProcedureClient } from "pg-db-libs";
const main = async () => {
const config = {
user: "postgres",
host: "localhost",
database: "mydb",
password: "password",
port: 5432,
};
const pgClient = new PgFunctionProcedureClient(config);
try {
await pgClient.connect();
// Call a function that returns a result set
const users = await pgClient.callFunctionOrProcedure<User>(
"get_users",
[],
User
);
console.log("Users from function:", users);
// Call a procedure with output parameters
const output = await pgClient.callFunctionOrProcedure<any>(
"update_user_email",
[1, "newemail@example.com"],
Object,
true // Indicating this procedure has output parameters
);
console.log("Output parameters:", output);
} catch (error) {
console.error("Error:", error);
} finally {
await pgClient.disconnect();
}
};
main();
License
MIT
---
### 7. **Add a LICENSE**
Choose a license (e.g., MIT) and add it as `LICENSE` in the root directory. Here's an example of the MIT license content:
```plaintext
MIT License
Copyright (c) 2024 Your Name
Permission is hereby granted...