-
Notifications
You must be signed in to change notification settings - Fork 27
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
Added FORMAT(binary) copy capability and example #204
base: master
Are you sure you want to change the base?
Conversation
The function Connection.putCopyData was overloaded to take const(ubyte[]) values since these are common for raw data. In addition the example.d file was updated to include an explicit binary copy in for BYTEA types and to work with dub.
// For FORMAT binary, send over the 19 byte PostgreSQL header manually | ||
// P G C O P Y \n 255 \r \n | ||
conn.putCopyData(cast(ubyte[])[ | ||
0x50,0x47,0x43,0x4F,0x50,0x59,0x0A,0xFF,0x0D,0x0A,0,0,0,0,0,0,0,0,0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it makes sense to hide this predefined constant in a separate method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh it certainly does.
This code is an extract of essential features from my application code that uses dpq2. I just wanted to get a working example to you and others for polishing. Preferably by someone who understands the guiding principles of dpq2 better than I.
size_t offset = 0; | ||
buf[].write!(short, BE)(2, &offset); // Sending two fields | ||
|
||
buf[].write!(int, BE)(long.sizeof, &offset); // BIGINT == long |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the dpq2.conv.from_d_types
module we have converter for (almost) all supported types. Actually, it converts D values into Value
struct, but it is possible to extract needed code into a separate codeblock
Hello! Thank you very much! I think this is a good improvement because sometimes it is very necessary to quickly fill a database with a large amount of data. Usually this is a rare operation, but if you need it then there are no workarounds. |
Thanks for the encouraging comments :-) Would it be possible to accept the pull and then convert it right away to a more canonical example? I'm much more confident in your ability than my own in this regard. For example when reading the library I didn't quite understand the BSON features, but I'm guessing they are applicable here? If this sounds reasonable, then maybe it would make more sense for me to send a pull request to a different branch. |
I find it hard to write code "for the drawer", because I don't need this functionality now.
No, we can decide to not support it at first. BSON support was added to It was later replaced in this capacity by Line 105 in ac6057c
It is high time to make Bson support by optional dependency. |
Sounds good, will do. Feel free to ignore this pull request. I'll submit another much later this evening. Also, I'm also seeing issues when building under GDC-13. Namely:
I can of course add a compile flag, but would prefer not to if possible. I presume you'd want updates for this issue in a separate pull request? If not I can try to address both topics at once.
Looking over the recursive dependency list for dpq2 I see:
as well as Phobos of course. Since I'm carefully tracking dependencies as my project moves into production, how many of these dependencies would no longer be required if I were to use a "no-BSON" version of dpq2? |
Yes, that would be great!
Also, |
Hi Denizzzka
The dpq2 library met most of my needs, but a small update was added to assist with fast binary copy-in. The changes are:
I certainly don't expect you to accept these changes upstream, but wanted to offer them in case they are useful.
Thanks for creating dpq2!