Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hacking stdin #11

Merged
merged 3 commits into from
Mar 21, 2016
Merged

hacking stdin #11

merged 3 commits into from
Mar 21, 2016

Conversation

rrbarbosa
Copy link
Contributor

I would like to see some support to read from stdin instead of only files. I am by no means a go programmer, but I think a push request is a good way to get the conversation going.

I hacked in some support for JSON files. I did not worry much about error handling and your fancy progress bar won't work.

If you would like to support the feature, I can go on and start implementing it for the other importers. Any comments are welcome.

@lukasmartinelli
Copy link
Owner

This is awesome idea and great initial work!! Thanks @rrbarbosa

Tell me when to merge. I will merge it and then go over the code afterwards to make sure progress bar etc. works again.

As far as I remember in the beginning pgfutter only supported input from stdin but then I forgot about how useful that is. Especially for streaming something into the database.

@rrbarbosa
Copy link
Contributor Author

Sure, I will work on it this week. 2 things:

  • The progress bar won't work with stdin as you don't know how many bytes/records you are reading beforehand, unless I am missing something...
  • Do you have any suggestions on how to deal with the table name when reading stdin?

@rrbarbosa
Copy link
Contributor Author

Ok. I tested both json and csv and they seem to be working from stdin. For now, if no filename is present and the --table option is not set, the data is loaded in a table named stdin.

I have not tested the JSONObject option.

Personally, I don't like that I need to test filename == "" multiple times to decide if I am reading from file or stdin. Probably a better way would be to create the proper Reader object when parsing... But hey, its working.

@lukasmartinelli lukasmartinelli self-assigned this Mar 21, 2016
lukasmartinelli added a commit that referenced this pull request Mar 21, 2016
@lukasmartinelli lukasmartinelli merged commit cfe524c into lukasmartinelli:master Mar 21, 2016
@lukasmartinelli
Copy link
Owner

Very very nice 👍
Yes passing around a Reader object to the different protocol implementations would be much cleaner. Will try to refactor this after the merge.

@rrbarbosa rrbarbosa deleted the stdin branch March 21, 2016 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants