def session(self): """Factory to create a session for this database. :rtype: :class:`~google.cloud.spanner_v1.session.Session` :returns: a session bound to this database. """ return Session(self)
def session(self, labels=None): """Factory to create a session for this database. :type labels: dict (str -> str) or None :param labels: (Optional) user-assigned labels for the session. :rtype: :class:`~google.cloud.spanner_v1.session.Session` :returns: a session bound to this database. """ return Session(self, labels=labels)
def _make_session_pb(name, labels=None): from google.cloud.spanner_v1.proto.spanner_pb2 import Session return Session(name=name, labels=labels)
from google.cloud.spanner import Client from google.cloud.spanner_v1.session import Session from faker import Faker PROJECT_NAME = 'grass-clump-479' INSTANCE_NAME = 'python-write' DATABASE_NAME = 'pythontest' client = Client(project=PROJECT_NAME) instance = client.instance(INSTANCE_NAME) database = instance.database(DATABASE_NAME) session = Session(database) session.create() transaction = session.transaction() transaction.begin() fake = Faker() for i in range(10000): transaction.insert(table='table_python', columns=( 'key', 'textcolumn', ), values=[ (i, fake.name()), ]) transaction.commit() with database.snapshot() as snapshot: results = snapshot.execute_sql('SELECT key,textcolumn from table_python') for row in results: