コード例 #1
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        database_ref = args.CONCEPTS.database.Parse()
        # DDL(Data Definition Language) is needed to get the schema of the current
        # database and table so that we know the type of each column (e.g. INT64)
        # user wants to delete.
        ddl = databases.GetDdl(database_ref)
        table = write_util.Table.FromDdl(ddl, args.table)

        mutation = database_sessions.MutationFactory.Delete(table, args.keys)

        # To commit a transaction in a session, we need to create one and delete it
        # at the end.
        session_name = database_sessions.Create(database_ref)
        session = resources.REGISTRY.ParseRelativeName(
            relative_name=session_name.name,
            collection='spanner.projects.instances.databases.sessions')
        try:
            return database_sessions.Commit(session, [mutation])
        finally:
            database_sessions.Delete(session)
コード例 #2
0
    def _LoadData(self, table_data, table_name):
        """Load data for a specified table.

    Args:
      table_data: a 2D list containing data from a CSV File. Example...
        table_data[0] = ['1', 'Some name', 'Some value'] table_data[1] = ['2',
        'Some other name', 'Some value']
      table_name: String. The name of the table to insert into.
    """
        ddl = databases.GetDdl(self._database)
        table = write_util.Table.FromDdl(ddl, table_name)
        columns = table.GetColumnTypes()

        session_name = database_sessions.Create(self._database)
        session = resources.REGISTRY.ParseRelativeName(
            relative_name=session_name.name,
            collection='spanner.projects.instances.databases.sessions')

        mutation_batch = []
        for row in table_data:
            mutation = sampledb_util.CreateInsertMutationFromCSVRow(
                table, row, columns)
            mutation_batch.append(mutation)
            if len(mutation_batch) >= self._BATCH_SIZE:
                database_sessions.Commit(session, mutation_batch)
                del mutation_batch[:]

        #  Commit any remaining mutations
        if mutation_batch:
            database_sessions.Commit(session, mutation_batch)

        database_sessions.Delete(session)
        return
コード例 #3
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        return database_sessions.Delete(args.CONCEPTS.session.Parse())
コード例 #4
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        session = database_sessions.Create(args.instance, args.database)
        try:
            return database_sessions.ExecuteSql(session, args.sql)
        finally:
            database_sessions.Delete(session)
コード例 #5
0
  def Run(self, args):
    """Runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
    session = CreateSession(args)
    try:
      return database_sessions.ExecuteSql(session, args.sql, args.query_mode)
    finally:
      database_sessions.Delete(session)
コード例 #6
0
  def Run(self, args):
    """Runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
    session = database_sessions.Create(args.instance, args.database)
    # Session id would be the string after the last /.
    session_id = session.name.split('/')[-1]
    try:
      return database_sessions.ExecuteSql(session, args.sql, args.query_mode)
    finally:
      database_sessions.Delete(args.instance, args.database, session_id)
コード例 #7
0
  def Run(self, args):
    """Runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
    session_name = database_sessions.Create(args.CONCEPTS.database.Parse())
    session = resources.REGISTRY.ParseRelativeName(
        relative_name=session_name.name,
        collection='spanner.projects.instances.databases.sessions')
    try:
      return database_sessions.ExecuteSql(session, args.sql, args.query_mode)
    finally:
      database_sessions.Delete(session)
コード例 #8
0
    def Run(self, args):
        """Runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        read_only_options = self.ParseReadOnlyOptions(args)
        session = CreateSession(args)
        try:
            return database_sessions.ExecuteSql(args.sql, args.query_mode,
                                                session, read_only_options,
                                                args.enable_partitioned_dml,
                                                args.timeout)
        finally:
            database_sessions.Delete(session)
コード例 #9
0
ファイル: update.py プロジェクト: Guliux10/bchacks_deepbreath
    def Run(self, args):
        """This is what gets called when the user runs this command."""

        database_ref = args.CONCEPTS.database.Parse()
        # DDL(Data Definition Language) is needed to get the schema of the current
        # database and table so that we know the type of each column (e.g. INT64)
        # user wants to delete.
        ddl = databases.GetDdl(database_ref)
        table = write_util.Table.FromDdl(ddl, args.table)
        data = write_util.ValidateArrayInput(table, args.data)

        mutation = database_sessions.MutationFactory.Update(table, data)

        # To commit a transaction in a session, we need to create one and delete it
        # at the end.
        session_name = database_sessions.Create(database_ref)
        session = resources.REGISTRY.ParseRelativeName(
            relative_name=session_name.name,
            collection='spanner.projects.instances.databases.sessions')
        try:
            return database_sessions.Commit(session, [mutation])
        finally:
            database_sessions.Delete(session)