yii2-to-prisma
SKILL.md
Yii2 to Prisma Transformation Skill
This skill provides a systematic approach to convert PHP Yii2 database queries into TypeScript/JavaScript Prisma Client queries.
Query Syntax Mapping
1. Basic Operations
| Yii2 (PHP) | Prisma (TypeScript) | Comment |
|---|---|---|
User::find() |
prisma.user.findMany() |
Basic multi-row fetch |
User::findOne($id) |
prisma.user.findUnique({ where: { id: $id } }) |
Fetch by ID |
User::find()->count() |
prisma.user.count() |
Count |
User::find()->exists() |
prisma.user.findFirst({ select: { id: true } }) !== null |
Existence check |
2. Filters (where)
| Yii2 | Prisma |
|---|---|
->where(['id' => 1]) |
where: { id: 1 } |
->andWhere(['status' => 1]) |
where: { AND: [ { status: 1 } ] } (or just merge if simple) |
->orWhere(['status' => 1]) |
where: { OR: [ { status: 1 } ] } |
->where(['>', 'age', 18]) |
where: { age: { gt: 18 } } |
->where(['in', 'id', [1, 2]]) |
where: { id: { in: [1, 2] } } |
->where(['like', 'name', 'john']) |
where: { name: { contains: 'john', mode: 'insensitive' } } |
3. Relations
| Yii2 | Prisma |
|---|---|
->joinWith('profile') |
include: { profile: true } |
->with(['posts', 'comments']) |
include: { posts: true, comments: true } |
->select(['id', 'email']) |
select: { id: true, email: true } |
4. Pagination and Sorting
| Yii2 | Prisma |
|---|---|
->orderBy('created_at DESC') |
orderBy: { created_at: 'desc' } |
->limit(10) |
take: 10 |
->offset(20) |
skip: 20 |
Transformation Rules
- CamelCase Conversion: Ensure that field names in Yii2 (often snake_case) are mapped correctly to the Prisma schema (often camelCase).
- Boolean Mapping: Yii2 often uses
0and1for booleans. Prisma usestrueandfalse. - Date Handling: Yii2 might use Unix timestamps or SQL dates. Prisma uses JS
Dateobjects. - Nested Relations: Yii2
joinWithcan be nested using dot notation (->joinWith('a.b')). Prisma uses nestedinclude.
Examples
Complex Query
Yii2:
$results = Product::find()
->select(['id', 'name', 'price'])
->joinWith('category')
->where(['category.slug' => 'electronics'])
->andWhere(['>', 'price', 100])
->orderBy('price DESC')
->limit(5)
->all();
Prisma:
const results = await prisma.product.findMany({
select: {
id: true,
name: true,
price: true,
category: true,
},
where: {
category: {
slug: 'electronics',
},
price: {
gt: 100,
},
},
orderBy: {
price: 'desc',
},
take: 5,
});
Weekly Installs
3
Repository
egalvez-svg/mis-skillsFirst Seen
6 days ago
Security Audits
Installed on
cline3
gemini-cli3
github-copilot3
codex3
kimi-cli3
cursor3