Created
February 28, 2016 01:28
-
-
Save hafizbadrie/0ecd725714af00f22ed8 to your computer and use it in GitHub Desktop.
A script to insert 1 M JSON document
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
require 'sequel' | |
require 'json' | |
exit 1 if ARGV.empty? | |
db = Sequel.connect("postgres://localhost/hafizbadrie?user=hafizbadrie") | |
video_ids = ['12345', '54321', '34567', '87654', '67854'] | |
platform = ['web-desktop', 'web-mobile', 'app-android', 'app-ios'] | |
embed = ['true', 'false'] | |
app_name = ['vidio', 'liputan6'] | |
table_name = ARGV[0] | |
counter = 0 | |
properties = [] | |
(1).upto(1000000).each do |i| | |
properties << { | |
video_ids: video_ids[rand(0..4)], | |
duration: rand(50..60), | |
seconds: rand(1..10), | |
platform: platform[rand(0..3)], | |
embed: embed[rand(0..1)], | |
app_name: app_name[rand(0..1)] | |
}.to_json | |
counter += 1 | |
if counter == 500 | |
db[table_name.to_sym].import(['properties'], properties) | |
properties = [] | |
counter = 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment