feat: Enhance documentation and add .gitignore entries
- Add new documentation sections for PostgreSQL installer functions and usage examples. Improves clarity and completeness of the documentation. - Add new files and patterns to .gitignore to prevent unnecessary files from being committed to the repository. Improves repository cleanliness and reduces clutter.
This commit is contained in:
@@ -9,9 +9,12 @@ The PostgreSQL client module provides the following features:
|
||||
1. **Basic PostgreSQL Operations**: Execute queries, fetch results, etc.
|
||||
2. **Connection Management**: Automatic connection handling and reconnection
|
||||
3. **Builder Pattern for Configuration**: Flexible configuration with authentication support
|
||||
4. **PostgreSQL Installer**: Install and configure PostgreSQL using nerdctl
|
||||
5. **Database Management**: Create databases and execute SQL scripts
|
||||
|
||||
## Prerequisites
|
||||
|
||||
For basic PostgreSQL operations:
|
||||
- PostgreSQL server must be running and accessible
|
||||
- Environment variables should be set for connection details:
|
||||
- `POSTGRES_HOST`: PostgreSQL server host (default: localhost)
|
||||
@@ -20,6 +23,11 @@ The PostgreSQL client module provides the following features:
|
||||
- `POSTGRES_PASSWORD`: PostgreSQL password
|
||||
- `POSTGRES_DB`: PostgreSQL database name (default: postgres)
|
||||
|
||||
For PostgreSQL installer:
|
||||
- nerdctl must be installed and working
|
||||
- Docker images must be accessible
|
||||
- Sufficient permissions to create and manage containers
|
||||
|
||||
## Test Files
|
||||
|
||||
### 01_postgres_connection.rhai
|
||||
@@ -34,6 +42,15 @@ Tests basic PostgreSQL connection and operations:
|
||||
- Dropping a table
|
||||
- Resetting the connection
|
||||
|
||||
### 02_postgres_installer.rhai
|
||||
|
||||
Tests PostgreSQL installer functionality:
|
||||
|
||||
- Installing PostgreSQL using nerdctl
|
||||
- Creating a database
|
||||
- Executing SQL scripts
|
||||
- Checking if PostgreSQL is running
|
||||
|
||||
### run_all_tests.rhai
|
||||
|
||||
Runs all PostgreSQL client module tests and provides a summary of the results.
|
||||
@@ -66,6 +83,13 @@ herodo --path src/rhai_tests/postgresclient/01_postgres_connection.rhai
|
||||
- `pg_query(query)`: Execute a query and return the results as an array of maps
|
||||
- `pg_query_one(query)`: Execute a query and return a single row as a map
|
||||
|
||||
### Installer Functions
|
||||
|
||||
- `pg_install(container_name, version, port, username, password)`: Install PostgreSQL using nerdctl
|
||||
- `pg_create_database(container_name, db_name)`: Create a new database in PostgreSQL
|
||||
- `pg_execute_sql(container_name, db_name, sql)`: Execute a SQL script in PostgreSQL
|
||||
- `pg_is_running(container_name)`: Check if PostgreSQL is running
|
||||
|
||||
## Authentication Support
|
||||
|
||||
The PostgreSQL client module will support authentication using the builder pattern in a future update.
|
||||
@@ -85,7 +109,9 @@ When implemented, the builder pattern will support the following configuration o
|
||||
|
||||
## Example Usage
|
||||
|
||||
```javascript
|
||||
### Basic PostgreSQL Operations
|
||||
|
||||
```rust
|
||||
// Connect to PostgreSQL
|
||||
if (pg_connect()) {
|
||||
print("Connected to PostgreSQL!");
|
||||
@@ -112,3 +138,51 @@ if (pg_connect()) {
|
||||
pg_execute(drop_query);
|
||||
}
|
||||
```
|
||||
|
||||
### PostgreSQL Installer
|
||||
|
||||
```rust
|
||||
// Install PostgreSQL
|
||||
let container_name = "my-postgres";
|
||||
let postgres_version = "15";
|
||||
let postgres_port = 5432;
|
||||
let postgres_user = "myuser";
|
||||
let postgres_password = "mypassword";
|
||||
|
||||
if (pg_install(container_name, postgres_version, postgres_port, postgres_user, postgres_password)) {
|
||||
print("PostgreSQL installed successfully!");
|
||||
|
||||
// Create a database
|
||||
let db_name = "mydb";
|
||||
if (pg_create_database(container_name, db_name)) {
|
||||
print(`Database '${db_name}' created successfully!`);
|
||||
|
||||
// Execute a SQL script
|
||||
let create_table_sql = `
|
||||
CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
email TEXT UNIQUE NOT NULL
|
||||
);
|
||||
`;
|
||||
|
||||
let result = pg_execute_sql(container_name, db_name, create_table_sql);
|
||||
print("Table created successfully!");
|
||||
|
||||
// Insert data
|
||||
let insert_sql = "#
|
||||
INSERT INTO users (name, email) VALUES
|
||||
('John Doe', 'john@example.com'),
|
||||
('Jane Smith', 'jane@example.com');
|
||||
#";
|
||||
|
||||
result = pg_execute_sql(container_name, db_name, insert_sql);
|
||||
print("Data inserted successfully!");
|
||||
|
||||
// Query data
|
||||
let query_sql = "SELECT * FROM users;";
|
||||
result = pg_execute_sql(container_name, db_name, query_sql);
|
||||
print(`Query result: ${result}`);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user