# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "activerecord", "6.1.0" | |
gem "activerecord-import" | |
gem "mysql2" | |
end | |
require "active_record" | |
require "logger" | |
ActiveRecord::Base.establish_connection(adapter: "mysql2", database: "test", username: "root") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :users, force: true do |t| | |
t.string :name, index: { unique: true } | |
t.decimal :money, precision: 10 | |
end | |
end | |
class User < ActiveRecord::Base | |
end | |
attributes = [ | |
{ name: "foo", money: "10000000000" }, | |
{ name: "foo", money: "20000000000" }, | |
] | |
User.import(attributes, on_duplicate_key_ignore: true) | |
# User.insert_all(attributes) | |
puts | |
puts User.pluck(:money) # => 9999999999 | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.