Sha256: 4609b7d676715feb2390c574c3d8f46b47f21deeee9e6e62097b47bddaa759d8

Contents?: true

Size: 1.38 KB

Versions: 19

Compression:

Stored size: 1.38 KB

Contents

# Copyright 2021 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

require "io/console"
require_relative "../config/environment"
require_relative "models/singer"
require_relative "models/album"

class Application
  def self.run
    singer_count = Singer.all.count
    album_count = Album.all.count
    puts ""
    puts "Singers in the database: #{singer_count}"
    puts "Albums in the database: #{album_count}"

    puts ""
    puts "Deleting all albums in the database using Partitioned DML"
    # Note that a Partitioned DML transaction can contain ONLY ONE DML statement.
    # If we want to delete all data in two different tables, we need to do so in two different PDML transactions.
    Album.transaction isolation: :pdml do
      count = Album.delete_all
      puts "Deleted #{count} albums"
    end

    puts ""
    puts "Deleting all singers in the database using Partitioned DML"
    Singer.transaction isolation: :pdml do
      count = Singer.delete_all
      puts "Deleted #{count} singers"
    end

    singer_count = Singer.all.count
    album_count = Album.all.count
    puts ""
    puts "Singers in the database: #{singer_count}"
    puts "Albums in the database: #{album_count}"

    puts ""
    puts "Press any key to end the application"
    STDIN.getch
  end
end

Application.run

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
activerecord-spanner-adapter-1.6.3 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.6.2 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.6.1 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.6.0 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.5.1 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.5.0 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.4.4 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.4.3 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.4.2 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.4.1 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.4.0 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.3.1 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.2.2 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.2.1 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.2.0 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.1.0 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.0.1 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-1.0.0 examples/snippets/partitioned-dml/application.rb
activerecord-spanner-adapter-0.7.0 examples/snippets/partitioned-dml/application.rb