|
| 1 | +# @topcoder/finance-prisma-client |
| 2 | + |
| 3 | +Prisma client package for TopCoder Finance API database. This package provides a factory function to create a Prisma client instance with a configurable database connection string. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @topcoder/finance-prisma-client |
| 9 | +``` |
| 10 | + |
| 11 | +Or via git repository: |
| 12 | + |
| 13 | +```bash |
| 14 | +npm install git+https://github.com/your-org/tc-finance-api.git#packages/finance-prisma-client |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +### Basic Usage |
| 20 | + |
| 21 | +```typescript |
| 22 | +import { createFinancePrismaClient } from '@topcoder/finance-prisma-client'; |
| 23 | + |
| 24 | +const prisma = createFinancePrismaClient('postgresql://user:password@localhost:5432/finance_db'); |
| 25 | + |
| 26 | +// Use the client |
| 27 | +const winnings = await prisma.winnings.findMany(); |
| 28 | +``` |
| 29 | + |
| 30 | +### With Options |
| 31 | + |
| 32 | +```typescript |
| 33 | +import { createFinancePrismaClient } from '@topcoder/finance-prisma-client'; |
| 34 | + |
| 35 | +const prisma = createFinancePrismaClient( |
| 36 | + 'postgresql://user:password@localhost:5432/finance_db', |
| 37 | + { |
| 38 | + log: ['query', 'info', 'warn', 'error'], |
| 39 | + transactionOptions: { |
| 40 | + timeout: 20000, // 20 seconds |
| 41 | + }, |
| 42 | + } |
| 43 | +); |
| 44 | +``` |
| 45 | + |
| 46 | +### Using Types |
| 47 | + |
| 48 | +```typescript |
| 49 | +import { |
| 50 | + createFinancePrismaClient, |
| 51 | + Prisma, |
| 52 | + payment_status, |
| 53 | + winnings |
| 54 | +} from '@topcoder/finance-prisma-client'; |
| 55 | + |
| 56 | +const prisma = createFinancePrismaClient(connectionString); |
| 57 | + |
| 58 | +// Use Prisma types |
| 59 | +const payment: Prisma.paymentCreateInput = { |
| 60 | + // ... |
| 61 | +}; |
| 62 | + |
| 63 | +// Use enum types |
| 64 | +const status: payment_status = 'PAID'; |
| 65 | + |
| 66 | +// Use model types |
| 67 | +const winning: winnings = await prisma.winnings.findFirst(); |
| 68 | +``` |
| 69 | + |
| 70 | +## Building |
| 71 | + |
| 72 | +Before using this package, you need to build it: |
| 73 | + |
| 74 | +```bash |
| 75 | +npm run build |
| 76 | +``` |
| 77 | + |
| 78 | +This will: |
| 79 | +1. Generate the Prisma client from the schema |
| 80 | +2. Compile TypeScript to JavaScript |
| 81 | + |
| 82 | +## Development |
| 83 | + |
| 84 | +When installing this package in development mode (e.g., via `npm install file:../path`), the `postinstall` script will automatically generate the Prisma client. |
| 85 | + |
| 86 | +## Requirements |
| 87 | + |
| 88 | +- Node.js >= 16 |
| 89 | +- Prisma >= 6.18.0 |
| 90 | +- PostgreSQL database |
| 91 | + |
| 92 | +## License |
| 93 | + |
| 94 | +UNLICENSED |
0 commit comments