~rbn/rom

read schema information from various DBMS and create go code to access the data

#1 split output templates/functions

~rbn filed ticket on rom todo

3 days ago
~rbn/rom

New ticket tracker added

18 days ago

#rom, relational object mapper

builds.sr.ht status GoDoc

reads schema information from various DBMS and generates according code.

#install

go install go.rbn.im/rom/cmd/rom

#supported databases

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

#usage

commandline 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")
  -mysql
    	read a mysql/maria database
  -package string
    	package name of generated code (default "foobar")
  -schema string
    	schema to read information for (default "schema")
  -sqlite
    	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.

#examples

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 & todos

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 https://www.sqlite.org/datatype3.html 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.

#contact

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