carter-ya / idea-plugin-jpa-support

Generate entity/repositroy for JPA/Lombok/Spring Data JPA.
Apache License 2.0
166 stars 57 forks source link

Read Schema from native DDL SQL #5

Closed engineer-myoa closed 2 years ago

engineer-myoa commented 5 years ago

The first, Thank you for your nice project.

When I started some project to development phase, I haven't physical schema. So, I suggest feature for schema read from native ddl sql.

Currently, I'm developing this feature in IPJS-001

But there need some discussion. (e.g Whether to use plug-in for parsing sql, etc ... )

Please review it.

carter-ya commented 5 years ago

Thank you for your use.

I think use native DDL sql to generate POJO and Repo is a nice feature.

If we want to parse sql, We should use some lightweight sql parser, because we only use the parser/formatter, etc...

engineer-myoa commented 5 years ago

:) So, I recommend this repository ddl-parser

I think generating List through parser, We can pass tableSchemaList to AutoGeneratorSettingsFrame!

carter-ya commented 5 years ago

This parser is not compatible. Cannot be compatible with schema containing database name. For example:

drop table if exists dbname.table_name;
create table dbname.table_name (
  f_id bigint unsigned not null comment 'id',
  f_version bigint unsigned not null default 0 comment 'version',
  f_created_at bigint unsigned not null comment 'created at',
  f_updated_at bigint unsigned not null comment 'updated at',
  primary key (f_id)
) engine = InnoDB default charset utf8mb4 comment 'table comment';

And the stack trace:

java.lang.RuntimeException: Illegal character "." at line 0, column 27

    at com.moilioncircle.ddl.parser.utils.MySqlToken.nextToken(MySqlToken.java:2024)
    at com.moilioncircle.ddl.parser.MysqlDDLParser.nextToken(MysqlDDLParser.java:2313)
    at com.moilioncircle.ddl.parser.MysqlDDLParser.match(MysqlDDLParser.java:2324)
    at com.moilioncircle.ddl.parser.MysqlDDLParser.name(MysqlDDLParser.java:685)

If we modify the schema, for example:

create table table_name (
  f_id bigint unsigned not null comment 'id',
  f_version bigint unsigned not null default 0 comment 'version',
  f_created_at bigint unsigned not null comment 'created at',
  f_updated_at bigint unsigned not null comment 'updated at',
  primary key (f_id)
) engine = InnoDB default charset utf8mb4 comment 'table comment';

Output:

TableInfo: 
 tableName=table_name
 pks=[]
 columns=[[columnName=f_id, type=BIGINT], [columnName=f_version, type=BIGINT], [columnName=f_created_at, type=BIGINT], [columnName=f_updated_at, type=BIGINT]]

It can't recognized primary key...

engineer-myoa commented 5 years ago

(Sorry, too late response)

You are right. It isn't compatible. Very nice example 👍 That parser also too complex That can not modify.

We can find any other! :)

carter-ya commented 5 years ago

Now,I have released a new version of the plugin (1.0.7). Support English and 简体中文.

carter-ya commented 5 years ago

druid Maybe the parser is a good choice?

engineer-myoa commented 5 years ago

It is too heavy if use only for parser.

But it has advantages also, It is large project. To make dispute or issue easily. And more trusted. (at least other project)

We need to verify this :) (but really sorry, my company is too busy. please forgive me, too late response T.T)