-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tim Holm <[email protected]>
- Loading branch information
1 parent
6529881
commit 0072ec2
Showing
35 changed files
with
1,015 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import 'package:grpc/grpc.dart'; | ||
|
||
export 'bucket.dart'; | ||
export 'keyvalue.dart'; | ||
export 'secret.dart'; | ||
export 'topic.dart'; | ||
export 'proto.dart'; | ||
export 'queue.dart'; | ||
|
||
typedef UseClientCallback<T extends Client, Resp> = Future<Resp> Function(T); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:nitric_sdk/nitric.dart'; | ||
import 'package:nitric_sdk/src/grpc_helper.dart'; | ||
import 'package:nitric_sdk/src/nitric/proto/resources/v1/resources.pb.dart'; | ||
import 'package:nitric_sdk/src/nitric/proto/resources/v1/resources.pbgrpc.dart' | ||
as $rp; | ||
import 'package:nitric_sdk/src/nitric/proto/sql/v1/sql.pbgrpc.dart' as $p; | ||
|
||
import 'api.dart'; | ||
|
||
/// A Topic for publishing events to subscribers of this topic. | ||
class SqlDatabase extends Resource { | ||
/// The name of the topic | ||
late final String? migrations; | ||
late final $p.SqlClient? _sqlClient; | ||
|
||
SqlDatabase(String name, | ||
{this.migrations, | ||
$p.SqlClient? client, | ||
$rp.ResourcesClient? resourcesClient}) | ||
: super(name, resourcesClient) { | ||
_sqlClient = client; | ||
} | ||
|
||
Future<Resp> _useClient<Resp>( | ||
UseClientCallback<$p.SqlClient, Resp> callback) async { | ||
final client = _sqlClient ?? | ||
$p.SqlClient(ClientChannelSingleton.instance.clientChannel); | ||
|
||
var resp = callback(client); | ||
|
||
if (_sqlClient == null) { | ||
await ClientChannelSingleton.instance.release(); | ||
} | ||
|
||
return resp; | ||
} | ||
|
||
/// Returns a connection endpoint to connect to the SQL database | ||
Future<String> connectionString() async { | ||
final req = $p.SqlConnectionStringRequest(databaseName: name); | ||
|
||
final resp = | ||
await _useClient((client) async => await client.connectionString(req)); | ||
|
||
return resp.connectionString; | ||
} | ||
|
||
@override | ||
$rp.ResourceDeclareRequest asRequest() { | ||
var resource = | ||
$rp.ResourceIdentifier(name: name, type: $rp.ResourceType.SqlDatabase); | ||
|
||
return $rp.ResourceDeclareRequest( | ||
id: resource, | ||
sqlDatabase: $rp.SqlDatabaseResource( | ||
migrations: SqlDatabaseMigrations(migrationsPath: migrations))); | ||
} | ||
} |
Oops, something went wrong.