Database
MongoDB, MySQL, PostgreSQL, and Redis database operations.
9 modules
| Module | Description |
|---|---|
| Chèn cơ sở dữ liệu | Chèn dữ liệu vào các bảng cơ sở dữ liệu |
| Truy vấn cơ sở dữ liệu | Thực thi truy vấn SQL trên cơ sở dữ liệu PostgreSQL, MySQL hoặc SQLite |
| Cập nhật cơ sở dữ liệu | Cập nhật dữ liệu trong các bảng cơ sở dữ liệu |
| MongoDB Find | Truy vấn tài liệu từ collection MongoDB |
| MongoDB Insert | Chèn một hoặc nhiều tài liệu vào collection MongoDB |
| Truy vấn MySQL | Thực thi truy vấn SQL trên cơ sở dữ liệu MySQL và trả về kết quả |
| Truy vấn PostgreSQL | Thực thi truy vấn SQL trên cơ sở dữ liệu PostgreSQL và trả về kết quả |
| Redis Get | Lấy giá trị từ cache Redis |
| Redis Set | Đặt giá trị trong cache Redis |
Modules
Chèn cơ sở dữ liệu
database.insert
Chèn dữ liệu vào các bảng cơ sở dữ liệu
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
table | string | Yes | - | Name of the table |
data | object | Yes | - | Data to insert or update |
database_type | select (postgresql, mysql, sqlite) | No | postgresql | Database type to connect to |
connection_string | string | No | - | Database connection string |
host | string | No | - | Database host |
port | number | No | - | Database port |
database | string | No | - | Database name |
user | string | No | - | Database username |
password | string | No | - | Database password |
returning | array | No | - | Columns to return after insert (PostgreSQL) |
Output:
| Field | Type | Description |
|---|---|---|
inserted_count | number | Số hàng đã chèn |
returning_data | array | Số hàng đã chèn |
Example: Insert single row
table: users
data: {"name": "John", "email": "john@example.com"}
database_type: postgresqlTruy vấn cơ sở dữ liệu
database.query
Thực thi truy vấn SQL trên cơ sở dữ liệu PostgreSQL, MySQL hoặc SQLite
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
query | string | Yes | - | SQL query to execute |
params | array | No | [] | Parameters for parameterized queries (prevents SQL injection) |
database_type | select (postgresql, mysql, sqlite) | No | postgresql | Database type to connect to |
connection_string | string | No | - | Database connection string |
host | string | No | - | Database host |
port | number | No | - | Database port |
database | string | No | - | Database name |
user | string | No | - | Database username |
password | string | No | - | Database password |
fetch | select (all, one, none) | No | all | How many rows to return from the query |
Output:
| Field | Type | Description |
|---|---|---|
rows | array | Các hàng kết quả truy vấn |
row_count | number | Các hàng kết quả truy vấn |
columns | array | Các hàng kết quả truy vấn |
Example: Select with parameters
query: SELECT * FROM users WHERE status = $1
params: ["active"]
database_type: postgresqlCập nhật cơ sở dữ liệu
database.update
Cập nhật dữ liệu trong các bảng cơ sở dữ liệu
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
table | string | Yes | - | Name of the table |
data | object | Yes | - | Data to insert or update |
where | object | Yes | - | WHERE conditions (column: value for equality) |
database_type | select (postgresql, mysql, sqlite) | No | postgresql | Database type to connect to |
connection_string | string | No | - | Database connection string |
host | string | No | - | Database host |
port | number | No | - | Database port |
database | string | No | - | Database name |
user | string | No | - | Database username |
password | string | No | - | Database password |
Output:
| Field | Type | Description |
|---|---|---|
updated_count | number | Số hàng đã cập nhật |
Example: Update user status
table: users
data: {"status": "active"}
where: {"id": 123}
database_type: postgresqlMongoDB Find
db.mongodb.find
Truy vấn tài liệu từ collection MongoDB
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
connection_string | string | No | - | MongoDB connection string (defaults to env.MONGODB_URL) |
database | string | Yes | - | Database name |
collection | string | Yes | - | Collection name |
filter | object | No | {} | MongoDB query filter (empty object {} returns all) |
projection | object | No | - | Fields to include/exclude in results |
limit | number | No | 100 | Maximum number of documents to return |
sort | object | No | - | Sort order (1 for ascending, -1 for descending) |
Output:
| Field | Type | Description |
|---|---|---|
documents | array | Mảng các tài liệu khớp |
count | number | Mảng các tài liệu khớp |
Example: Find all active users
database: myapp
collection: users
filter: {"status": "active"}
limit: 50Example: Find with projection and sort
database: myapp
collection: orders
filter: {"total": {"$gt": 100}}
projection: {"_id": 0, "order_id": 1, "total": 1, "created_at": 1}
sort: {"created_at": -1}
limit: 20MongoDB Insert
db.mongodb.insert
Chèn một hoặc nhiều tài liệu vào collection MongoDB
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
connection_string | string | No | - | MongoDB connection string (defaults to env.MONGODB_URL) |
database | string | Yes | - | Database name |
collection | string | Yes | - | Collection name |
document | object | No | - | Document to insert (for single insert) |
documents | array | No | - | Array of documents to insert (for bulk insert) |
Output:
| Field | Type | Description |
|---|---|---|
inserted_count | number | Số tài liệu đã chèn |
inserted_ids | array | Số tài liệu đã chèn |
Example: Insert single document
database: myapp
collection: users
document: {"name": "John Doe", "email": "john@example.com", "created_at": "${timestamp}"}Example: Insert multiple documents
database: myapp
collection: products
documents: [{"name": "Product A", "price": 19.99}, {"name": "Product B", "price": 29.99}]Truy vấn MySQL
db.mysql.query
Thực thi truy vấn SQL trên cơ sở dữ liệu MySQL và trả về kết quả
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
host | string | No | - | Database host |
port | number | No | 3306 | Database port |
user | string | No | - | Database username |
password | string | No | - | Database password |
database | string | No | - | Database name |
query | string | Yes | - | SQL query to execute |
params | array | No | [] | Parameters for parameterized queries (prevents SQL injection) |
Output:
| Field | Type | Description |
|---|---|---|
rows | array | Mảng các hàng kết quả dưới dạng đối tượng |
row_count | number | Mảng các hàng kết quả dưới dạng đối tượng |
columns | array | Mảng các hàng kết quả dưới dạng đối tượng |
Example: Select products
query: SELECT id, name, price FROM products WHERE stock > 0 ORDER BY price DESC LIMIT 20Example: Parameterized query
query: SELECT * FROM orders WHERE customer_id = %s AND created_at > %s
params: ["${customer_id}", "2024-01-01"]Truy vấn PostgreSQL
db.postgresql.query
Thực thi truy vấn SQL trên cơ sở dữ liệu PostgreSQL và trả về kết quả
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
connection_string | string | No | - | Database connection string |
query | string | Yes | - | SQL query to execute |
params | array | No | [] | Parameters for parameterized queries (prevents SQL injection) |
Output:
| Field | Type | Description |
|---|---|---|
rows | array | Mảng các hàng kết quả dưới dạng đối tượng |
row_count | number | Mảng các hàng kết quả dưới dạng đối tượng |
columns | array | Mảng các hàng kết quả dưới dạng đối tượng |
Example: Select users
query: SELECT id, email, created_at FROM users WHERE active = true LIMIT 10Example: Parameterized query
query: SELECT * FROM orders WHERE user_id = $1 AND status = $2
params: ["${user_id}", "completed"]Redis Get
db.redis.get
Lấy giá trị từ cache Redis
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
key | string | Yes | - | Redis key |
host | string | No | - | Redis host (from env.REDIS_HOST or explicit) |
port | number | No | 6379 | Redis port |
db | number | No | 0 | Redis database number |
Output:
| Field | Type | Description |
|---|---|---|
value | any | Giá trị trả về |
exists | boolean | Giá trị trả về |
key | string | Giá trị trả về |
Example: Get cached value
key: user:123:profile
host: ${env.REDIS_HOST}Example: Get from remote Redis
key: session:abc
host: redis.example.com
port: 6379
db: 1Redis Set
db.redis.set
Đặt giá trị trong cache Redis
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
key | string | Yes | - | Redis key |
value | any | Yes | - | Value to store |
ttl | number | No | - | Time to live in seconds (optional) |
host | string | No | - | Redis host (from env.REDIS_HOST or explicit) |
port | number | No | 6379 | Redis port |
db | number | No | 0 | Redis database number |
Output:
| Field | Type | Description |
|---|---|---|
success | boolean | Whether the operation completed successfully |
key | string | Key identifier |
Example: Cache user profile
key: user:123:profile
value: {"name": "John", "email": "john@example.com"}
ttl: 3600Example: Set session data
key: session:abc
value: active
ttl: 1800
host: redis.example.com