@@ -8,8 +8,7 @@ import type {
8
8
PostgresView ,
9
9
} from '../../lib/index.js'
10
10
import type { GeneratorMetadata } from '../../lib/generators.js'
11
-
12
- const defaultSchema = process . env . PG_META_GENERATE_TYPES_DEFAULT_SCHEMA
11
+ import { DEFAULT_SCHEMA } from '../constants.js'
13
12
14
13
export const apply = async ( {
15
14
schemas,
@@ -392,18 +391,12 @@ export type Database = {
392
391
} ) }
393
392
}
394
393
395
- ${
396
- defaultSchema
397
- ? `export type DefaultSchema = Database[Extract<keyof Database, ${ JSON . stringify ( defaultSchema ) } >]
398
- export type DefaultSchemaOrPublic = DefaultSchema`
399
- : `export type PublicSchema = Database[Extract<keyof Database, "public">]
400
- export type DefaultSchemaOrPublic = PublicSchema`
401
- }
394
+ type DefaultSchema = Database[Extract<keyof Database, ${ JSON . stringify ( DEFAULT_SCHEMA ) || '"public"' } >]
402
395
403
396
404
397
export type Tables<
405
398
PublicTableNameOrOptions extends
406
- | keyof (DefaultSchemaOrPublic ["Tables"] & DefaultSchemaOrPublic ["Views"])
399
+ | keyof (DefaultSchema ["Tables"] & DefaultSchema ["Views"])
407
400
| { schema: keyof Database },
408
401
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
409
402
? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
@@ -416,8 +409,8 @@ export type Tables<
416
409
}
417
410
? R
418
411
: never
419
- : PublicTableNameOrOptions extends keyof (DefaultSchemaOrPublic ["Tables"] & DefaultSchemaOrPublic ["Views"])
420
- ? (DefaultSchemaOrPublic ["Tables"] & DefaultSchemaOrPublic ["Views"])[PublicTableNameOrOptions] extends {
412
+ : PublicTableNameOrOptions extends keyof (DefaultSchema ["Tables"] & DefaultSchema ["Views"])
413
+ ? (DefaultSchema ["Tables"] & DefaultSchema ["Views"])[PublicTableNameOrOptions] extends {
421
414
Row: infer R
422
415
}
423
416
? R
@@ -426,7 +419,7 @@ export type Tables<
426
419
427
420
export type TablesInsert<
428
421
PublicTableNameOrOptions extends
429
- | keyof DefaultSchemaOrPublic ["Tables"]
422
+ | keyof DefaultSchema ["Tables"]
430
423
| { schema: keyof Database },
431
424
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
432
425
? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
@@ -437,8 +430,8 @@ export type TablesInsert<
437
430
}
438
431
? I
439
432
: never
440
- : PublicTableNameOrOptions extends keyof DefaultSchemaOrPublic ["Tables"]
441
- ? DefaultSchemaOrPublic ["Tables"][PublicTableNameOrOptions] extends {
433
+ : PublicTableNameOrOptions extends keyof DefaultSchema ["Tables"]
434
+ ? DefaultSchema ["Tables"][PublicTableNameOrOptions] extends {
442
435
Insert: infer I
443
436
}
444
437
? I
@@ -447,7 +440,7 @@ export type TablesInsert<
447
440
448
441
export type TablesUpdate<
449
442
PublicTableNameOrOptions extends
450
- | keyof DefaultSchemaOrPublic ["Tables"]
443
+ | keyof DefaultSchema ["Tables"]
451
444
| { schema: keyof Database },
452
445
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
453
446
? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
@@ -458,8 +451,8 @@ export type TablesUpdate<
458
451
}
459
452
? U
460
453
: never
461
- : PublicTableNameOrOptions extends keyof DefaultSchemaOrPublic ["Tables"]
462
- ? DefaultSchemaOrPublic ["Tables"][PublicTableNameOrOptions] extends {
454
+ : PublicTableNameOrOptions extends keyof DefaultSchema ["Tables"]
455
+ ? DefaultSchema ["Tables"][PublicTableNameOrOptions] extends {
463
456
Update: infer U
464
457
}
465
458
? U
@@ -468,28 +461,28 @@ export type TablesUpdate<
468
461
469
462
export type Enums<
470
463
PublicEnumNameOrOptions extends
471
- | keyof DefaultSchemaOrPublic ["Enums"]
464
+ | keyof DefaultSchema ["Enums"]
472
465
| { schema: keyof Database },
473
466
EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database }
474
467
? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"]
475
468
: never = never
476
469
> = PublicEnumNameOrOptions extends { schema: keyof Database }
477
470
? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName]
478
- : PublicEnumNameOrOptions extends keyof DefaultSchemaOrPublic ["Enums"]
479
- ? DefaultSchemaOrPublic ["Enums"][PublicEnumNameOrOptions]
471
+ : PublicEnumNameOrOptions extends keyof DefaultSchema ["Enums"]
472
+ ? DefaultSchema ["Enums"][PublicEnumNameOrOptions]
480
473
: never
481
474
482
475
export type CompositeTypes<
483
476
PublicCompositeTypeNameOrOptions extends
484
- | keyof DefaultSchemaOrPublic ['CompositeTypes']
477
+ | keyof DefaultSchema ['CompositeTypes']
485
478
| { schema: keyof Database },
486
479
CompositeTypeName extends PublicCompositeTypeNameOrOptions extends { schema: keyof Database }
487
480
? keyof Database[PublicCompositeTypeNameOrOptions['schema']]['CompositeTypes']
488
481
: never = never
489
482
> = PublicCompositeTypeNameOrOptions extends { schema: keyof Database }
490
483
? Database[PublicCompositeTypeNameOrOptions['schema']]['CompositeTypes'][CompositeTypeName]
491
- : PublicCompositeTypeNameOrOptions extends keyof DefaultSchemaOrPublic ['CompositeTypes']
492
- ? DefaultSchemaOrPublic ['CompositeTypes'][PublicCompositeTypeNameOrOptions]
484
+ : PublicCompositeTypeNameOrOptions extends keyof DefaultSchema ['CompositeTypes']
485
+ ? DefaultSchema ['CompositeTypes'][PublicCompositeTypeNameOrOptions]
493
486
: never;
494
487
`
495
488
0 commit comments