[protobuf] protobuf <==> SQL

3,471 views
Skip to first unread message

ury

unread,
Apr 21, 2010, 2:53:03 PM4/21/10
to Protocol Buffers
Hi,

I wonder if someone has an idea for a generic way of storing protobuf
messages in an SQL database (not as a blob, but in a way the data can
be queried with SQL statements) and how to construct the protobuf
messages back from the SQL database.

Thank you

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.

Jason Hsueh

unread,
Apr 21, 2010, 3:29:33 PM4/21/10
to ury, Protocol Buffers
You could write a bridge between the database and protobufs using reflection. It is probably simplest if each field in the protobuf corresponds to a column in the database table. Then when processing the result of a SQL query, you can just iterate over the columns, find the corresponding field in the proto, and set the value to what was returned in the query. You can do the same sort of thing to insert/update the table, going from protobuf fields to column name/values.

Marc Gravell

unread,
Apr 21, 2010, 5:26:14 PM4/21/10
to ury, Protocol Buffers
In a way similar to how Jason suggests, with those requirements (i.e. not storing a BLOB) I would use an ORM to persist a type model, and protobuf to serialize a type model on the wire. Possibly the same type model, or possibly not.

Which ORM might be suitable depends a lot more on your platform; for example, with .NET a LINQ-to-SQL data-context with serialization enabled will work /immediately/ with protobuf-net, as LINQ-to-SQL includes [DataMember(Order=n)] attributes which protobuf-net chooses to interpret as protobuf field numbers.

Marc
--
Regards,

Marc

Chris Dew

unread,
May 23, 2012, 9:17:22 AM5/23/12
to prot...@googlegroups.com
I would use:

protoc --descriptor_set_out=foo.desc --include_imports foo.proto

to generate a description of the protocol in protobuf format.

Then I would transform every message type into a table.

If you want more information, email me at cms...@gmail.com

All the best,

Chris.

On Wednesday, 21 April 2010 19:53:03 UTC+1, ury wrote:
Hi,

I wonder if someone has an idea for a generic way of storing protobuf
messages in an SQL database (not as a blob, but in a way the data can
be queried with SQL statements) and how to construct the protobuf
messages back from the SQL database.

Thank you

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages