tdconverter

command
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2019 License: MIT Imports: 10 Imported by: 0

README

tdconverter

This is a CLI tool to make easy to convert table definition files to SQL and Go struct etc.

Description

This tool converts table definitions to SQL and Go struct etc. Currently this package supports SQL and Go format.

For example, if the table definition is like...

sample table

SQL is output as follows.

$ tdconverter -i sample -n sample sql
complete!
# This file generated by tdconv. DO NOT EDIT.
# See more details at https://github.com/takuoki/tdconv.
DROP TABLE IF EXISTS sample_table;
CREATE TABLE `sample_table` (
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'this is id!',
    `foo` VARCHAR(32) NOT NULL UNIQUE,
    `bar` VARCHAR(32),
    PRIMARY KEY (id),
    INDEX `bar_key` (bar)
);

Go struct is output as follows.

$ tdconverter -i sample -n sample go
complete!
// This file generated by tdconv. DO NOT EDIT.
// See more details at https://github.com/takuoki/tdconv.
package main

import(
  "time"
)

type sampleTable struct {
  ID *int
  Foo *string
  Bar *string
}

Install

If you have a Go environment, you can install this tool using go get. Before installing, enable the Go module feature.

go get github.com/takuoki/tdconv/tools/tdconverter

If not, download it from the release page.

Requirements

This tool uses Google OAuth2.0. So before executing tool, you have to prepare credentials.json. See Go Quickstart, or Blog (Japanese) for the details.

Usage

Create the table definitions

Copy the table definition template, and fill the value as you need.

Create SQL or Go struct

After you've finished written a table definition, you can create SQL files with the sql sub command of this tool. If you want to output them as Go format, use the go sub command. For usage, the sql and go commands are almost same, so this README only contains the sql examples.

Output a file with --sheetid or -i option. In this case, all sheets are output.

$ tdconverter -i 1B8iFPPfyx81Q_0YDzGMN-a6zIw82B0x583A1eqcg_xA sql
complete!

If the sheet is already registered in the configuration, you can use that alias.

$ tdconverter -i sample sql
complete!

If you use --sheetname or -n option, you can output a file for only that sheet.

$ tdconverter -i sample -n sample sql
complete!

If you want to output files for each sheet, use --multi or -m option.

$ tdconverter -i sample -m sql
complete!

If you want to use common columns feature, specify the common sheet using --common or -c option.

$ tdconverter -i sample -c common sql
complete!
Show Configurations

You can show the configurations with conf sub command. Following list is the default configurations.

$ tdconverter conf
  NAME               | ALIAS  | SPREADSHEET ID
------------------------------------------------------------------------------
  tdconverter-sample | sample | 1B8iFPPfyx81Q_0YDzGMN-a6zIw82B0x583A1eqcg_xA
  tdconverter-common | common | 1MWfimYqzTtHwuw4i8JCZZwDnsvLCBVQGiOyMpH8-2IQ

You can add some configurations to tdconverter.json.

{
  "sheets": [
    {
      "name": "your sheet",
      "alias": "alias",
      "spreadsheet_id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    }
  ]
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL