caspian-utils 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,7 @@ This page documents the Prisma workflow for Caspian projects where `caspian.conf
16
16
 
17
17
  When a project enables Prisma, use `prisma/schema.prisma` for schema management, `prisma.config.ts` for Prisma config and seed wiring, and reuse an app-owned `src/lib/prisma/` package when the project includes one.
18
18
 
19
- High-priority rule: when `caspian.config.json` has `prisma: true`, Python-side database access must use the generated Prisma Python ORM. Route `page()` functions, route-owned `@rpc()` actions, auth handlers, upload flows, and shared helpers should import the generated client from `src/lib/prisma/**` instead of inventing direct driver calls, hand-written SQL wrappers, JSON manifests as active stores, app-specific HTTP fetches, or browser-side database fetches. Use raw SQL only through Prisma as a narrow fallback when the generated ORM cannot express a query clearly.
19
+ High-priority rule: when `caspian.config.json` has `prisma: true`, Python-side database access must use the generated Prisma Python ORM. Route `page()` functions, route-owned `@rpc()` actions, auth handlers, upload flows, and shared helpers should import the generated client from `src/lib/prisma/**` instead of inventing direct driver calls, hand-written SQL wrappers, JSON manifests as active stores, app-specific HTTP fetches, or browser-side database fetches. For normal reads and writes, default to Prisma methods such as `find_many`, `find_unique`, `create`, `update`, `delete`, `delete_many`, aggregates, includes, and transactions. Use raw SQL only through Prisma as a narrow fallback when the generated ORM cannot express a query clearly, and treat that fallback as provider-specific code that may break when a project moves between SQLite, MySQL, and PostgreSQL.
20
20
 
21
21
  Treat `caspian.config.json` as the single source of truth for whether Prisma is enabled in a workspace. If `prisma` is false and the user wants Prisma, ask first, then update `caspian.config.json` and run `npx casp update project` before assuming Prisma-managed files exist.
22
22
 
@@ -31,7 +31,7 @@ The standard Prisma flow in Caspian is:
31
31
  5. Run `npx ppy generate` so the Python ORM classes stay aligned with the updated schema.
32
32
  6. Reuse the shared Python database layer in `src/lib/prisma/` when Python route or RPC code needs database access, and never hand-edit generated ORM classes.
33
33
 
34
- Use this workflow instead of writing raw SQL first. Drop to raw SQL only through Prisma when a query cannot be expressed clearly with the generated client.
34
+ Use this workflow instead of writing raw SQL first. For normal CRUD and relation work, stay on the generated Prisma API. Drop to raw SQL only through Prisma when a query cannot be expressed clearly with the generated client, and assume that raw SQL requires extra review for cross-database portability.
35
35
 
36
36
  ## Environment Setup
37
37
 
@@ -49,7 +49,7 @@ Example for PostgreSQL in async-friendly production environments:
49
49
  DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
50
50
  ```
51
51
 
52
- For most local development, SQLite is the simplest starting point. For production or higher concurrency workloads, prefer PostgreSQL or MySQL.
52
+ For most local development, SQLite is the simplest starting point. For production or higher concurrency workloads, prefer PostgreSQL or MySQL. Regardless of the starting provider, keep application queries on the Prisma ORM whenever possible so schema and query behavior stay easier to migrate across providers.
53
53
 
54
54
  ## Global Prisma Configuration
55
55
 
@@ -318,16 +318,27 @@ async with prisma.transaction() as tx:
318
318
  )
319
319
  ```
320
320
 
321
- ### Raw SQL Fallback
322
-
323
- ```python
324
- users = await prisma.query_raw(
325
- "SELECT * FROM User WHERE email LIKE ?",
326
- "%@gmail.com",
327
- )
328
- ```
329
-
330
- Use raw SQL sparingly and only through Prisma. Prefer the generated Prisma API when the query can be expressed clearly there.
321
+ ### Raw SQL Fallback
322
+
323
+ Use this escape hatch sparingly. Raw SQL is not the default query style in a Prisma-enabled Caspian project.
324
+
325
+ Before using `query_raw()` or `execute_raw()`, confirm that the generated Prisma API cannot express the query clearly with normal methods such as `find_many`, `find_unique`, `create`, `update`, `delete`, `delete_many`, `aggregate`, relation `include`, or transactions.
326
+
327
+ Important portability warning:
328
+
329
+ - Raw SQL is provider-specific. Placeholder style, identifier quoting, JSON operators, case-sensitivity rules, date functions, and aggregate behavior can differ across SQLite, MySQL, and PostgreSQL.
330
+ - A raw query that works in SQLite may fail after a move to PostgreSQL or MySQL even when the Prisma schema migrates cleanly.
331
+ - If a project may switch providers, prefer Prisma ORM methods first and treat raw SQL as an exception that needs provider-aware review.
332
+
333
+ ```python
334
+ users = await prisma.user.find_many(
335
+ where={
336
+ "email": {"contains": "@gmail.com"},
337
+ },
338
+ )
339
+ ```
340
+
341
+ If raw SQL is still unavoidable, keep it tightly scoped, document why the ORM was insufficient, and verify it against the current datasource provider in `prisma/schema.prisma`.
331
342
 
332
343
  ## Recommended Project Rules
333
344
 
@@ -339,7 +350,7 @@ Use raw SQL sparingly and only through Prisma. Prefer the generated Prisma API w
339
350
  - Use `await` with Prisma operations.
340
351
  - Convert Prisma objects to template-safe dictionaries when rendering HTML.
341
352
  - Validate incoming mutation data before calling `create`, `update`, or `delete` operations.
342
- - Prefer Prisma queries over raw SQL, and prefer raw SQL over undocumented custom query helpers.
353
+ - Prefer Prisma queries over raw SQL. If raw SQL is unavoidable, keep it provider-aware, narrowly scoped, and documented so future database-provider migrations do not silently break application behavior.
343
354
 
344
355
  ## AI Retrieval Notes
345
356
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caspian-utils",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Caspian tooling",
5
5
  "main": "index.js",
6
6
  "scripts": {