Command rom

Command rom reads schema information from various DBMS and generates according code.


go install

Supported Databases

currently supported are MySQL/MariaDB and SQLite. support for postgres is planned.


command line usage is as follows:

Usage of rom:
  -dsn string
    	data source name (default "schematest:schematest@unix(/var/run/mysql/mysql.sock)/information_schema?parseTime=True")
    	read a mysql/maria database
  -package string
    	package name of generated code (default "foobar")
  -schema string
    	schema to read information for (default "schema")
    	read a sqlite database

the switches -mysql and -sqlite are mutually exclusive. the -dsn switch must always select the "information_schema" database where applicable. currently this is the case for MySQL/MariaDB. the schema which code is generated for is selected by the -schema switch.


to generate code for a MariaDB schema named "foobar" you would run rom like this:

rom -mysql -dsn "user:pass@unix(/path/to/mysql.sock)/information_schema?parseTime=True" -schema "foobar"

an example of usage for SQLite would be:

rom -sqlite -dsn "/path/to/database.sqlite"

note that the -schema switch is ignored for sqlite.

Quirks & Todo

the generated code is.. questionable? this is fixable with templates which are read from files, as tastes may differ enough.

the whole foreign constraint reading is WIP, but should be really nice to have in the end.

to work correctly with SQLite databases, they need to contain data. reading an empty database generates errors, as there are no information about the data types which can be gathered then.

see for more information about this.

it would be interesting to generate code for other languages. this isn't that complicated, in the end replacing the output template and functions which filter go keywords with something more general should be enough.


email regarding this package (comments, questions, patches) can be send to "code ate".

Package Files

doc.go rom.go

Package main imports 7 packages (graph). Updated now.

Tools for package owners.