jihantoro

jihantoro

Ecto Schema Generator

hi, i have a lot of table in my db, is there any tool that automaticallly generate schema based on table column (with column types, etc)

something like, i just need to define credentials and database, and the tool will generate schema for all table

Most Liked

mikemccall

mikemccall

I was looking for a tool like this too. Something that worked much like django’s inspect.db. I ended up writing some one off scripts and using phoenix’s mix phx.gen.schema.

You can obtain information about your database using something like:

select *
from INFORMATION_SCHEMA.TABLES
where table_schema = 'database';

and

select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'table_name';

I still ended up doing plenty manual work but this did save a lot of time. It was a one off thing it didn’t bother me too much. I don’t know how much that helps but it’s another option.

Eiji

Eiji

Firstly it uses template. I think that much better is simple macro here. It’s harder to read its code. Secondly it supports really low number of types. I can see only DateTime, but no Date and Time. There is no array support as well as json/jsonb support. Thirdly it generates field with float type for decimal database type. As said of course such tool does not support lots of other things which @jihantoro would need to change anyway. There could be a good scenic tool which asks what to do in special cases, but such generator is too limited and there is no simple solution for all edge cases. Of course we could say that’s enough at start, but if you have really big number of different tables then ensuring that decimal have proper declaration is not so easy too while project could still compile which causes lots of confusion. For example think how to properly support enum inside json/jsonb column.

benperiton

benperiton

Possibly helpful posts;

Last Post!

OvermindDL1

OvermindDL1

For note, I wouldn’t really consider such a tool very useful, schema’s should match the query patterns, which may not necessarily match the tables. In my case I do have a schema ‘near’ matching each table, but I also have a lot more schemas for all the return data from the queries to keep everything typed and clean. (Except in a few cases where I return maps/lists/tuples/whatever for dynamic or pipelining reasons.)

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement