Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create model from existing table #108

Closed
federico-razzoli opened this issue Mar 1, 2019 · 9 comments
Closed

Create model from existing table #108

federico-razzoli opened this issue Mar 1, 2019 · 9 comments
Labels
enhancement New feature or request

Comments

@federico-razzoli
Copy link

Red should be able to create a model from an existing table.

Motivations:

  • a DBA shouldn't be required to learn an ORM to check table structures
  • a user could want to use a feature that is not supported by Red, creating the table in SQL
  • maybe a table has been created by another application
@FCO FCO added the enhancement New feature or request label Mar 1, 2019
@jonathanstowe
Copy link
Contributor

The only difficulty with this is that the mechanism to determine the structure of a table varies wildly between database engines, so there will be a lot of code. It might be worth starting with some abstract representation for a model that can generate the code. I made one for Informix years ago and it was a pain.

@FCO
Copy link
Owner

FCO commented Mar 1, 2019

I think we should create a AST for creating models, and each Driver could read its database and create the AST... than we would have only one code generating the model...

Sent with GitHawk

@jonathanstowe
Copy link
Contributor

Sounds like a plan.

@FCO
Copy link
Owner

FCO commented Mar 1, 2019

Would it be a cli tool?

Sent with GitHawk

@federico-razzoli
Copy link
Author

It's also possible to read the metadata from information_schema tables. Except that SQLite doesn't have information_schema.

@FCO
Copy link
Owner

FCO commented Jul 23, 2019

@federico-razzoli @jonathanstowe I'm starting implementing it with this commit 67eca7e it seems to be working good (still far from complete).

@FCO
Copy link
Owner

FCO commented Jul 23, 2019

It's also possible to read the metadata from information_schema tables. Except that SQLite doesn't have information_schema.

It does! It's called sqlite_master! https://github.com/FCO/Red/blob/master/lib/Red/Driver/SQLite/SQLiteMaster.pm6

@jonathanstowe
Copy link
Contributor

I guess that they've done that for the convenience of making a DB dump, but it's not very convenient for doing anything else with it.

@FCO
Copy link
Owner

FCO commented Nov 20, 2019

@FCO FCO closed this as completed Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants