{"id":27219943,"url":"https://github.com/pixelbend/pg-ledger","last_synced_at":"2025-04-10T06:50:01.000Z","repository":{"id":287095243,"uuid":"963270274","full_name":"pixelbend/pg-ledger","owner":"pixelbend","description":"A robust and flexible starting point for financial transactions management ","archived":false,"fork":false,"pushed_at":"2025-04-09T12:33:38.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T00:01:38.652Z","etag":null,"topics":["financial-transactions","ledger","postgres","postgresql","transactions","yugabyte","yugabytedb"],"latest_commit_sha":null,"homepage":"","language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pixelbend.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-04-09T12:25:18.000Z","updated_at":"2025-04-09T12:36:49.000Z","dependencies_parsed_at":"2025-04-10T00:01:40.571Z","dependency_job_id":"b5fe0916-fd93-4c8f-8850-bcb5ca4133d9","html_url":"https://github.com/pixelbend/pg-ledger","commit_stats":null,"previous_names":["pixelbend/pg-ledger"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Fpg-ledger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Fpg-ledger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Fpg-ledger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Fpg-ledger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pixelbend","download_url":"https://codeload.github.com/pixelbend/pg-ledger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248173852,"owners_count":21059595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["financial-transactions","ledger","postgres","postgresql","transactions","yugabyte","yugabytedb"],"created_at":"2025-04-10T06:50:00.423Z","updated_at":"2025-04-10T06:50:00.980Z","avatar_url":"https://github.com/pixelbend.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pg Ledger\n\n## Overview\n\npgledger is a PostgreSQL database schema designed for managing financial transactions and accounts.\nIt provides a robust and scalable foundation for building financial applications.\n\n## Features\n\n- **Accounts**: Create and manage accounts with unique IDs, names, currencies, and balances.\n- **Transfers**: Record transactions between accounts, including transfer amounts, timestamps, and account balances.\n- **Entries**: Store detailed information about each transaction, including account IDs, transfer IDs, amounts, and\n  timestamps.\n- **Constraints**: Enforce rules for account balances, such as preventing negative or positive balances.\n- **Functions**: Utilize pre-built functions for creating accounts, transfers, and entries, as well as checking account\n  balance constraints.\n\n## Schema\n\nThe pgledger schema consists of the following\n\n- **Tables**\n    - **accounts**: Stores information about each account.\n    - **transfers**: Records transactions between accounts.\n    - **entries**: Stores detailed information about each transaction.\n\n- **Indexes**\n    - **accounts_id_idx**: Index on the accounts table for efficient lookup by ID.\n    - **transfers_from_account_id_idx**: Index on the transfers table for efficient lookup by from_account_id.\n    - **transfers_to_account_id_idx**: Index on the transfers table for efficient lookup by to_account_id.\n\n- **Functions**\n    - **create_account**: Creates a new account with the specified name, currency, and balance constraints.\n    - **create_transfer**: Records a transaction between two accounts.\n    - **check_account_balance_constraints**: Verifies that an account's balance complies with its constraints.\n\n## Usage of Pg Ledger\n\nOnce you've created the `pgledger.sql` schema in your Postgres instance, you can use it as follows.\n\n```sql\n-- Create a new account with the specified name, currency, and balance constraints\n-- Parameters: account name, currency, allow negative balance, allow positive balance\nSELECT *\nFROM create_account('My Account', 'USD', TRUE, TRUE);\n\n-- Record a transfer of a specified amount between two accounts\n-- Parameters: from account ID, to account ID, transfer amount\nSELECT *\nFROM create_transfer('account1', 'account2', 100.00);\n\n-- Check if an account's balance complies with its constraints (e.g. negative or positive balance)\n-- Parameter: account ID\nSELECT *\nFROM check_account_balance_constraints('account1');\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixelbend%2Fpg-ledger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpixelbend%2Fpg-ledger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixelbend%2Fpg-ledger/lists"}