8000 refactor: small modifications to the validation doc · adonisjs/lucid.adonisjs.com@16a9c77 · GitHub
[go: up one dir, main page]

Skip to content

Commit 16a9c77

Browse files
committed
refactor: small modifications to the validation doc
1 parent 334990c commit 16a9c77

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

content/docs/guides/validation.md

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ The rule is a macro for `VineString` and `VineNumber`, so you can use it after `
3434

3535
You may either pass a callback to query the database directly, or an object:
3636

37-
- The callback must return `true` if the value is unique (does not exist), or `false` if the value already exists.
38-
- You may also pass an options object to specify the table and column.
37+
- The [callback](https://github.com/adonisjs/lucid/blob/21.x/src/types/vine.ts#L61-L65) must return `true` if the value is unique (does not exist), or `false` if the value already exists.
38+
- You may also pass an [options object](https://github.com/adonisjs/lucid/blob/21.x/src/types/vine.ts#L17-L55) to specify the table and column.
3939

4040
```ts
4141
// Usage with callback
@@ -56,22 +56,10 @@ const schema = vine.object({
5656
.string()
5757
// highlight-start
5858
.unique({ table: 'users', column: 'email' }),
59-
// highlight-end
59+
// highlight-end
6060
})
6161
```
6262

63-
Following is the list of available parameters for the unique rule:
64-
65-
```ts
66-
type UniqueRuleCallback = (db: Database, value: string, field: FieldContext) => Promise<boolean>
67-
68-
type UniqueRuleOptions = {
69-
table: string
70-
column?: string
71-
filter?: (db: DatabaseQueryBuilderContract, value: unknown, field: FieldContext) => Promise<void>
72-
}
73-
```
74-
7563
You may also use your Lucid model directly inside the callback:
7664

7765
```ts
@@ -81,7 +69,7 @@ const schema = vine.object({
8169
// highlight-start
8270
.unique((_, value) => {
8371
const row = await User.findBy('email', value)
84-
return row === null
72+
return row ? false : true
8573
}),
8674
// highlight-end
8775
})
@@ -97,8 +85,8 @@ The rule is also a macro for `VineString` and `VineNumber`, so you can use it af
9785

9886
You may either pass a callback to query the database directly, or an object:
9987

100-
- The callback must return `true` if the value exists, `false` otherwise.
101-
- You may also pass an option object to specify the table and column.
88+
- The [callback](https://github.com/adonisjs/lucid/blob/21.x/src/types/vine.ts#L61-L65) must return `true` if the value exists, `false` otherwise.
89+
- You may also pass an [options object](https://github.com/adonisjs/lucid/blob/21.x/src/types/vine.ts#L17-L55) to specify the table and column.
10290

10391
```ts
10492
// Usage with callback
@@ -122,15 +110,3 @@ const schema = vine.object({
122110
// highlight-end
123111
})
124112
```
125-
126-
Following is the list of available parameters for the exists rule:
127-
128-
```ts
129-
type ExistsRuleCallback = (db: Database, value: string, field: FieldContext) => Promise<boolean>
130-
131-
type ExistsRuleOptions = {
132-
table: string
133-
column?: string
134-
filter?: (db: DatabaseQueryBuilderContract, value: unknown, field: FieldContext) => Promise<void>
135-
}
136-
```

0 commit comments

Comments
 (0)
0