SchemaCrawler Java API 检索检查列约束
SchemaCrawler Java API retrieve check column constraints
每个 this 问题及其评论,为了获得约束(我对检查约束特别感兴趣),必须执行以下操作:
包括一个 .jar
对应于他们选择的数据库驱动程序,例如 schemacrawler-postgresql or schemacrawler-sqlite.
将详细级别设置为 detailed
(或更高),如下所示:
val optionsBuilder = SchemaCrawlerOptionsBuilder.builder()
.withLoadOptions(LoadOptionsBuilder.builder()
.withSchemaInfoLevel(SchemaInfoLevelBuilder.detailed())
.toOptions()
)
val options = optionsBuilder.toOptions()
val catalog = SchemaCrawlerUtility.getCatalog(dataSource.get(), options)
- 使用
Table.getTableConstraints()
方法。
我已经包含了 PostgreSQL、SQLite、MySQL 的 .jar
文件,但我只得到了 PostgreSQL 的约束,而对于 SQLite 和 MySQL,结果都是空的(并且不仅有检查约束,也没有空约束,但也没有它们的迹象;可以通过检查列是否可以直接为空来检索此信息,但检查约束没有这样的API)。有没有我没有考虑过的额外步骤?包括 MySQL 的 .jar
似乎有助于解决上面链接的问题。
我的依赖如下:
implementation("us.fatehi:schemacrawler:16.9.3")
implementation("us.fatehi:schemacrawler-mysql:16.9.3")
implementation("us.fatehi:schemacrawler-sqlite:16.9.3")
implementation("us.fatehi:schemacrawler-postgresql:16.9.3")
我认为你做的一切都是正确的。 SchemaCrawler sources its information from what the JDBC driver provides, and from the database's data dictionary (or INFORMATION_SCHEMA
views). SchemaCrawler will not infer any metadata. So, in your case, if neither the MySQL JDBC driver nor the MySQL INFORMATION_SCHEMA
report constraints, SchemaCrawler will not retrieve them. In this case, if you want to find NULL
constraints, your best bet is to traverse the metadata and look for columns that are not nullable. You can build a utility method to do this, or submit an SchemaCrawler 此实用程序的增强请求。如果 JDBC 驱动程序和数据字典视图都没有报告检查约束,我没有很好的建议。
Sualeh Fatehi,SchemaCrawler
每个 this 问题及其评论,为了获得约束(我对检查约束特别感兴趣),必须执行以下操作:
包括一个
.jar
对应于他们选择的数据库驱动程序,例如 schemacrawler-postgresql or schemacrawler-sqlite.将详细级别设置为
detailed
(或更高),如下所示:
val optionsBuilder = SchemaCrawlerOptionsBuilder.builder()
.withLoadOptions(LoadOptionsBuilder.builder()
.withSchemaInfoLevel(SchemaInfoLevelBuilder.detailed())
.toOptions()
)
val options = optionsBuilder.toOptions()
val catalog = SchemaCrawlerUtility.getCatalog(dataSource.get(), options)
- 使用
Table.getTableConstraints()
方法。
我已经包含了 PostgreSQL、SQLite、MySQL 的 .jar
文件,但我只得到了 PostgreSQL 的约束,而对于 SQLite 和 MySQL,结果都是空的(并且不仅有检查约束,也没有空约束,但也没有它们的迹象;可以通过检查列是否可以直接为空来检索此信息,但检查约束没有这样的API)。有没有我没有考虑过的额外步骤?包括 MySQL 的 .jar
似乎有助于解决上面链接的问题。
我的依赖如下:
implementation("us.fatehi:schemacrawler:16.9.3")
implementation("us.fatehi:schemacrawler-mysql:16.9.3")
implementation("us.fatehi:schemacrawler-sqlite:16.9.3")
implementation("us.fatehi:schemacrawler-postgresql:16.9.3")
我认为你做的一切都是正确的。 SchemaCrawler sources its information from what the JDBC driver provides, and from the database's data dictionary (or INFORMATION_SCHEMA
views). SchemaCrawler will not infer any metadata. So, in your case, if neither the MySQL JDBC driver nor the MySQL INFORMATION_SCHEMA
report constraints, SchemaCrawler will not retrieve them. In this case, if you want to find NULL
constraints, your best bet is to traverse the metadata and look for columns that are not nullable. You can build a utility method to do this, or submit an SchemaCrawler 此实用程序的增强请求。如果 JDBC 驱动程序和数据字典视图都没有报告检查约束,我没有很好的建议。
Sualeh Fatehi,SchemaCrawler