Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pinia-orm/.eslintcache

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions packages/pinia-orm/src/repository/Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,39 @@ import type { WeakCache } from '../cache/WeakCache'
import { config as globalConfig } from '../store/Config'
import type { FilledInstallOptions } from '../store/Store'

export interface Repository<M extends Model = Model> {
/**
* Add a where clause where `field` value is in values.
*/
whereIn (field: string, values: any[] | Set<any>): Query<M>
/**
* Add a where clause where `field` value is in values or ...
*/
orWhereIn (field: string, values: any[] | Set<any>): Query<M>
/**
* Add a where clause where `field` value is not in values or ...
*/
orWhereNotIn (field: string, values: any[] | Set<any>): Query<M>
/**
* Add a where clause where `field` has not defined values
*/
whereNotIn (field: string, values: any[] | Set<any>): Query<M>
/**
* Add a where clause to get all results where `field` is null
*/
whereNull (field: string): Query<M>
/**
* Add a where clause to get all results where `field` is not null
*/
whereNotNull (field: string): Query<M>
/**
* Find the model with the given id.
*/
find (id: string | number): Item<M>
find (ids: (string | number)[]): Collection<M>
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class Repository<M extends Model = Model> {
[index: string]: any
/**
Expand Down
35 changes: 0 additions & 35 deletions packages/pinia-orm/src/types/repository.ts

This file was deleted.

3 changes: 3 additions & 0 deletions playgrounds/nuxt3/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script setup lang="ts">
import User from './models/User'
import { useRepo } from 'pinia-orm'
import { UserRepository } from './repositories/UserRepository'

const userRepo = useRepo(User)
const users = userRepo.save([
Expand All @@ -22,6 +23,8 @@ const users = userRepo.save([
],
},
])
const userCustomRepo = useRepo(UserRepository)
const newUser = userCustomRepo.find(1)
console.log(userRepo.with('todos').get())

onBeforeMount(() => {
Expand Down
10 changes: 10 additions & 0 deletions playgrounds/nuxt3/repositories/UserRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Repository } from "pinia-orm"
import User from "~/models/User"

export class UserRepository extends Repository<User> {
use = User

custom (): number {
return 1
}
}