prax-orm 0.11.0

A next-generation, type-safe ORM for Rust inspired by Prisma
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
---
import DocsLayout from '../../layouts/DocsLayout.astro';
import CodeBlock from '../../components/CodeBlock.astro';

// Field Attributes
const fieldAttrsBasic = `model User {
    id        Int      @id              // Primary key
    count     Int      @auto            // Auto-increment
    email     String   @unique          // Unique constraint
    active    Boolean  @default(true)   // Default value
    createdAt DateTime @default(now())  // Function default
    updatedAt DateTime @updatedAt       // Auto-update timestamp
    firstName String   @map("first_name") // Column name mapping
    data      Json?    @ignore          // Ignore in client
}`;

const fieldAttrsAdvanced = `model Post {
    // UUID with auto-generation
    id        String   @id @default(uuid())

    // CUID alternatives
    publicId  String   @default(cuid())
    shortId   String   @default(nanoid())
    sortId    String   @default(ulid())

    // Database-specific column types
    content   String   @db.Text
    price     Decimal  @db.Decimal(10, 2)
    metadata  Json     @db.JsonB

    // Relation with custom name
    author    User     @relation("PostAuthor")
}`;

// Model Attributes
const modelAttrs = `model User {
    id       Int    @id @auto
    email    String
    tenantId Int
    role     String

    // Map to different table name
    @@map("users")

    // Single-field index
    @@index([email])

    // Composite index with name
    @@index([tenantId, role], name: "tenant_role_idx")

    // Composite unique constraint
    @@unique([email, tenantId])

    // Composite primary key
    @@id([tenantId, id])

    // Full-text search index (PostgreSQL)
    @@index([name, bio], type: GIN)
}`;

// Relation Attributes
const relationAttrs = `model Post {
    id       Int  @id @auto
    author   User @relation(
        fields: [authorId],      // Foreign key field(s)
        references: [id],        // Referenced field(s)
        name: "UserPosts",       // Relation name (for disambiguation)
        onDelete: Cascade,       // Delete behavior
        onUpdate: Cascade        // Update behavior
    )
    authorId Int
}

model Comment {
    id       Int  @id @auto
    // Self-relation example
    parent   Comment?  @relation("CommentReplies", fields: [parentId], references: [id])
    parentId Int?
    replies  Comment[] @relation("CommentReplies")
}`;

// String Validators
const stringValidators = `model User {
    // Email format validation
    email       String  @validate.email

    // URL format validation
    website     String? @validate.url

    // ID format validators
    externalId  String  @validate.uuid
    trackingId  String  @validate.cuid
    shortCode   String  @validate.nanoid
    sortableId  String  @validate.ulid

    // Length constraints
    username    String  @validate.minLength(3) @validate.maxLength(30)
    bio         String? @validate.length(10, 500)

    // Pattern matching
    phone       String  @validate.regex("^\\+[1-9]\\d{1,14}$")
    slug        String  @validate.slug

    // Content validators
    firstName   String  @validate.alpha
    code        String  @validate.alphanumeric
    lowerName   String  @validate.lowercase
    upperCode   String  @validate.uppercase

    // String content
    searchTerm  String  @validate.startsWith("search:")
    filePath    String  @validate.endsWith(".json")
    keywords    String  @validate.contains("prax")

    // Whitespace handling
    cleanInput  String  @validate.trim
    noSpaces    String  @validate.noWhitespace

    // Network validators
    ipAddress   String  @validate.ip
    ipv4Only    String  @validate.ipv4
    ipv6Only    String  @validate.ipv6

    // Format validators
    cardNumber  String  @validate.creditCard
    phoneNum    String  @validate.phone
    hexColor    String  @validate.hex
    encoded     String  @validate.base64
    jsonStr     String  @validate.json
}`;

// Numeric Validators
const numericValidators = `model Product {
    // Range constraints
    price       Decimal @validate.min(0)
    discount    Int     @validate.max(100)
    quantity    Int     @validate.range(0, 10000)

    // Sign validators
    rating      Float   @validate.positive
    adjustment  Int     @validate.negative
    balance     Decimal @validate.nonNegative
    debt        Decimal @validate.nonPositive

    // Type validators
    wholeNumber Float   @validate.integer
    percentage  Float   @validate.multipleOf(0.01)
    safeNumber  Float   @validate.finite
}`;

// Array Validators
const arrayValidators = `model Post {
    // Array length constraints
    tags        String[] @validate.minItems(1)
    categories  String[] @validate.maxItems(5)
    keywords    String[] @validate.items(1, 10)

    // Array content validators
    uniqueTags  String[] @validate.unique
    requiredArr String[] @validate.nonEmpty
}`;

// Date Validators
const dateValidators = `model Event {
    // Relative date validators
    birthDate   DateTime @validate.past
    eventDate   DateTime @validate.future
    lastLogin   DateTime @validate.pastOrPresent
    nextReview  DateTime @validate.futureOrPresent

    // Absolute date constraints
    startDate   DateTime @validate.after("2024-01-01")
    endDate     DateTime @validate.before("2025-12-31")
}`;

// General Validators
const generalValidators = `model User {
    // Required even if type is optional
    middleName  String? @validate.required

    // Non-empty (works with strings, arrays, etc.)
    nickname    String  @validate.notEmpty

    // Enum-like constraint
    status      String  @validate.oneOf("active", "inactive", "pending")
    role        String  @validate.oneOf("admin", "user", "guest")

    // Custom validator function
    password    String  @validate.custom("strongPassword")
}`;

// ID Generation - UUID
const uuidExamples = `model User {
    // UUID v4 as primary key (recommended for distributed systems)
    id        String   @id @default(uuid())

    // UUID with native database type (PostgreSQL)
    id        String   @id @default(uuid()) @db.Uuid
}

model Session {
    // UUID for non-primary key fields
    id        Int      @id @auto
    token     String   @unique @default(uuid())
}

// Example generated values:
// "550e8400-e29b-41d4-a716-446655440000"
// "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
// "f47ac10b-58cc-4372-a567-0e02b2c3d479"`;

// ID Generation - CUID
const cuidExamples = `model Post {
    // CUID as primary key (collision-resistant, sortable)
    id        String   @id @default(cuid())

    // CUID for public-facing IDs
    slug      String   @unique @default(cuid())
}

model ApiKey {
    // CUID2 - more secure, shorter (next generation)
    id        Int      @id @auto
    key       String   @unique @default(cuid2())
}

// CUID example values (25 chars, starts with 'c'):
// "cjld2cjxh0000qzrmn831i7rn"
// "cjld2cyuq0000t3rmniod1foy"

// CUID2 example values (24 chars, random start):
// "tz4a98xxat96iws9zmbrgj3a"
// "pfh0haxfpzowht3oi213cqos"`;

// ID Generation - NanoID
const nanoidExamples = `model ShortUrl {
    // NanoID - URL-friendly, customizable length
    id        String   @id @default(nanoid())     // 21 chars default
    code      String   @unique @default(nanoid(8)) // 8 chars custom
}

model InviteCode {
    id        Int      @id @auto
    // Short codes for sharing
    code      String   @unique @default(nanoid(6))
}

// NanoID example values (21 chars default):
// "V1StGXR8_Z5jdHi6B-myT"
// "FwcE6X9N4f7kLpQrS2hJm"

// NanoID(8) example values:
// "5fX8pK2m"
// "R9qW3vNx"`;

// ID Generation - ULID
const ulidExamples = `model Event {
    // ULID - sortable by creation time
    id        String   @id @default(ulid())
}

model LogEntry {
    // ULID preserves insertion order
    id        String   @id @default(ulid())
    level     String
    message   String
    timestamp DateTime @default(now())
}

// ULID example values (26 chars, time-sortable):
// "01ARZ3NDEKTSV4RRFFQ69G5FAV"
// "01BX5ZZKBKACTAV9WEVGEMMVRY"
// Structure: TTTTTTTTTTSSSSSSSSSSSSSSSS
//            |---------|--------------|
//            timestamp    randomness`;

// ID Generation Comparison
const idComparison = `// Choose the right ID type for your use case:

model Example {
    // UUID v4 - Universal, widely supported
    // ✓ Standard format (RFC 4122)
    // ✓ Native database support (PostgreSQL UUID type)
    // ✗ Not sortable by creation time
    // ✗ Longer (36 chars with dashes)
    uuidId      String @default(uuid())

    // CUID - Collision-resistant, horizontal scaling
    // ✓ Sortable (roughly by creation time)
    // ✓ URL-safe characters
    // ✓ Designed for distributed systems
    // ✗ Longer than NanoID (25 chars)
    cuidId      String @default(cuid())

    // CUID2 - Next generation CUID
    // ✓ More secure (unpredictable)
    // ✓ Shorter than CUID (24 chars)
    // ✓ Better entropy distribution
    // ✗ Not sortable by time
    cuid2Id     String @default(cuid2())

    // NanoID - Compact, customizable
    // ✓ URL-safe (A-Za-z0-9_-)
    // ✓ Customizable length
    // ✓ Smaller than UUID (21 chars default)
    // ✗ Not sortable by time
    nanoidId    String @default(nanoid())

    // ULID - Time-sortable
    // ✓ Lexicographically sortable
    // ✓ Encodes timestamp (first 10 chars)
    // ✓ Compatible with UUID format
    // ✗ Timestamp can leak creation time
    ulidId      String @default(ulid())

    // Auto-increment - Simple sequential
    // ✓ Smallest storage (integer)
    // ✓ Natural ordering
    // ✗ Reveals record count
    // ✗ Not suitable for distributed systems
    autoId      Int    @auto
}`;

// Default Value Functions
const defaultFunctions = `model Record {
    // Timestamp functions
    createdAt   DateTime @default(now())

    // UUID generation (v4)
    id          String   @default(uuid())

    // CUID generation (collision-resistant)
    publicId    String   @default(cuid())

    // CUID2 (next generation, more secure)
    trackingId  String   @default(cuid2())

    // NanoID (URL-friendly, customizable)
    shortId     String   @default(nanoid())
    customId    String   @default(nanoid(10))  // Custom length

    // ULID (sortable)
    sortableId  String   @default(ulid())

    // Auto-increment (integers)
    sequence    Int      @default(autoincrement())

    // Database sequence
    orderNum    Int      @default(dbgenerated("nextval('order_seq')"))

    // Static defaults
    active      Boolean  @default(true)
    role        String   @default("user")
    count       Int      @default(0)
    tags        String[] @default([])
}`;

// Database-specific Attributes
const dbSpecific = `model Document {
    // PostgreSQL types
    id          Int      @id @auto
    data        Json     @db.JsonB           // JSONB for indexing
    content     String   @db.Text            // TEXT type
    amount      Decimal  @db.Decimal(19, 4)  // DECIMAL(19,4)
    small       Int      @db.SmallInt        // SMALLINT
    big         BigInt   @db.BigInt          // BIGINT
    uuid        String   @db.Uuid            // UUID type
    xml         String   @db.Xml             // XML type
    inet        String   @db.Inet            // INET type
    cidr        String   @db.Cidr            // CIDR type
    macaddr     String   @db.MacAddr         // MACADDR type

    // MySQL types
    tinyText    String   @db.TinyText
    mediumText  String   @db.MediumText
    longText    String   @db.LongText
    tinyInt     Int      @db.TinyInt
    mediumInt   Int      @db.MediumInt
    year        Int      @db.Year

    // Column charset (MySQL)
    name        String   @db.VarChar(255) @db.Charset("utf8mb4")
}`;

// Documentation Attributes
const docAttrs = `model User {
    /// @hidden - Exclude from public API
    internalId  String

    /// @internal - Admin-only visibility
    debugInfo   Json?

    /// @sensitive - Mask in logs
    ssn         String?

    /// @readonly - Cannot be set via API
    createdAt   DateTime @default(now())

    /// @writeonly - Not returned in responses
    password    String

    /// @deprecated Use 'email' instead
    /// @since 1.0.0
    oldEmail    String?

    /// @example "john@example.com"
    /// @label "Email Address"
    /// @placeholder "Enter your email"
    email       String

    /// @group "Personal Info"
    /// @order 1
    firstName   String

    /// @alias "userName"
    /// @json "user_name"
    username    String
}`;

// Index Types
const indexTypes = `model SearchDocument {
    id       Int    @id @auto
    title    String
    content  String
    tags     String[]
    location Json

    // B-Tree index (default)
    @@index([title])

    // Hash index (equality only)
    @@index([id], type: Hash)

    // GIN index (arrays, JSONB, full-text)
    @@index([tags], type: GIN)
    @@index([content], type: GIN)  // Full-text search

    // GiST index (geometric, full-text)
    @@index([location], type: GiST)

    // BRIN index (large sorted tables)
    @@index([createdAt], type: BRIN)

    // Partial index with condition
    @@index([email], where: "active = true")

    // Unique index with nulls handling
    @@unique([email], nulls: NotDistinct)
}`;

// Vector Index Types
const vectorIndexTypes = `// Vector indexes for AI/ML similarity search (requires pgvector)
// Database URL is configured in prax.toml, not in the schema
datasource db {
    provider   = "postgresql"
    extensions = [vector]
}

model Document {
    id        Int          @id @auto
    title     String
    content   String
    embedding Vector(1536)  // OpenAI embedding dimension

    // HNSW index - best recall, recommended for most use cases
    @@index([embedding], type: Hnsw, ops: Cosine)
}

model ImageSearch {
    id       Int        @id @auto
    features Vector(512)

    // IVFFlat index - faster builds for large datasets
    @@index([features], type: IvfFlat, ops: L2, lists: 100)
}

model AdvancedSearch {
    id        Int          @id @auto
    embedding Vector(768)

    // HNSW with custom parameters
    @@index([embedding], type: Hnsw, ops: Cosine, m: 32, ef_construction: 128)

    // Inner product for max similarity
    @@index([embedding], type: Hnsw, ops: InnerProduct, name: "ip_idx")
}

// Index Type Options:
// - type: Hnsw | IvfFlat
// - ops: Cosine | L2 | InnerProduct
// - m: HNSW connections (default 16)
// - ef_construction: HNSW build quality (default 64)
// - lists: IVFFlat clusters (default 100)`;

// Index types reference table
const indexTypesTable = [
  { type: 'BTree', use: 'Default, range queries, sorting', pg: '✅', mysql: '✅', sqlite: '✅' },
  { type: 'Hash', use: 'Equality comparisons only', pg: '✅', mysql: '✅', sqlite: '❌' },
  { type: 'GIN', use: 'Arrays, JSONB, full-text', pg: '✅', mysql: '❌', sqlite: '❌' },
  { type: 'GiST', use: 'Geometric, full-text, ranges', pg: '✅', mysql: '❌', sqlite: '❌' },
  { type: 'BRIN', use: 'Large sorted tables', pg: '✅', mysql: '❌', sqlite: '❌' },
  { type: 'Hnsw', use: 'Vector similarity (best recall)', pg: '✅*', mysql: '❌', sqlite: '❌' },
  { type: 'IvfFlat', use: 'Vector similarity (fast build)', pg: '✅*', mysql: '❌', sqlite: '❌' },
];

const vectorOpsTable = [
  { op: 'Cosine', desc: 'Cosine distance (1 - similarity)', best: 'Text embeddings (normalized)' },
  { op: 'L2', desc: 'Euclidean distance', best: 'Image features (unnormalized)' },
  { op: 'InnerProduct', desc: 'Negative inner product', best: 'Max inner product search' },
];
---

<DocsLayout title="Attributes - Prax ORM">
  <article class="max-w-4xl mx-auto px-6 py-12">
    <header class="mb-12">
      <h1 class="text-4xl font-bold mb-4">Attributes</h1>
      <p class="text-xl text-muted">
        Configure field and model behavior with powerful attributes and validators.
      </p>
    </header>

    <nav class="mb-12 p-4 bg-surface-elevated rounded-lg">
      <h3 class="text-sm font-semibold text-muted uppercase tracking-wider mb-3">On this page</h3>
      <ul class="grid grid-cols-2 md:grid-cols-3 gap-2 text-sm">
        <li><a href="/schema/attributes#field-attrs" class="text-accent hover:underline">Field Attributes</a></li>
        <li><a href="/schema/attributes#model-attrs" class="text-accent hover:underline">Model Attributes</a></li>
        <li><a href="/schema/attributes#relations" class="text-accent hover:underline">Relation Attributes</a></li>
        <li><a href="/schema/attributes#id-generation" class="text-accent hover:underline">ID Generation</a></li>
        <li><a href="/schema/attributes#string-validators" class="text-accent hover:underline">String Validators</a></li>
        <li><a href="/schema/attributes#numeric-validators" class="text-accent hover:underline">Numeric Validators</a></li>
        <li><a href="/schema/attributes#array-validators" class="text-accent hover:underline">Array Validators</a></li>
        <li><a href="/schema/attributes#date-validators" class="text-accent hover:underline">Date Validators</a></li>
        <li><a href="/schema/attributes#general-validators" class="text-accent hover:underline">General Validators</a></li>
        <li><a href="/schema/attributes#defaults" class="text-accent hover:underline">Default Functions</a></li>
        <li><a href="/schema/attributes#db-specific" class="text-accent hover:underline">Database Types</a></li>
        <li><a href="/schema/attributes#documentation" class="text-accent hover:underline">Documentation</a></li>
        <li><a href="/schema/attributes#index-types" class="text-accent hover:underline">Index Types</a></li>
        <li><a href="/schema/attributes#vector-indexes" class="text-accent hover:underline">Vector Indexes</a></li>
      </ul>
    </nav>

    <div class="space-y-16">
      <!-- Field Attributes -->
      <section id="field-attrs">
        <h2 class="text-2xl font-semibold mb-4">Field Attributes</h2>
        <p class="text-muted mb-4">
          Field attributes modify individual field behavior, constraints, and mapping.
        </p>

        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm">
            <thead>
              <tr class="border-b border-border">
                <th class="text-left py-2 pr-4 font-semibold">Attribute</th>
                <th class="text-left py-2 font-semibold">Description</th>
              </tr>
            </thead>
            <tbody class="divide-y divide-border">
              <tr><td class="py-2 pr-4"><code>&#64;id</code></td><td>Marks field as primary key</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;auto</code></td><td>Auto-increment for integers</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;unique</code></td><td>Unique constraint</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;default(value)</code></td><td>Default value or function</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;updatedAt</code></td><td>Auto-update timestamp on modification</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;map("name")</code></td><td>Map to different column name</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;ignore</code></td><td>Exclude from generated client</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;relation(...)</code></td><td>Configure relation behavior</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;db.Type</code></td><td>Database-specific column type</td></tr>
            </tbody>
          </table>
        </div>

        <h3 class="text-lg font-medium mb-3">Basic Usage</h3>
        <CodeBlock code={fieldAttrsBasic} lang="prax" filename="prax/schema.prax" />

        <h3 class="text-lg font-medium mb-3 mt-6">Advanced Usage</h3>
        <CodeBlock code={fieldAttrsAdvanced} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- Model Attributes -->
      <section id="model-attrs">
        <h2 class="text-2xl font-semibold mb-4">Model Attributes</h2>
        <p class="text-muted mb-4">
          Model-level attributes (prefixed with <code>&#64;&#64;</code>) configure table-wide behavior.
        </p>

        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm">
            <thead>
              <tr class="border-b border-border">
                <th class="text-left py-2 pr-4 font-semibold">Attribute</th>
                <th class="text-left py-2 font-semibold">Description</th>
              </tr>
            </thead>
            <tbody class="divide-y divide-border">
              <tr><td class="py-2 pr-4"><code>&#64;&#64;map("name")</code></td><td>Map to different table name</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;&#64;id([fields])</code></td><td>Composite primary key</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;&#64;unique([fields])</code></td><td>Composite unique constraint</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;&#64;index([fields])</code></td><td>Create database index</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;&#64;ignore</code></td><td>Exclude model from client</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;&#64;schema("name")</code></td><td><strong>Not yet supported</strong> — per-model schema assignment has no effect in the DSL and is a compile error in the derive macro</td></tr>
            </tbody>
          </table>
        </div>

        <CodeBlock code={modelAttrs} lang="prax" filename="prax/schema.prax" />

        <div class="mt-4 p-4 rounded-xl bg-info-500/10 border border-info-500/30">
          <p class="text-info-400 text-sm">
            <strong>Note:</strong> On the Rust derive side (<code>#[derive(Model)]</code>), unknown
            <code>#[prax(...)]</code> attribute keys are compile errors in v0.11 — the macro rejects
            them rather than silently ignoring them.
          </p>
        </div>
      </section>

      <!-- Relation Attributes -->
      <section id="relations">
        <h2 class="text-2xl font-semibold mb-4">Relation Attributes</h2>
        <p class="text-muted mb-4">
          Configure how models relate to each other with referential actions.
        </p>

        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm">
            <thead>
              <tr class="border-b border-border">
                <th class="text-left py-2 pr-4 font-semibold">Parameter</th>
                <th class="text-left py-2 font-semibold">Description</th>
              </tr>
            </thead>
            <tbody class="divide-y divide-border">
              <tr><td class="py-2 pr-4"><code>fields</code></td><td>Local foreign key field(s)</td></tr>
              <tr><td class="py-2 pr-4"><code>references</code></td><td>Referenced field(s) on related model</td></tr>
              <tr><td class="py-2 pr-4"><code>name</code></td><td>Relation name for disambiguation</td></tr>
              <tr><td class="py-2 pr-4"><code>onDelete</code></td><td>Action when referenced record deleted</td></tr>
              <tr><td class="py-2 pr-4"><code>onUpdate</code></td><td>Action when referenced key updated</td></tr>
            </tbody>
          </table>
        </div>

        <h3 class="text-lg font-medium mb-3">Referential Actions</h3>
        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm">
            <thead>
              <tr class="border-b border-border">
                <th class="text-left py-2 pr-4 font-semibold">Action</th>
                <th class="text-left py-2 font-semibold">Behavior</th>
              </tr>
            </thead>
            <tbody class="divide-y divide-border">
              <tr><td class="py-2 pr-4"><code>Cascade</code></td><td>Delete/update related records</td></tr>
              <tr><td class="py-2 pr-4"><code>Restrict</code></td><td>Prevent delete/update if references exist</td></tr>
              <tr><td class="py-2 pr-4"><code>NoAction</code></td><td>Similar to Restrict (database-dependent)</td></tr>
              <tr><td class="py-2 pr-4"><code>SetNull</code></td><td>Set foreign key to NULL</td></tr>
              <tr><td class="py-2 pr-4"><code>SetDefault</code></td><td>Set foreign key to default value</td></tr>
            </tbody>
          </table>
        </div>

        <CodeBlock code={relationAttrs} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- ID Generation -->
      <section id="id-generation">
        <h2 class="text-2xl font-semibold mb-4">ID Generation</h2>
        <p class="text-muted mb-4">
          Prax supports multiple ID generation strategies for different use cases.
          Choose the right one based on your requirements for uniqueness, sortability, and distribution.
        </p>

        <!-- UUID -->
        <div class="mb-8">
          <h3 class="text-xl font-semibold mb-3 flex items-center gap-2">
            <span class="px-2 py-1 bg-blue-500/20 text-blue-400 rounded text-sm font-mono">uuid()</span>
            UUID v4
          </h3>
          <p class="text-muted mb-4">
            Universally Unique Identifier - the industry standard for distributed systems.
            Generates 128-bit identifiers with extremely low collision probability.
          </p>

          <div class="grid md:grid-cols-2 gap-4 mb-4">
            <div class="p-4 bg-green-500/10 border border-green-500/20 rounded-lg">
              <h4 class="font-semibold text-green-400 mb-2">Advantages</h4>
              <ul class="text-sm space-y-1 text-muted">
                <li>• RFC 4122 standard format</li>
                <li>• Native PostgreSQL <code>UUID</code> type support</li>
                <li>• Widely recognized and supported</li>
                <li>• Cryptographically random (v4)</li>
                <li>• No central coordination needed</li>
              </ul>
            </div>
            <div class="p-4 bg-red-500/10 border border-red-500/20 rounded-lg">
              <h4 class="font-semibold text-red-400 mb-2">Considerations</h4>
              <ul class="text-sm space-y-1 text-muted">
                <li>• 36 characters with dashes</li>
                <li>• Not sortable by creation time</li>
                <li>• Random distribution (index fragmentation)</li>
                <li>• Larger storage than auto-increment</li>
              </ul>
            </div>
          </div>

          <div class="p-3 bg-surface-elevated rounded-lg mb-4">
            <span class="text-xs text-muted uppercase tracking-wider">Example Output</span>
            <code class="block mt-1 text-accent font-mono">550e8400-e29b-41d4-a716-446655440000</code>
          </div>

          <CodeBlock code={uuidExamples} lang="prax" filename="prax/schema.prax" />
        </div>

        <!-- CUID -->
        <div class="mb-8">
          <h3 class="text-xl font-semibold mb-3 flex items-center gap-2">
            <span class="px-2 py-1 bg-purple-500/20 text-purple-400 rounded text-sm font-mono">cuid()</span>
            CUID
          </h3>
          <p class="text-muted mb-4">
            Collision-resistant Unique Identifier - designed for horizontal scaling and distributed systems.
            Includes a timestamp component for rough time-ordering.
          </p>

          <div class="grid md:grid-cols-2 gap-4 mb-4">
            <div class="p-4 bg-green-500/10 border border-green-500/20 rounded-lg">
              <h4 class="font-semibold text-green-400 mb-2">Advantages</h4>
              <ul class="text-sm space-y-1 text-muted">
                <li>• Roughly sortable by creation time</li>
                <li>• URL-safe characters only</li>
                <li>• Designed for distributed systems</li>
                <li>• Shorter than UUID (25 chars)</li>
                <li>• Includes machine fingerprint</li>
              </ul>
            </div>
            <div class="p-4 bg-red-500/10 border border-red-500/20 rounded-lg">
              <h4 class="font-semibold text-red-400 mb-2">Considerations</h4>
              <ul class="text-sm space-y-1 text-muted">
                <li>• Not a standard format</li>
                <li>• Timestamp is extractable</li>
                <li>• Consider CUID2 for new projects</li>
              </ul>
            </div>
          </div>

          <div class="p-3 bg-surface-elevated rounded-lg mb-4">
            <span class="text-xs text-muted uppercase tracking-wider">Example Output</span>
            <code class="block mt-1 text-accent font-mono">cjld2cjxh0000qzrmn831i7rn</code>
          </div>

          <CodeBlock code={cuidExamples} lang="prax" filename="prax/schema.prax" />
        </div>

        <!-- CUID2 -->
        <div class="mb-8">
          <h3 class="text-xl font-semibold mb-3 flex items-center gap-2">
            <span class="px-2 py-1 bg-pink-500/20 text-pink-400 rounded text-sm font-mono">cuid2()</span>
            CUID2
          </h3>
          <p class="text-muted mb-4">
            Next-generation CUID with improved security. More unpredictable and shorter than the original.
            <strong class="text-foreground">Recommended for new projects.</strong>
          </p>

          <div class="grid md:grid-cols-2 gap-4 mb-4">
            <div class="p-4 bg-green-500/10 border border-green-500/20 rounded-lg">
              <h4 class="font-semibold text-green-400 mb-2">Advantages</h4>
              <ul class="text-sm space-y-1 text-muted">
                <li>• More secure than CUID</li>
                <li>• Shorter (24 characters)</li>
                <li>• Better entropy distribution</li>
                <li>• No extractable timestamp</li>
                <li>• URL-safe characters</li>
              </ul>
            </div>
            <div class="p-4 bg-red-500/10 border border-red-500/20 rounded-lg">
              <h4 class="font-semibold text-red-400 mb-2">Considerations</h4>
              <ul class="text-sm space-y-1 text-muted">
                <li>• Not sortable by time</li>
                <li>• Newer, less widespread adoption</li>
              </ul>
            </div>
          </div>

          <div class="p-3 bg-surface-elevated rounded-lg mb-4">
            <span class="text-xs text-muted uppercase tracking-wider">Example Output</span>
            <code class="block mt-1 text-accent font-mono">tz4a98xxat96iws9zmbrgj3a</code>
          </div>
        </div>

        <!-- NanoID -->
        <div class="mb-8">
          <h3 class="text-xl font-semibold mb-3 flex items-center gap-2">
            <span class="px-2 py-1 bg-orange-500/20 text-orange-400 rounded text-sm font-mono">nanoid()</span>
            NanoID
          </h3>
          <p class="text-muted mb-4">
            Compact, URL-friendly unique IDs with customizable length.
            Perfect for short URLs, invite codes, and user-facing identifiers.
          </p>

          <div class="grid md:grid-cols-2 gap-4 mb-4">
            <div class="p-4 bg-green-500/10 border border-green-500/20 rounded-lg">
              <h4 class="font-semibold text-green-400 mb-2">Advantages</h4>
              <ul class="text-sm space-y-1 text-muted">
                <li>• URL-safe (A-Za-z0-9_-)</li>
                <li>• Customizable length</li>
                <li>• Compact (21 chars default)</li>
                <li>• Cryptographically secure</li>
                <li>• Fast generation</li>
              </ul>
            </div>
            <div class="p-4 bg-red-500/10 border border-red-500/20 rounded-lg">
              <h4 class="font-semibold text-red-400 mb-2">Considerations</h4>
              <ul class="text-sm space-y-1 text-muted">
                <li>• Not sortable by time</li>
                <li>• Shorter IDs = higher collision risk</li>
                <li>• No embedded metadata</li>
              </ul>
            </div>
          </div>

          <div class="p-3 bg-surface-elevated rounded-lg mb-4">
            <span class="text-xs text-muted uppercase tracking-wider">Example Output</span>
            <div class="mt-1 space-y-1">
              <code class="block text-accent font-mono">V1StGXR8_Z5jdHi6B-myT</code>
              <code class="block text-muted font-mono text-sm">nanoid(8): 5fX8pK2m</code>
            </div>
          </div>

          <CodeBlock code={nanoidExamples} lang="prax" filename="prax/schema.prax" />
        </div>

        <!-- ULID -->
        <div class="mb-8">
          <h3 class="text-xl font-semibold mb-3 flex items-center gap-2">
            <span class="px-2 py-1 bg-cyan-500/20 text-cyan-400 rounded text-sm font-mono">ulid()</span>
            ULID
          </h3>
          <p class="text-muted mb-4">
            Universally Unique Lexicographically Sortable Identifier.
            Encodes creation timestamp, making IDs naturally sortable by time.
          </p>

          <div class="grid md:grid-cols-2 gap-4 mb-4">
            <div class="p-4 bg-green-500/10 border border-green-500/20 rounded-lg">
              <h4 class="font-semibold text-green-400 mb-2">Advantages</h4>
              <ul class="text-sm space-y-1 text-muted">
                <li>• Lexicographically sortable</li>
                <li>• Encodes millisecond timestamp</li>
                <li>• Case-insensitive</li>
                <li>• Compatible with UUID (128-bit)</li>
                <li>• Better index performance</li>
              </ul>
            </div>
            <div class="p-4 bg-red-500/10 border border-red-500/20 rounded-lg">
              <h4 class="font-semibold text-red-400 mb-2">Considerations</h4>
              <ul class="text-sm space-y-1 text-muted">
                <li>• Timestamp is extractable</li>
                <li>• 26 characters (longer than CUID2)</li>
                <li>• Limited entropy in same millisecond</li>
              </ul>
            </div>
          </div>

          <div class="p-3 bg-surface-elevated rounded-lg mb-4">
            <span class="text-xs text-muted uppercase tracking-wider">Example Output</span>
            <code class="block mt-1 text-accent font-mono">01ARZ3NDEKTSV4RRFFQ69G5FAV</code>
            <div class="mt-2 text-xs text-muted font-mono">
              <span class="text-cyan-400">01ARZ3NDEK</span><span class="text-gray-500">TSV4RRFFQ69G5FAV</span>
              <div class="mt-1">
                <span class="text-cyan-400">└─ timestamp ─┘</span><span class="text-gray-500">└── randomness ──┘</span>
              </div>
            </div>
          </div>

          <CodeBlock code={ulidExamples} lang="prax" filename="prax/schema.prax" />
        </div>

        <!-- Comparison Table -->
        <div class="mb-8">
          <h3 class="text-xl font-semibold mb-4">Comparison</h3>
          <div class="overflow-x-auto">
            <table class="w-full text-sm">
              <thead>
                <tr class="border-b border-border">
                  <th class="text-left py-2 pr-4 font-semibold">Type</th>
                  <th class="text-left py-2 pr-4 font-semibold">Length</th>
                  <th class="text-left py-2 pr-4 font-semibold">Sortable</th>
                  <th class="text-left py-2 pr-4 font-semibold">URL-Safe</th>
                  <th class="text-left py-2 font-semibold">Best For</th>
                </tr>
              </thead>
              <tbody class="divide-y divide-border">
                <tr>
                  <td class="py-2 pr-4"><code>uuid()</code></td>
                  <td class="py-2 pr-4">36</td>
                  <td class="py-2 pr-4">No</td>
                  <td class="py-2 pr-4">No (dashes)</td>
                  <td class="py-2">Database PKs, APIs</td>
                </tr>
                <tr>
                  <td class="py-2 pr-4"><code>cuid()</code></td>
                  <td class="py-2 pr-4">25</td>
                  <td class="py-2 pr-4">Roughly</td>
                  <td class="py-2 pr-4">Yes</td>
                  <td class="py-2">Distributed systems</td>
                </tr>
                <tr>
                  <td class="py-2 pr-4"><code>cuid2()</code></td>
                  <td class="py-2 pr-4">24</td>
                  <td class="py-2 pr-4">No</td>
                  <td class="py-2 pr-4">Yes</td>
                  <td class="py-2">Security-sensitive apps</td>
                </tr>
                <tr>
                  <td class="py-2 pr-4"><code>nanoid()</code></td>
                  <td class="py-2 pr-4">21*</td>
                  <td class="py-2 pr-4">No</td>
                  <td class="py-2 pr-4">Yes</td>
                  <td class="py-2">Short URLs, invite codes</td>
                </tr>
                <tr>
                  <td class="py-2 pr-4"><code>ulid()</code></td>
                  <td class="py-2 pr-4">26</td>
                  <td class="py-2 pr-4">Yes</td>
                  <td class="py-2 pr-4">Yes</td>
                  <td class="py-2">Time-series, logs, events</td>
                </tr>
              </tbody>
            </table>
            <p class="text-xs text-muted mt-2">* NanoID length is customizable</p>
          </div>

          <CodeBlock code={idComparison} lang="prax" filename="comparison.prax" />
        </div>
      </section>

      <!-- String Validators -->
      <section id="string-validators">
        <h2 class="text-2xl font-semibold mb-4">String Validators</h2>
        <p class="text-muted mb-4">
          Validate string field content with built-in rules.
        </p>

        <div class="grid md:grid-cols-2 gap-4 mb-6">
          <div class="p-4 bg-surface-elevated rounded-lg">
            <h4 class="font-semibold mb-2">Format Validators</h4>
            <ul class="text-sm space-y-1 text-muted">
              <li><code>&#64;validate.email</code> - Email format</li>
              <li><code>&#64;validate.url</code> - URL format</li>
              <li><code>&#64;validate.uuid</code> - UUID format</li>
              <li><code>&#64;validate.cuid</code> - CUID format</li>
              <li><code>&#64;validate.nanoid</code> - NanoID format</li>
              <li><code>&#64;validate.ulid</code> - ULID format</li>
              <li><code>&#64;validate.ip</code> - IP address (v4 or v6)</li>
              <li><code>&#64;validate.ipv4</code> - IPv4 only</li>
              <li><code>&#64;validate.ipv6</code> - IPv6 only</li>
            </ul>
          </div>
          <div class="p-4 bg-surface-elevated rounded-lg">
            <h4 class="font-semibold mb-2">Content Validators</h4>
            <ul class="text-sm space-y-1 text-muted">
              <li><code>&#64;validate.alpha</code> - Letters only</li>
              <li><code>&#64;validate.alphanumeric</code> - Letters and numbers</li>
              <li><code>&#64;validate.lowercase</code> - Lowercase only</li>
              <li><code>&#64;validate.uppercase</code> - Uppercase only</li>
              <li><code>&#64;validate.slug</code> - URL slug format</li>
              <li><code>&#64;validate.hex</code> - Hexadecimal string</li>
              <li><code>&#64;validate.base64</code> - Base64 encoded</li>
              <li><code>&#64;validate.json</code> - Valid JSON string</li>
            </ul>
          </div>
        </div>

        <CodeBlock code={stringValidators} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- Numeric Validators -->
      <section id="numeric-validators">
        <h2 class="text-2xl font-semibold mb-4">Numeric Validators</h2>
        <p class="text-muted mb-4">
          Constrain numeric field values with range and sign validators.
        </p>

        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm">
            <thead>
              <tr class="border-b border-border">
                <th class="text-left py-2 pr-4 font-semibold">Validator</th>
                <th class="text-left py-2 font-semibold">Description</th>
              </tr>
            </thead>
            <tbody class="divide-y divide-border">
              <tr><td class="py-2 pr-4"><code>&#64;validate.min(n)</code></td><td>Minimum value (inclusive)</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.max(n)</code></td><td>Maximum value (inclusive)</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.range(min, max)</code></td><td>Value between min and max</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.positive</code></td><td>Greater than zero</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.negative</code></td><td>Less than zero</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.nonNegative</code></td><td>Zero or greater</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.nonPositive</code></td><td>Zero or less</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.integer</code></td><td>Must be whole number</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.multipleOf(n)</code></td><td>Must be multiple of n</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.finite</code></td><td>Not Infinity or NaN</td></tr>
            </tbody>
          </table>
        </div>

        <CodeBlock code={numericValidators} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- Array Validators -->
      <section id="array-validators">
        <h2 class="text-2xl font-semibold mb-4">Array Validators</h2>
        <p class="text-muted mb-4">
          Validate array fields for length and content constraints.
        </p>

        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm">
            <thead>
              <tr class="border-b border-border">
                <th class="text-left py-2 pr-4 font-semibold">Validator</th>
                <th class="text-left py-2 font-semibold">Description</th>
              </tr>
            </thead>
            <tbody class="divide-y divide-border">
              <tr><td class="py-2 pr-4"><code>&#64;validate.minItems(n)</code></td><td>Minimum array length</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.maxItems(n)</code></td><td>Maximum array length</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.items(min, max)</code></td><td>Array length range</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.unique</code></td><td>All items must be unique</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.nonEmpty</code></td><td>At least one item required</td></tr>
            </tbody>
          </table>
        </div>

        <CodeBlock code={arrayValidators} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- Date Validators -->
      <section id="date-validators">
        <h2 class="text-2xl font-semibold mb-4">Date Validators</h2>
        <p class="text-muted mb-4">
          Validate datetime fields with temporal constraints.
        </p>

        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm">
            <thead>
              <tr class="border-b border-border">
                <th class="text-left py-2 pr-4 font-semibold">Validator</th>
                <th class="text-left py-2 font-semibold">Description</th>
              </tr>
            </thead>
            <tbody class="divide-y divide-border">
              <tr><td class="py-2 pr-4"><code>&#64;validate.past</code></td><td>Must be in the past</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.future</code></td><td>Must be in the future</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.pastOrPresent</code></td><td>Not in the future</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.futureOrPresent</code></td><td>Not in the past</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.after("date")</code></td><td>After specific date</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.before("date")</code></td><td>Before specific date</td></tr>
            </tbody>
          </table>
        </div>

        <CodeBlock code={dateValidators} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- General Validators -->
      <section id="general-validators">
        <h2 class="text-2xl font-semibold mb-4">General Validators</h2>
        <p class="text-muted mb-4">
          Universal validators that work across different field types.
        </p>

        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm">
            <thead>
              <tr class="border-b border-border">
                <th class="text-left py-2 pr-4 font-semibold">Validator</th>
                <th class="text-left py-2 font-semibold">Description</th>
              </tr>
            </thead>
            <tbody class="divide-y divide-border">
              <tr><td class="py-2 pr-4"><code>&#64;validate.required</code></td><td>Field must have a value (even if optional type)</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.notEmpty</code></td><td>Non-empty string/array</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.oneOf(...)</code></td><td>Value must be one of specified options</td></tr>
              <tr><td class="py-2 pr-4"><code>&#64;validate.custom("fn")</code></td><td>Custom validation function</td></tr>
            </tbody>
          </table>
        </div>

        <CodeBlock code={generalValidators} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- Default Value Functions -->
      <section id="defaults">
        <h2 class="text-2xl font-semibold mb-4">Default Value Functions</h2>
        <p class="text-muted mb-4">
          Auto-generate values for fields using built-in functions.
        </p>

        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm">
            <thead>
              <tr class="border-b border-border">
                <th class="text-left py-2 pr-4 font-semibold">Function</th>
                <th class="text-left py-2 font-semibold">Description</th>
              </tr>
            </thead>
            <tbody class="divide-y divide-border">
              <tr><td class="py-2 pr-4"><code>now()</code></td><td>Current timestamp</td></tr>
              <tr><td class="py-2 pr-4"><code>uuid()</code></td><td>Random UUID v4</td></tr>
              <tr><td class="py-2 pr-4"><code>cuid()</code></td><td>Collision-resistant unique ID</td></tr>
              <tr><td class="py-2 pr-4"><code>cuid2()</code></td><td>Next-gen CUID (more secure)</td></tr>
              <tr><td class="py-2 pr-4"><code>nanoid()</code></td><td>URL-friendly unique ID</td></tr>
              <tr><td class="py-2 pr-4"><code>nanoid(n)</code></td><td>NanoID with custom length</td></tr>
              <tr><td class="py-2 pr-4"><code>ulid()</code></td><td>Sortable unique ID</td></tr>
              <tr><td class="py-2 pr-4"><code>autoincrement()</code></td><td>Auto-incrementing integer</td></tr>
              <tr><td class="py-2 pr-4"><code>dbgenerated("expr")</code></td><td>Database-generated expression</td></tr>
            </tbody>
          </table>
        </div>

        <CodeBlock code={defaultFunctions} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- Database-specific Attributes -->
      <section id="db-specific">
        <h2 class="text-2xl font-semibold mb-4">Database-Specific Types</h2>
        <p class="text-muted mb-4">
          Map fields to native database column types with <code>&#64;db.*</code> attributes.
        </p>

        <div class="grid md:grid-cols-2 gap-4 mb-6">
          <div class="p-4 bg-surface-elevated rounded-lg">
            <h4 class="font-semibold mb-2">PostgreSQL Types</h4>
            <ul class="text-sm space-y-1 text-muted">
              <li><code>&#64;db.Text</code> - Unlimited text</li>
              <li><code>&#64;db.JsonB</code> - Binary JSON (indexable)</li>
              <li><code>&#64;db.Uuid</code> - Native UUID</li>
              <li><code>&#64;db.Xml</code> - XML type</li>
              <li><code>&#64;db.Inet</code> - IP address</li>
              <li><code>&#64;db.Cidr</code> - Network address</li>
              <li><code>&#64;db.MacAddr</code> - MAC address</li>
              <li><code>&#64;db.Decimal(p, s)</code> - Precise decimal</li>
            </ul>
          </div>
          <div class="p-4 bg-surface-elevated rounded-lg">
            <h4 class="font-semibold mb-2">MySQL Types</h4>
            <ul class="text-sm space-y-1 text-muted">
              <li><code>&#64;db.TinyText</code> - 255 bytes</li>
              <li><code>&#64;db.MediumText</code> - 16 MB</li>
              <li><code>&#64;db.LongText</code> - 4 GB</li>
              <li><code>&#64;db.TinyInt</code> - Tiny integer</li>
              <li><code>&#64;db.MediumInt</code> - Medium integer</li>
              <li><code>&#64;db.Year</code> - Year type</li>
              <li><code>&#64;db.VarChar(n)</code> - Variable char</li>
              <li><code>&#64;db.Charset("utf8mb4")</code> - Charset</li>
            </ul>
          </div>
        </div>

        <CodeBlock code={dbSpecific} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- Documentation Attributes -->
      <section id="documentation">
        <h2 class="text-2xl font-semibold mb-4">Documentation &amp; Metadata</h2>
        <p class="text-muted mb-4">
          Add metadata and documentation to fields using doc comments.
        </p>

        <div class="grid md:grid-cols-2 gap-4 mb-6">
          <div class="p-4 bg-surface-elevated rounded-lg">
            <h4 class="font-semibold mb-2">Visibility</h4>
            <ul class="text-sm space-y-1 text-muted">
              <li><code>&#64;hidden</code> - Exclude from public API</li>
              <li><code>&#64;internal</code> - Admin-only access</li>
              <li><code>&#64;sensitive</code> - Mask in logs</li>
              <li><code>&#64;readonly</code> - Not settable via API</li>
              <li><code>&#64;writeonly</code> - Not in responses</li>
            </ul>
          </div>
          <div class="p-4 bg-surface-elevated rounded-lg">
            <h4 class="font-semibold mb-2">Documentation</h4>
            <ul class="text-sm space-y-1 text-muted">
              <li><code>&#64;deprecated</code> - Mark as deprecated</li>
              <li><code>&#64;since version</code> - Version introduced</li>
              <li><code>&#64;example value</code> - Example value</li>
              <li><code>&#64;label text</code> - Display label</li>
              <li><code>&#64;placeholder text</code> - Input placeholder</li>
            </ul>
          </div>
        </div>

        <CodeBlock code={docAttrs} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- Index Types -->
      <section id="index-types">
        <h2 class="text-2xl font-semibold mb-4">Index Types</h2>
        <p class="text-muted mb-4">
          Create different types of database indexes for query optimization.
        </p>

        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm border border-border rounded-lg">
            <thead class="bg-muted/50">
              <tr>
                <th class="text-left px-4 py-3 font-semibold">Type</th>
                <th class="text-left px-4 py-3 font-semibold">Use Case</th>
                <th class="text-left px-4 py-3 font-semibold">PG</th>
                <th class="text-left px-4 py-3 font-semibold">MySQL</th>
                <th class="text-left px-4 py-3 font-semibold">SQLite</th>
              </tr>
            </thead>
            <tbody>
              {indexTypesTable.map((row) => (
                <tr class="border-t border-border">
                  <td class="px-4 py-2 font-mono text-primary">{row.type}</td>
                  <td class="px-4 py-2 text-muted">{row.use}</td>
                  <td class="px-4 py-2">{row.pg}</td>
                  <td class="px-4 py-2">{row.mysql}</td>
                  <td class="px-4 py-2">{row.sqlite}</td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>

        <p class="text-sm text-muted mb-4">* Requires pgvector extension</p>

        <CodeBlock code={indexTypes} lang="prax" filename="prax/schema.prax" />
      </section>

      <!-- Vector Indexes -->
      <section id="vector-indexes">
        <h2 class="text-2xl font-semibold mb-4">Vector Indexes</h2>
        <p class="text-muted mb-4">
          Vector indexes enable fast approximate nearest neighbor (ANN) search for AI/ML embeddings.
          Requires the <code>pgvector</code> PostgreSQL extension.
        </p>

        <h3 class="text-lg font-medium mb-3">Distance Operations</h3>
        <div class="overflow-x-auto mb-6">
          <table class="w-full text-sm border border-border rounded-lg">
            <thead class="bg-muted/50">
              <tr>
                <th class="text-left px-4 py-3 font-semibold">Operation</th>
                <th class="text-left px-4 py-3 font-semibold">Description</th>
                <th class="text-left px-4 py-3 font-semibold">Best For</th>
              </tr>
            </thead>
            <tbody>
              {vectorOpsTable.map((row) => (
                <tr class="border-t border-border">
                  <td class="px-4 py-2 font-mono text-primary">{row.op}</td>
                  <td class="px-4 py-2">{row.desc}</td>
                  <td class="px-4 py-2 text-muted">{row.best}</td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>

        <div class="mb-6 p-4 bg-primary/10 border border-primary/20 rounded-lg">
          <h4 class="font-medium mb-2">💡 Choosing an Index Type</h4>
          <ul class="text-sm text-muted space-y-1 list-disc list-inside">
            <li><strong>HNSW:</strong> Best recall, faster queries, slower builds - recommended for most cases</li>
            <li><strong>IVFFlat:</strong> Faster builds, slightly lower recall - good for large datasets (1M+ vectors)</li>
          </ul>
        </div>

        <CodeBlock code={vectorIndexTypes} lang="prax" filename="prax/schema.prax" />
      </section>
    </div>
  </article>
</DocsLayout>