-
-
Save kamipo/3db82c3bb7cbcbf007b4d4367a5c5227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Author
kamipo
commented
Jan 6, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment