Skip to content

Add support for custom types to ddl2cpp#110

Merged
rbock merged 10 commits intorbock:custom_typefrom
matthijs:custom_type
Mar 29, 2026
Merged

Add support for custom types to ddl2cpp#110
rbock merged 10 commits intorbock:custom_typefrom
matthijs:custom_type

Conversation

@matthijs
Copy link
Copy Markdown
Contributor

@matthijs matthijs commented Mar 28, 2026

See issue #106

Add three possible ways for mapping columns to user-defined types.

  1. By using --path-to-cpp-types <csv>
  2. Inline SQL leading comments
  3. PostgreSQL extension: handle unmodified pg_dump output

I haven't checked where mysqldump or sqlite3 puts the comments. If you have an example of how that looks I can try to fix that too.

A somewhat unrelated change but it caused me a headache, add the possibility to strip the schema from the table (pg_dump includes the schema in the CREATE TABLE statement).

And of course, updated the documentation.

@rbock
Copy link
Copy Markdown
Owner

rbock commented Mar 29, 2026

Thanks, this looks pretty cool already!

Can you add some tests, too?

MySQL dump with comment:

DROP TABLE IF EXISTS `tab_foo`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `tab_foo` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `text_nn_d` varchar(255) NOT NULL DEFAULT '',
  `int_n` int DEFAULT NULL COMMENT 'cpp_type:test::my_int',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

sqlite3 does not seem to support column comments officially, see docs. But it seems to happily accept comments in the same way as MySQL above.

@matthijs
Copy link
Copy Markdown
Contributor Author

I've updated the MR based on your comments.

Also added a note about the sqlite backend. According to what I found on internet only inline comments are supported (and preserved when dumped).

@rbock
Copy link
Copy Markdown
Owner

rbock commented Mar 29, 2026

Nice! Thanks for the super swift implementation, the support for multiple options, and the clean documentation!

@rbock rbock merged commit 622d25b into rbock:custom_type Mar 29, 2026
1 check passed
rbock pushed a commit that referenced this pull request Mar 29, 2026
* Add support for special (custom) cpp types (using a csv file)
* Add parsing support for custom types as annotation in the leading comments of a type (cpp_type:<type>)
* When a cpp_type annotation exists dont emit an error SQL data type for .. is not supported.
* Improve ddl2cpp documentation by adding c++ user-defined type support.
* Add unit tests for the user-defined types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants