# sql-protobuf

> Convert SQL CREATE TABLE statements to .proto (Proto Buffers)

Latest version **1.0.1** (published 2015-09-04) · BSD-2 license · 0 weekly downloads

## Install

```sh
npm install sql-protobuf
pnpm add sql-protobuf
yarn add sql-protobuf
bun add sql-protobuf
```

Provides the command `sql-protobuf`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-09-04 |
| First published | 2015-09-04 |
| Weekly downloads | 0 |
| License | BSD-2 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Karissa McKelvey |
| Maintainers | karissa |

## Links

- npm: https://www.npmjs.com/package/sql-protobuf
- Repository: https://github.com/karissa/sql-protobuf
- Issues: https://github.com/karissa/sql-protobuf/issues
- npm.io page: https://npm.io/package/sql-protobuf

## Dependencies (2)

- [tape](https://npm.io/package/tape.md) ^4.2.0
- [protocol-buffers-schema](https://npm.io/package/protocol-buffers-schema.md) ^2.0.3

## Recent versions

- 1.0.1 (latest) — 2015-09-04
- 1.0.0 — 2015-09-04

## README

# sql-protobuf

Convert a SQL CREATE TABLE statement into a protobuf schema.

[![NPM](https://nodei.co/npm/sql-protobuf.png)](https://nodei.co/npm/sql-protobuf/)

Parsing SQL with regex has been called 'almost impossible' -- but I like to think we can cover over 90% of the cases. There might be bugs. If this has trouble with a functioning SQL CREATE TABLE statement, let's try to fix it.

```
$ npm install -g sql-protobuf
```

Yes, this successfully handles:
  * Multiple CREATE TABLE statements in one file
  * NOT NULL
  * " and ` denotations for variable names
  * bigint
  * DEFAULT
  * IF NOT EXISTS
  * case inSenSitIvIty
  * Statement defined in one line

No, this doesn't handle:
  * Anything other than CREATE TABLE statements
  * Backwards compatibility
  * Non-basic SQL types

If the SQL type isn't found, it'll default to Protocol Buffers `string` type.

### CLI usage

```
$ sql-protobuf [input-file]
<...proto output...>
```

### Example

```
$ sql-protobuf schema.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
```
var convert = require('sql-protobuf')
var file = fs.readFileSync('schema.sql').toString()
console.log(convert(file))
```

### TODO

Need more example sql schemas

---
_Source: https://npm.io/package/sql-protobuf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
