Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/okdistribute/protobufit

Turn that schema into a protobuf
https://github.com/okdistribute/protobufit

Last synced: 27 days ago
JSON representation

Turn that schema into a protobuf

Awesome Lists containing this project

README

        

# protobufit

Converts various schema types into [Protocol Buffers](https://developers.google.com/protocol-buffers/?hl=en) format (v2).

Supports:
* [SQL `CREATE TABLE` statements](http://www.w3schools.com/sql/sql_create_table.asp)
* [JSON Schema](json-schema.org)

Yes, this handles:
* Multiple schema definitions in a single file
* Tries to auto-detect the given schema format if not specified
* `required` and `repeated`

```
npm install -g protobufit
```

### CLI usage

```
protobufit [input-file] [-f ]
: 'sql' or 'jsonschema'
```

### Example

```
protobufit schema.sql -f sql > schema.proto
```

schema.sql
```
CREATE TABLE "pluto" (
"boroughtext" text,
"block" integer,
"lot" bigint,
"cd" date NOT NULL,
);
```

schema.proto
```
syntax = "proto2";

message pluto {
optional string boroughtext = 1;
optional int32 block = 2;
optional int64 lot = 3;
required string cd = 4;
```

### JS usage

```js
var protobufit = require('protobufit')
var data = fs.readFileSync('schema.sql').toString()
var opts = {format: 'sql'}
console.log(protobufit(data, opts))
```

### TODO
* datapackage.json
* Rdata?