
Research
/Security News
npm Author Qix Compromised via Phishing Email in Major Supply Chain Attack
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
activerecord_data_importer
Advanced tools
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/activerecord_data_importer
. To experiment with that code, run bin/console
for an interactive prompt.
TODO: Delete this and the text above, and describe your gem
Add this line to your application's Gemfile:
gem 'activerecord_data_importer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install activerecord_data_importer
please include sentence on ActiveRecord's Model
include ActiverecordDataImporter
When you defined model like this
class Item < ActiveRecord::Base
include ActiverecordDataImporter
end
schema
///////////
create_table "Items", force: :cascade do |t|
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
///////////
and exsit file json file like context,
[
{ "id": 1, "name": "hoge" },
{ "id": 2, "name": "huga" }
]
you'll be able to import the following description(json file path is /foo/bar/items.json).
Item.import_from_json "/foo/bar/items.json"
If json single object following description, it can be used in the same way.
{ "id": 1, "name": "hoge" }
If you've used association model example
class Item < ActiveRecord::Base
include ActiverecordDataImporter
has_many :item_effects
end
class ItemEffect < ActiveRecord::Base
include ActiverecordDataImporter
end
schema
///////////
create_table "Items", force: :cascade do |t|
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "Item_effects", force: :cascade do |t|
t.integer "value", null: false
t.integer "item_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
///////////
you can import such json structure
[
{
"id": 1,
"name": "hoge",
"item_effects":[
{ "value": 1 },
{ "value": 2 },
{ "value": 3 }
]
},
{
"id": 2,
"name": "huga",
"item_effects":[
{ "value": 1 },
{ "value": 2 },
{ "value": 3 }
]
},
{
"id": 3,
"name": "piyo",
"item_effects":[
{ "value": 1 },
{ "value": 2 },
{ "value": 3 }
]
}
]
You can also import in the same way if it multistage association in the correct json description.
If importing target schema has version column, It will be increment automatically each time a record is updated. But, if same data importing (no change), version is not updated. Also, having assosiation and updating child association, parent version is updated. Furthermore, when version is updated, version number is that obtained by adding 1 to the highest number in all data before the update
csv file format is supported. if you want to use relational structure, please define same row and column name should be dotted
And if relational data is has_many
structure, please put the serial number before the dot
ex:
csv file
id,name,item_effects1.value,item_effects2.value,item_effects3.value
1,hoge,1,2,3
2,huga,1,2,3
3,piyo,1,2,3
table showing
id | name | item_effects1.value | item_effects2.value | item_effects3.value |
---|---|---|---|---|
1 | hoge | 1 | 2 | 3 |
2 | huga | 1 | 2 | 3 |
3 | piyo | 1 | 2 | 3 |
when before imported data is
{
"id": 1,
"name": "hoge",
"item_effects":[
{ "value": 1 },
{ "value": 2 },
{ "value": 3 }
]
}
and after is...
{
"id": 1,
"name": "hoge",
"item_effects":[
{ "value": 1 },
{ "value": 2 }
]
}
the result is that..
Item.find(1).item_effects
>> [#<ItemEffect id: 1, item_id: 1, value: 1, created_at: "2015-09-15 09:32:19", updated_at: "2015-09-15 09:32:19">, #<ItemEffect id: 2, item_id: 1, value: 2, created_at: "2015-09-15 09:32:19", updated_at: "2015-09-15 09:32:19">]
After checking out the repo, run bin/setup
to install dependencies. Then, run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that activerecord_data_importer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.