Turbine is a toy CLI app for converting Rails schema declarations into equivalent type declarations in other languages.

Related tags

Command-line turbine
Overview

Turbine

Turbine is a toy CLI app for converting Rails schema declarations into equivalent type declarations in other languages.

It’s described as a toy because the parsing of schema files is less than robust, and the conversion into type declarations is somewhat limited. Basically, use it at your own risk sort of thing.

USAGE:
    turbine [OPTIONS] <SCHEMA>

ARGS:
    <SCHEMA>    Specifies the location of the Rails schema file

FLAGS:
    -h, --help       Print help information
    -V, --version    Print version information

OPTIONS:
    -f, --format <FORMAT>    Specifies type definition format to convert the schema file into
                             [default: spec] [possible values: spec, rust, typescript]
    -o, --output <OUTPUT>    Where to save the output. If no name is specified it defaults to stdout

Example Output

Given a rails schema of

ActiveRecord::Schema.define(version: 2021_09_16_202951) do
  create_table "sample_schema", id: :serial, force: :cascade do |t|
    t.primary_key "a"
    t.string "b"
    t.text "c"
    t.integer "d"
    t.bigint "e"
    t.float "f"
    t.decimal "g"
    t.numeric "h"
    t.datetime "i"
    t.time "j"
    t.date "k"
    t.binary "l"
    t.boolean "m"
    t.hstore "n"
    t.jsonb "o"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end
end

Clojure Spec

(spec/def sample_schema
  {:a int?
   :b string?
   :c string?
   :d int?
   :e int?
   :f float?
   :g float?
   :h int?
   :i string?
   :j string?
   :k string?
   :l string?
   :m boolean?
   :n map?
   :o map?
   :created_at string?
   :updated_at string?})

Rust

struct SampleSchema {
   a: usize,
   b: String,
   c: String,
   d: i64,
   e: i128,
   f: f64,
   g: f64,
   h: i64,
   i: String,
   j: String,
   k: String,
   l: Vec<u8>,
   m: bool,
   n: std::collections::HashMap<String,String>,
   o: std::collections::HashMap<String,String>,
   created_at: String,
   updated_at: String,
}

TypeScript

type SampleSchema {
  a: number;
  b: string;
  c: string;
  d: number;
  e: number;
  f: number;
  g: number;
  h: number;
  i: string;
  j: string;
  k: string;
  l: string;
  m: bool;
  n: any;
  o: any;
  created_at: string;
  updated_at: string;
}

Building

I have not set up, like, any CI/CD for this. So if you want a copy you’ll have to build it yourself. Luckily, Rust makes this pretty easy.

$ cargo build --release
 # or if you want to install it onto your path
$ cargo install --path .

Where laziness won

For example, when turbine encounters a JsonB column or HStore column, it will type out these values as the safest possible types for their language. IE: any in TypeScript, map? in Clojure Spec and HashMap in Rust. Additionally, all date/time types are represented as strings. I did this because of laziness, the possibility of date/times not represented in the base language, and when interacting with an API, it’s probably a string already.

The Rails schema parser is also the simplest form I could build. It looks for create_table declarations, captures the next word as the name for the type and then looks for a word like “t.integer” to describe the type of the column. If the column declaration doesn’t start with “t.” or is surrounded by strings, things will break and break badly. So, don’t do that.

Finally, it doesn’t handle where columns can be nullable… yet.

You might also like...
Tool for mass import of hosts into Zabbix (and other API functions)

zabbix-tools A CLI tool for interacting with Zabbix API built in Rust. Designed for Zabbix 6.0. Functions added to test API and add hosts manually or

Transform jsx/tsx files to reactive views in js/ts to use in Web Components, insert into DOM or integrate with other libraries/frameworks
Transform jsx/tsx files to reactive views in js/ts to use in Web Components, insert into DOM or integrate with other libraries/frameworks

viewmill Features | Installation | Getting Started | Notes | Examples viewmill is aimed to create complex UIs from a simple form of JSX. It statically

A CLI for analyzing the programming languages and how much code written in a project.
A CLI for analyzing the programming languages and how much code written in a project.

projlyzer A CLI for analyzing the programming languages and how much code written in a project. New features are on the way... Example Screenshot Buil

Traverse DMMF of Prisma schema, in your terminal

Let's DMMF Traverse DMMF of Prisma schema, in your terminal. Powered by jless. Installation brew tap yujong-lee/tap brew install letsdmmf Usage # lets

Event-sourcing Schema Definition Language

ESDL Event-sourcing Schema Definition Language Schema definition language for defining aggregates, commands, events & custom types. Heavily inspired b

This crate provides a set of functions to generate SQL statements for various PostgreSQL schema objects

This crate provides a set of functions to generate SQL statements for various PostgreSQL schema objects, such as tables, views, materialized views, functions, triggers, and indexes. The generated SQL statements can be useful for schema introspection, documentation, or migration purposes.

A todo list app that indexes your app to find TODO:'s

forgot A todo list app that indexes your app to find TODO:'s Usage to list all your todos forgot list list all your todos ignoring search in ./target,

Next-generation, type-safe CLI parser for Rust

Next-generation, type-safe CLI parser for Rust

a (soon to be) calculator frontend and a (soon to be optimizing) toy IR backend

Zach-Calc Zach-Calc is a pet project for me to try and better understand pattern matching, optimization, IRs, and the likes. ./libs/* contains librari

Owner
Justin
Justin
A crate that allows you to mostly-safely cast one type into another type.

A crate that allows you to mostly-safely cast one type into another type. This is mostly useful for generic functions, e.g. pub fn foo<S>(s: S) {

Bincode 3 Sep 23, 2023
Explain semver requirements by converting them into less than, greater than, and/or equal to form.

semver-explain Convert SemVer requirements to their most-obvious equivalents. semver-explain is a CLI tool to explain Semantic Versioning requirements

Andrew Lilley Brinker 27 Oct 29, 2022
Striving to create a great Application with full functions of learning languages by ChatGPT, TTS, STT and other awesome AI models

Striving to create a great Application with full functions of learning languages by ChatGPT, TTS, STT and other awesome AI models, supports talking, speaking assessment, memorizing words with contexts, Listening test, so on.

null 155 Apr 20, 2023
Programming language made by me to learn other people how to make programming languages :3

Spectra programming language Programming language made for my tutorial videos (my youtube channel): Syntax Declaring a variable: var a = 3; Function

Adi Salimgereyev 3 Jul 25, 2023
A simple CLI tool for converting CSV file content to JSON.

fast-csv-to-json A simple CLI tool for converting CSV file content to JSON. 我花了一個小時搓出來,接著優化了兩天的快速 CSV 轉 JSON CLI 小工具 Installation Install Rust with ru

Ming Chang 3 Apr 5, 2023
Demo app duplicated in 5 languages (Go/JavaScript/Python/Ruby/Rust) showing how to go from source code to container image using melange+apko

hello-melange-apko ?? This repo contains an example app duplicated across 5 languages showing how to: Package source code into APKs using melange Buil

Chainguard 16 Jan 23, 2023
zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.

zigfi zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets

Aldrin Zigmund Cortez Velasco 18 Oct 24, 2022
Blazingly fast Rust CLI app to sync data from a folder of excel workbooks into generated c# code for unity usage

Extensions supported ( .xls, .xlsx, .xlsm, .xlsb, .xla, .xlam, .ods ) Speed Test Image shows the results of 5000defs synced from 2 workbooks and 5 she

null 4 Feb 16, 2023
🦀️atos for linux by rust - A partial replacement for Apple's atos tool for converting addresses within a binary file to symbols.

atosl-rs ??️ atos for linux by rust - A partial replacement for Apple's atos tool for converting addresses within a binary file to symbols. tested on

everettjf 60 Dec 29, 2022
A blazingly fast command-line tool for converting Chinese punctuations to English punctuations

A blazingly fast command-line tool for converting Chinese punctuations to English punctuations

Hogan Lee 9 Dec 23, 2022