create method
Creates a new session.
A session can be used to perform transactions that read and/or modify data
in a Cloud Spanner database. Sessions are meant to be reused for many
consecutive transactions. Sessions can only execute one transaction at a
time. To execute multiple concurrent read-write/write-only transactions,
create multiple sessions. Note that standalone reads and queries use a
transaction internally, and count toward the one transaction limit. Active
sessions use additional server resources, so it is a good idea to delete
idle and unneeded sessions. Aside from explicit deletes, Cloud Spanner may
delete sessions for which no operations are sent for more than an hour. If
a session is deleted, requests to it return NOT_FOUND
. Idle sessions can
be kept alive by sending a trivial SQL query periodically, e.g., "SELECT 1"
.
request
- The metadata request object.
Request parameters:
database
- Required. The database in which the new session is created.
Value must have pattern
^projects/\[^/\]+/instances/\[^/\]+/databases/\[^/\]+$
.
$fields
- Selector specifying which fields to include in a partial
response.
Completes with a Session.
Completes with a commons.ApiRequestError if the API endpoint returned an error.
If the used http.Client
completes with an error when making a REST call,
this method will complete with the same error.
Implementation
async.Future<Session> create(
CreateSessionRequest request,
core.String database, {
core.String? $fields,
}) async {
final body_ = convert.json.encode(request);
final queryParams_ = <core.String, core.List<core.String>>{
if ($fields != null) 'fields': [$fields],
};
final url_ = 'v1/' + core.Uri.encodeFull('$database') + '/sessions';
final response_ = await _requester.request(
url_,
'POST',
body: body_,
queryParams: queryParams_,
);
return Session.fromJson(response_ as core.Map<core.String, core.dynamic>);
}