@@ -69,14 +69,16 @@ export interface Database {
69
69
( table ) => `${ JSON . stringify ( table . name ) } : {
70
70
Row: {
71
71
${ [
72
- ...table . columns . map (
73
- ( column ) =>
74
- `${ JSON . stringify ( column . name ) } : ${ pgTypeToTsType (
75
- column . format ,
76
- types ,
77
- schemas
78
- ) } ${ column . is_nullable ? '| null' : '' } `
79
- ) ,
72
+ ...table . columns
73
+ . sort ( ( { name : a } , { name : b } ) => a . localeCompare ( b ) )
74
+ . map (
75
+ ( column ) =>
76
+ `${ JSON . stringify ( column . name ) } : ${ pgTypeToTsType (
77
+ column . format ,
78
+ types ,
79
+ schemas
80
+ ) } ${ column . is_nullable ? '| null' : '' } `
81
+ ) ,
80
82
...schemaFunctions
81
83
. filter ( ( fn ) => fn . argument_types === table . name )
82
84
. map (
@@ -90,48 +92,52 @@ export interface Database {
90
92
] }
91
93
}
92
94
Insert: {
93
- ${ table . columns . map ( ( column ) => {
94
- let output = JSON . stringify ( column . name )
95
+ ${ table . columns
96
+ . sort ( ( { name : a } , { name : b } ) => a . localeCompare ( b ) )
97
+ . map ( ( column ) => {
98
+ let output = JSON . stringify ( column . name )
95
99
96
- if ( column . identity_generation === 'ALWAYS' ) {
97
- return `${ output } ?: never`
98
- }
100
+ if ( column . identity_generation === 'ALWAYS' ) {
101
+ return `${ output } ?: never`
102
+ }
99
103
100
- if (
101
- column . is_nullable ||
102
- column . is_identity ||
103
- column . default_value !== null
104
- ) {
105
- output += '?:'
106
- } else {
107
- output += ':'
108
- }
104
+ if (
105
+ column . is_nullable ||
106
+ column . is_identity ||
107
+ column . default_value !== null
108
+ ) {
109
+ output += '?:'
110
+ } else {
111
+ output += ':'
112
+ }
109
113
110
- output += pgTypeToTsType ( column . format , types , schemas )
114
+ output += pgTypeToTsType ( column . format , types , schemas )
111
115
112
- if ( column . is_nullable ) {
113
- output += '| null'
114
- }
116
+ if ( column . is_nullable ) {
117
+ output += '| null'
118
+ }
115
119
116
- return output
117
- } ) }
120
+ return output
121
+ } ) }
118
122
}
119
123
Update: {
120
- ${ table . columns . map ( ( column ) => {
121
- let output = JSON . stringify ( column . name )
124
+ ${ table . columns
125
+ . sort ( ( { name : a } , { name : b } ) => a . localeCompare ( b ) )
126
+ . map ( ( column ) => {
127
+ let output = JSON . stringify ( column . name )
122
128
123
- if ( column . identity_generation === 'ALWAYS' ) {
124
- return `${ output } ?: never`
125
- }
129
+ if ( column . identity_generation === 'ALWAYS' ) {
130
+ return `${ output } ?: never`
131
+ }
126
132
127
- output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } `
133
+ output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } `
128
134
129
- if ( column . is_nullable ) {
130
- output += '| null'
131
- }
135
+ if ( column . is_nullable ) {
136
+ output += '| null'
137
+ }
132
138
133
- return output
134
- } ) }
139
+ return output
140
+ } ) }
135
141
}
136
142
}`
137
143
)
@@ -144,46 +150,52 @@ export interface Database {
144
150
: schemaViews . map (
145
151
( view ) => `${ JSON . stringify ( view . name ) } : {
146
152
Row: {
147
- ${ view . columns . map (
148
- ( column ) =>
149
- `${ JSON . stringify ( column . name ) } : ${ pgTypeToTsType (
150
- column . format ,
151
- types ,
152
- schemas
153
- ) } ${ column . is_nullable ? '| null' : '' } `
154
- ) }
153
+ ${ view . columns
154
+ . sort ( ( { name : a } , { name : b } ) => a . localeCompare ( b ) )
155
+ . map (
156
+ ( column ) =>
157
+ `${ JSON . stringify ( column . name ) } : ${ pgTypeToTsType (
158
+ column . format ,
159
+ types ,
160
+ schemas
161
+ ) } ${ column . is_nullable ? '| null' : '' } `
162
+ ) }
155
163
}
156
164
${
157
165
view . is_updatable
158
166
? `Insert: {
159
- ${ view . columns . map ( ( column ) => {
160
- let output = JSON . stringify ( column . name )
167
+ ${ view . columns
168
+ . sort ( ( { name : a } , { name : b } ) => a . localeCompare ( b ) )
169
+ . map ( ( column ) => {
170
+ let output = JSON . stringify ( column . name )
161
171
162
- if ( ! column . is_updatable ) {
163
- return `${ output } ?: never`
164
- }
172
+ if ( ! column . is_updatable ) {
173
+ return `${ output } ?: never`
174
+ }
165
175
166
- output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } | null`
176
+ output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } | null`
167
177
168
- return output
169
- } ) }
178
+ return output
179
+ } ) }
170
180
}`
171
181
: ''
172
182
}
173
183
${
174
184
view . is_updatable
175
185
? `Update: {
176
- ${ view . columns . map ( ( column ) => {
177
- let output = JSON . stringify ( column . name )
186
+ ${ view . columns
187
+ . sort ( ( { name : a } , { name : b } ) => a . localeCompare ( b ) )
188
+ . map ( ( column ) => {
189
+ let output = JSON . stringify ( column . name )
178
190
179
- if ( ! column . is_updatable ) {
180
- return `${ output } ?: never`
181
- }
191
+ if ( ! column . is_updatable ) {
192
+ return `${ output } ?: never`
193
+ }
182
194
183
- output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } | null`
195
+ output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } | null`
184
196
185
- return output
186
- } ) }
197
+ return output
198
+ } ) }
187
199
}`
188
200
: ''
189
201
}
0 commit comments