@@ -81,7 +81,7 @@ pub async fn run_generate_command(
81
81
82
82
let filter_skip_tables = |table : & String | -> bool { !ignore_tables. contains ( table) } ;
83
83
84
- let database_name = if !is_sqlite {
84
+ let _database_name = if !is_sqlite {
85
85
// The database name should be the first element of the path string
86
86
//
87
87
// Throwing an error if there is no database name since it might be
@@ -113,81 +113,104 @@ pub async fn run_generate_command(
113
113
114
114
let ( schema_name, table_stmts) = match url. scheme ( ) {
115
115
"mysql" => {
116
- use sea_schema:: mysql:: discovery:: SchemaDiscovery ;
117
- use sqlx:: MySql ;
118
-
119
- println ! ( "Connecting to MySQL ..." ) ;
120
- let connection =
121
- sqlx_connect :: < MySql > ( max_connections, acquire_timeout, url. as_str ( ) , None )
122
- . await ?;
123
-
124
- println ! ( "Discovering schema ..." ) ;
125
- let schema_discovery = SchemaDiscovery :: new ( connection, database_name) ;
126
- let schema = schema_discovery. discover ( ) . await ?;
127
- let table_stmts = schema
128
- . tables
129
- . into_iter ( )
130
- . filter ( |schema| filter_tables ( & schema. info . name ) )
131
- . filter ( |schema| filter_hidden_tables ( & schema. info . name ) )
132
- . filter ( |schema| filter_skip_tables ( & schema. info . name ) )
133
- . map ( |schema| schema. write ( ) )
134
- . collect ( ) ;
135
- ( None , table_stmts)
116
+ #[ cfg( not( feature = "sqlx-mysql" ) ) ]
117
+ {
118
+ panic ! ( "mysql feature is off" )
119
+ }
120
+ #[ cfg( feature = "sqlx-mysql" ) ]
121
+ {
122
+ use sea_schema:: mysql:: discovery:: SchemaDiscovery ;
123
+ use sqlx:: MySql ;
124
+
125
+ println ! ( "Connecting to MySQL ..." ) ;
126
+ let connection = sqlx_connect :: < MySql > (
127
+ max_connections,
128
+ acquire_timeout,
129
+ url. as_str ( ) ,
130
+ None ,
131
+ )
132
+ . await ?;
133
+ println ! ( "Discovering schema ..." ) ;
134
+ let schema_discovery = SchemaDiscovery :: new ( connection, _database_name) ;
135
+ let schema = schema_discovery. discover ( ) . await ?;
136
+ let table_stmts = schema
137
+ . tables
138
+ . into_iter ( )
139
+ . filter ( |schema| filter_tables ( & schema. info . name ) )
140
+ . filter ( |schema| filter_hidden_tables ( & schema. info . name ) )
141
+ . filter ( |schema| filter_skip_tables ( & schema. info . name ) )
142
+ . map ( |schema| schema. write ( ) )
143
+ . collect ( ) ;
144
+ ( None , table_stmts)
145
+ }
136
146
}
137
147
"sqlite" => {
138
- use sea_schema:: sqlite:: discovery:: SchemaDiscovery ;
139
- use sqlx:: Sqlite ;
140
-
141
- println ! ( "Connecting to SQLite ..." ) ;
142
- let connection = sqlx_connect :: < Sqlite > (
143
- max_connections,
144
- acquire_timeout,
145
- url. as_str ( ) ,
146
- None ,
147
- )
148
- . await ?;
149
-
150
- println ! ( "Discovering schema ..." ) ;
151
- let schema_discovery = SchemaDiscovery :: new ( connection) ;
152
- let schema = schema_discovery
153
- . discover ( )
154
- . await ?
155
- . merge_indexes_into_table ( ) ;
156
- let table_stmts = schema
157
- . tables
158
- . into_iter ( )
159
- . filter ( |schema| filter_tables ( & schema. name ) )
160
- . filter ( |schema| filter_hidden_tables ( & schema. name ) )
161
- . filter ( |schema| filter_skip_tables ( & schema. name ) )
162
- . map ( |schema| schema. write ( ) )
163
- . collect ( ) ;
164
- ( None , table_stmts)
148
+ #[ cfg( not( feature = "sqlx-sqlite" ) ) ]
149
+ {
150
+ panic ! ( "sqlite feature is off" )
151
+ }
152
+ #[ cfg( feature = "sqlx-sqlite" ) ]
153
+ {
154
+ use sea_schema:: sqlite:: discovery:: SchemaDiscovery ;
155
+ use sqlx:: Sqlite ;
156
+
157
+ println ! ( "Connecting to SQLite ..." ) ;
158
+ let connection = sqlx_connect :: < Sqlite > (
159
+ max_connections,
160
+ acquire_timeout,
161
+ url. as_str ( ) ,
162
+ None ,
163
+ )
164
+ . await ?;
165
+ println ! ( "Discovering schema ..." ) ;
166
+ let schema_discovery = SchemaDiscovery :: new ( connection) ;
167
+ let schema = schema_discovery
168
+ . discover ( )
169
+ . await ?
170
+ . merge_indexes_into_table ( ) ;
171
+ let table_stmts = schema
172
+ . tables
173
+ . into_iter ( )
174
+ . filter ( |schema| filter_tables ( & schema. name ) )
175
+ . filter ( |schema| filter_hidden_tables ( & schema. name ) )
176
+ . filter ( |schema| filter_skip_tables ( & schema. name ) )
177
+ . map ( |schema| schema. write ( ) )
178
+ . collect ( ) ;
179
+ ( None , table_stmts)
180
+ }
165
181
}
166
182
"postgres" | "postgresql" => {
167
- use sea_schema:: postgres:: discovery:: SchemaDiscovery ;
168
- use sqlx:: Postgres ;
169
-
170
- println ! ( "Connecting to Postgres ..." ) ;
171
- let schema = database_schema. as_deref ( ) . unwrap_or ( "public" ) ;
172
- let connection = sqlx_connect :: < Postgres > (
173
- max_connections,
174
- acquire_timeout,
175
- url. as_str ( ) ,
176
- Some ( schema) ,
177
- )
178
- . await ?;
179
- println ! ( "Discovering schema ..." ) ;
180
- let schema_discovery = SchemaDiscovery :: new ( connection, schema) ;
181
- let schema = schema_discovery. discover ( ) . await ?;
182
- let table_stmts = schema
183
- . tables
184
- . into_iter ( )
185
- . filter ( |schema| filter_tables ( & schema. info . name ) )
186
- . filter ( |schema| filter_hidden_tables ( & schema. info . name ) )
187
- . filter ( |schema| filter_skip_tables ( & schema. info . name ) )
188
- . map ( |schema| schema. write ( ) )
189
- . collect ( ) ;
190
- ( database_schema, table_stmts)
183
+ #[ cfg( not( feature = "sqlx-postgres" ) ) ]
184
+ {
185
+ panic ! ( "postgres feature is off" )
186
+ }
187
+ #[ cfg( feature = "sqlx-postgres" ) ]
188
+ {
189
+ use sea_schema:: postgres:: discovery:: SchemaDiscovery ;
190
+ use sqlx:: Postgres ;
191
+
192
+ println ! ( "Connecting to Postgres ..." ) ;
193
+ let schema = database_schema. as_deref ( ) . unwrap_or ( "public" ) ;
194
+ let connection = sqlx_connect :: < Postgres > (
195
+ max_connections,
196
+ acquire_timeout,
197
+ url. as_str ( ) ,
198
+ Some ( schema) ,
199
+ )
200
+ . await ?;
201
+ println ! ( "Discovering schema ..." ) ;
202
+ let schema_discovery = SchemaDiscovery :: new ( connection, schema) ;
203
+ let schema = schema_discovery. discover ( ) . await ?;
204
+ let table_stmts = schema
205
+ . tables
206
+ . into_iter ( )
207
+ . filter ( |schema| filter_tables ( & schema. info . name ) )
208
+ . filter ( |schema| filter_hidden_tables ( & schema. info . name ) )
209
+ . filter ( |schema| filter_skip_tables ( & schema. info . name ) )
210
+ . map ( |schema| schema. write ( ) )
211
+ . collect ( ) ;
212
+ ( database_schema, table_stmts)
213
+ }
191
214
}
192
215
_ => unimplemented ! ( "{} is not supported" , url. scheme( ) ) ,
193
216
} ;
0 commit comments