Skip to content
On this page

string

protobuf

Generate Protocol Buffers message definitions from SQL schema

Example Output ​

Generated from the pet-store sample schema:

protobuf
// Generated by @sqldoc/templates/protobuf -- DO NOT EDIT
syntax = "proto3";

package schema;

import "google/protobuf/timestamp.proto";

message Adoption {
  int32 id = 1;
  int32 pet_id = 2;
  int32 owner_id = 3;
  google.protobuf.Timestamp adopted_at = 4;
  string adoption_fee = 5;
}

message AdoptionsAuditLog {
  int64 id = 1;
  string table_name = 2;
  string operation = 3;
  optional string old_data = 4;
  optional string new_data = 5;
  google.protobuf.Timestamp changed_at = 6;
}

message Category {
  int32 id = 1;
  string name = 2;
  optional string description = 3;
}

message LegacyInventory {
  int32 id = 1;
  optional string item_name = 2;
  optional string old_sku = 3;
  optional int32 quantity = 4;
}

message Location {
  int32 id = 1;
  string name = 2;
  string address = 3;
  string city = 4;
  optional string zip = 5;
}

message MedicalRecord {
  int32 id = 1;
  int32 pet_id = 2;
  string visit_date = 3;
  string diagnosis = 4;
  optional string treatment = 5;
  optional string vet_name = 6;
}

message Owner {
  int32 id = 1;
  string name = 2;
  string email = 3;
  optional string phone = 4;
  optional google.protobuf.Timestamp created_at = 5;
}

message Pet {
  int32 id = 1;
  optional int32 category_id = 2;
  string name = 3;
  string sku = 4;
  string price = 5;
  optional string internal_notes = 6;
  string status = 7;
  optional google.protobuf.Timestamp created_at = 8;
}

message Review {
  int32 id = 1;
  int32 pet_id = 2;
  int32 owner_id = 3;
  int32 rating = 4;
  optional string body = 5;
  optional int32 location_id = 6;
  optional google.protobuf.Timestamp created_at = 7;
}

message StaffAuditLog {
  int64 id = 1;
  string table_name = 2;
  string operation = 3;
  optional string old_data = 4;
  optional string new_data = 5;
  google.protobuf.Timestamp changed_at = 6;
}

Usage ​

Add to your sqldoc.config.ts:

typescript
export default {
  dialect: 'postgres',
  schema: ['./schema.sql'],
  codegen: [
    {
      template: 'protobuf',
      output: './generated/schema.proto',
    },
  ],
}

Then run:

bash
sqldoc codegen