소스 정보
- 저장소
- tools-only/X-Skills
- 최근 소스 활동
- 2026년 2월 9일 04:08
- 감지된 SKILL.md 언어
- 영어
- 스타
- 7
- 포크
- 1
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/tools-only/X-Skills --skill stored-proc명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SOC 직업 분류 기준
SKILL.md 표시 중
| name | stored-proc |
| description | Generate production-ready stored procedures and database functions |
| shortcut | stor |
Generate production-ready stored procedures, functions, triggers, and custom database logic for complex business rules, performance optimization, and transaction safety across PostgreSQL, MySQL, and SQL Server.
Use /stored-proc when you need to:
DON'T use this when:
This command implements comprehensive stored procedure generation because:
Alternative considered: Application-layer logic
Alternative considered: Database views
Before running this command:
Define inputs, outputs, error conditions, and transaction boundaries.
Select function (returns value), procedure (performs action), or trigger (automated).
Write procedural code with proper error handling and transaction management.
Implement input validation, SQL injection prevention, and permission checks.
Test edge cases, measure performance, and optimize execution plans.
The command generates:
procedures/business_logic.sql - Production-ready stored proceduresfunctions/calculations.sql - Reusable database functionstriggers/audit_triggers.sql - Automated data tracking triggerstests/procedure_tests.sql - Unit tests for validationdocs/procedure_api.md - Documentation with usage examples-- Order processing with inventory management and audit logging
CREATE OR REPLACE FUNCTION process_order(
p_customer_id INTEGER,
p_order_items JSONB,
p_shipping_address JSONB
) RETURNS TABLE (
order_id INTEGER,
total_amount DECIMAL(10,2),
status VARCHAR(50),
estimated_delivery DATE
) AS $$
DECLARE
v_order_id INTEGER;
v_total DECIMAL(10,2) := 0;
v_item JSONB;
v_product_id INTEGER;
v_quantity INTEGER;
v_price DECIMAL(10,2);
v_available_stock INTEGER;
BEGIN
-- Validate customer exists and is active
IF NOT EXISTS (
SELECT 1 FROM customers
WHERE customer_id = p_customer_id AND status = 'active'
) THEN
RAISE EXCEPTION 'Customer % not found or inactive', p_customer_id
USING HINT = 'Check customer_id and status';
END IF;
-- Create order record
INSERT INTO orders (customer_id, order_date, status, shipping_address)
(
p_customer_id,
,
,
p_shipping_address
)
RETURNING order_id v_order_id;
v_item jsonb_array_elements(p_order_items)
LOOP
v_product_id : (v_item)::;
v_quantity : (v_item)::;
price v_price
products
product_id v_product_id active ;
IF v_price
RAISE EXCEPTION , v_product_id;
IF;
stock_quantity v_available_stock
inventory
product_id v_product_id
;
IF v_available_stock v_quantity
RAISE EXCEPTION ,
v_product_id, v_available_stock, v_quantity
HINT ;
IF;
order_items (order_id, product_id, quantity, unit_price, subtotal)
(
v_order_id,
v_product_id,
v_quantity,
v_price,
v_quantity v_price
);
inventory
stock_quantity stock_quantity v_quantity,
last_updated
product_id v_product_id;
v_total : v_total (v_quantity v_price);
LOOP;
orders
total_amount v_total,
status
order_id v_order_id;
v_delivery_date ;
v_delivery_date : ;
WHILE (DOW v_delivery_date) (, ) LOOP
v_delivery_date : v_delivery_date ;
LOOP;
;
order_audit_log (order_id, action, user_id, , details)
(
v_order_id,
,
,
,
jsonb_build_object(
, p_customer_id,
, v_total,
, jsonb_array_length(p_order_items)
)
);
QUERY
v_order_id,
v_total,
::(),
v_delivery_date;
EXCEPTION
OTHERS
error_log (function_name, error_message, error_detail, )
(
,
SQLERRM,
,
);
RAISE;
;
$$ plpgsql;
process_order(
,
::JSONB,
::JSONB
);
-- User activity report generator with aggregations
DELIMITER $$
CREATE PROCEDURE generate_user_activity_report(
IN p_start_date DATE,
IN p_end_date DATE,
IN p_user_type VARCHAR(50)
)
BEGIN
DECLARE v_user_id INT;
DECLARE v_username VARCHAR(255);
DECLARE v_total_logins INT;
DECLARE v_total_transactions DECIMAL(10,2);
DECLARE v_done INT DEFAULT FALSE;
-- Cursor to iterate over users
DECLARE user_cursor CURSOR FOR
SELECT user_id, username
FROM users
WHERE user_type = p_user_type
AND created_at <= p_end_date
ORDER BY username;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;
-- Create temporary results table
DROP TEMPORARY TABLE IF EXISTS temp_user_report;
CREATE TEMPORARY TABLE temp_user_report (
user_id ,
username (),
total_logins ,
total_transactions (,),
avg_transaction_value (,),
last_activity_date DATETIME,
activity_status ()
);
TRANSACTION;
user_cursor;
user_loop: LOOP
user_cursor v_user_id, v_username;
IF v_done
LEAVE user_loop;
IF;
() v_total_logins
login_history
user_id v_user_id
login_date p_start_date p_end_date
status ;
((amount), ) v_total_transactions
transactions
user_id v_user_id
transaction_date p_start_date p_end_date
status ;
temp_user_report (
user_id,
username,
total_logins,
total_transactions,
avg_transaction_value,
last_activity_date,
activity_status
)
v_user_id,
v_username,
v_total_logins,
v_total_transactions,
v_total_logins v_total_transactions v_total_logins
,
( (activity_date)
(
(login_date) activity_date login_history user_id v_user_id
(transaction_date) transactions user_id v_user_id
) activities),
v_total_logins
v_total_logins
v_total_logins
;
LOOP;
user_cursor;
;
user_id,
username,
total_logins,
FORMAT(total_transactions, ) total_transactions,
FORMAT(avg_transaction_value, ) avg_transaction_value,
DATE_FORMAT(last_activity_date, ) last_activity,
activity_status
temp_user_report
total_transactions ;
$$
DELIMITER ;
generate_user_activity_report(, , );
-- PostgreSQL audit trigger for tracking all table changes
CREATE OR REPLACE FUNCTION audit_trigger_function()
RETURNS TRIGGER AS $$
BEGIN
IF TG_OP = 'INSERT' THEN
INSERT INTO audit_log (
table_name,
operation,
row_id,
new_data,
changed_by,
changed_at
) VALUES (
TG_TABLE_NAME,
'INSERT',
NEW.id,
row_to_json(NEW),
CURRENT_USER,
CURRENT_TIMESTAMP
);
RETURN NEW;
ELSIF TG_OP = 'UPDATE' THEN
INSERT INTO audit_log (
table_name,
operation,
row_id,
old_data,
new_data,
changed_by,
changed_at
) VALUES (
TG_TABLE_NAME,
'UPDATE',
NEW.id,
row_to_json(OLD),
row_to_json(NEW),
CURRENT_USER,
CURRENT_TIMESTAMP
);
RETURN NEW;
ELSIF TG_OP = 'DELETE' THEN
INSERT INTO audit_log (
table_name,
operation,
row_id,
old_data,
changed_by,
changed_at
) VALUES (
TG_TABLE_NAME,
'DELETE',
OLD.id,
row_to_json(OLD),
,
);
;
IF;
;
$$ plpgsql;
users_audit_trigger
AFTER users
audit_trigger_function();
orders_audit_trigger
AFTER orders
audit_trigger_function();
transactions_audit_trigger
AFTER transactions
audit_trigger_function();
| Error | Cause | Solution |
|---|---|---|
| "Function does not exist" | Missing or misspelled function name | Check function signature and schema |
| "Deadlock detected" | Concurrent transactions locking same rows | Use FOR UPDATE SKIP LOCKED or retry logic |
| "Stack depth limit exceeded" | Infinite recursion in function | Add recursion depth limit checks |
| "Out of shared memory" | Too many cursors or temp tables | Close cursors explicitly, limit temp table size |
| "Division by zero" | Unhandled edge case | Add NULL/zero checks before calculations |
Function Types
Volatility Categories
IMMUTABLE: Pure function, same inputs = same outputsSTABLE: Results consistent within transactionVOLATILE: May change even with same inputs (default)Security Options
SECURITY DEFINER: Runs with creator's permissionsSECURITY INVOKER: Runs with caller's permissions (default)DO:
DON'T:
SELECT * in production functions (specify columns)FOR UPDATE SKIP LOCKED to avoid blocking in high-concurrency scenarios/database-migration-manager - Deploy stored procedures across environments/sql-query-optimizer - Optimize queries within procedures/database-transaction-monitor - Monitor procedure execution and locks/database-security-scanner - Audit procedure permissions and SQL injection risks