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

go-jet can't generate table model files and table sql builder files #241

Closed
Chinnasit opened this issue May 28, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@Chinnasit
Copy link

Describe the bug
when using the command :
jet -source=mysql -dsn="user:pass@tcp(localhost:3306)/dbname" -path=./gen

command output :
Connecting to MySQL database...
Retrieving database information...
FOUND 1 table(s), 0 view(s), 0 enum(s)
Destination directory: gen/book_store
Cleaning up destination directory...
Generating table model files...
17:1: expected '}', found 1 (and 1 more errors)

but when I delete a comment in the SQL command COMMENT 'e\r\n1' so jet generator works

Environment (please complete the following information):

  • OS : Windows
  • Database : AWS RDS for MySQL
  • Database driver : [e.g. pq, pgx]
  • Jet version : 2.10.0

Code snippet
SQL Editor in DBeaver :
CREATE TABLE books (
id int NOT NULL AUTO_INCREMENT,
rate decimal(10,2) DEFAULT '0.00' COMMENT 'e\r\n1',
PRIMARY KEY (id)
)ENGINE=InnoDB AUTO_INCREMENT=250 DEFAULT CHARSET=utf8mb4;

Expected behavior
can generate table model files and table sql builder files

@Chinnasit Chinnasit added the bug Something isn't working label May 28, 2023
@joefrancia
Copy link

I get a very similar thing with the two tables below. Let me know if it's ok to keep these in the same issue, or if I should open a new one

This one fails because someone messed up the second column name. It appears they programmatically generated the table and forgot to add an alias for the column name. Ignoring the table during the gen phase was enough to get around this, as I don't need this table in my app:

CREATE TABLE `Compliance` (
  `PatientID` int(11) DEFAULT NULL,
  `Concat(Patients.LastName, ', ', Patients.FirstName)` varchar(102) COLLATE utf8_unicode_ci DEFAULT NULL,
  `Type` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
  `Label` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB;
Connecting to MySQL database...
Retrieving database information...
	FOUND 59 table(s), 3 view(s), 3 enum(s)
Destination directory: .gen/MySchema
Cleaning up destination directory...
Generating table model files...
16:25: expected ')', found ',' (and 1 more errors)

And this one the Operator ENUM fails because of the = sign presumably. I also added this table to the -ignore-tables option, but it still tried to read the ENUM and failed. Adding this ENUM to -ignore-enums was enough to get around it:

CREATE TABLE `Rules` (
  `RuleID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `Label` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
  `RuleSQL` varchar(4000) COLLATE utf8_unicode_ci DEFAULT NULL,
  `Allowance` int(10) unsigned DEFAULT '0',
  `AllowEmptySet` tinyint(1) unsigned DEFAULT '0',
  `Operator` enum('=','!=','<=','>=','<','>','IN') COLLATE utf8_unicode_ci DEFAULT NULL,
`TableName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB;
Connecting to MySQL database...
Retrieving database information...
	FOUND 133 table(s), 1 view(s), 16 enum(s)
Destination directory: .gen/MySchema
Cleaning up destination directory...
Generating table model files...
Generating view model files...
Generating enum model files...
16:58: expected '==', found '=' (and 4 more errors)

@go-jet
Copy link
Owner

go-jet commented Jun 3, 2023

Hi @Chinnasit , @joefrancia ,
Good catch. It seems additional character escapes are needed.

@go-jet go-jet added this to the Version 2.11.0 milestone Jun 3, 2023
@go-jet
Copy link
Owner

go-jet commented Jul 24, 2023

@Chinnasit
The issue with mysql comment containing an ASCII control character is fixed with Release v2.10.1.
@joefrancia
At first, I thought to remove non-golang identifier characters from the name, but that would create additional problems down the road. For instance, your enum values contains only non-golang identifier characters.
For situations like this, it is best to create generator customization and change the name from the code manually. Take a look at these two tests: TestRenameEnumValueName and TestGeneratorTemplate_Model_SqlBuilder_RenameStructFieldNames.

@go-jet go-jet closed this as completed Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants