Skip to content

Commit

Permalink
fix(generate): Fix datasource failed to generate dataproxy client.
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Mar 10, 2023
1 parent b0b3e66 commit 8c5b7d7
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions bin/generator/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:io';
import 'package:code_builder/code_builder.dart' as code;
import 'package:crypto/crypto.dart' as crypto;
import 'package:dart_style/dart_style.dart' show DartFormatter;
import 'package:orm/orm.dart' as orm;
import 'package:path/path.dart' as path;
import 'package:orm/dmmf.dart' as dmmf;

Expand Down Expand Up @@ -1594,20 +1595,23 @@ extension PrismaClientGenerator on Generator {
code.Expression _buildDataProxyEndpoint() {
final datasource = options.datasources.first;

// `const String.fromEnvironment('DATABASE_URL')`
final fromEnvironment =
code.refer('String').constInstanceNamed('fromEnvironment', [
code.literalString(datasource.url.fromEnvVar!, raw: true),
]);

final other = datasource.url.value != null
? code.literalString(datasource.url.value!, raw: true)
: fromEnvironment;
late code.Expression url;
if (datasource.url.fromEnvVar == null && datasource.url.value == null) {
throw orm.PrismaInitializationException(
message: 'No datasource url provided',
);
} else if (datasource.url.fromEnvVar != null) {
url = code.refer('String').constInstanceNamed('fromEnvironment', [
code.literalString(datasource.url.fromEnvVar!, raw: true),
]);
} else if (datasource.url.value != null) {
url = code.literalString(datasource.url.value!, raw: true);
}

final param = code
.refer('datasources')
.nullSafeProperty(datasource.name)
.ifNullThen(other);
.ifNullThen(url);

return code.refer('Uri').property('parse').call([param]);
}
Expand Down

0 comments on commit 8c5b7d7

Please sign in to comment.