Support customized SQL formater for SchemaExport

Description

The default SQL formatter that comes with NHibernate adds extraneous indentation. IFormatter interface is public but SchemaExport doesn't expose an interface to set its formatter. Working around with reflection is definitely not elegant.

Hope that a formatter class can be specified in addition to the format_sql boolean configuration setting, so that customized formatter can be used.

Environment

None

Activity

Show:

Yufan Lou August 8, 2017 at 5:31 PM
Edited

I see. I definitely welcome a way to override the formatters. That's how I initially wanted to do it. Currently in SchemaExport the format style is hardcoded in Initialize() function without a formatter property to set.

Frédéric Delaporte August 8, 2017 at 3:18 PM

Why not adding the possibility of configuring a custom formatting class, of course implementing IFormatter.

Your proposition would mean defining a unique formatter, whatever the SQL, be it DDL or DML. Currently, when formatting SQL is enabled, it uses the basic formatter for DML and the DDL formatter for DDL. (Otherwise it uses the no format formatter, which as shown here does not do anything.)

There are many places where this choice is done, so introducing the new sql_formatter setting would have many impacts, while lacking the ability to specify specialized formatter for DDL/DML.

So maybe a way to override FormatStyle.Basic, FormatStyle.Ddl and FormatStyle.None Formatter should be added instead. This would let format_sql logic still pick the appropriate formatter depending on the context and setting.

But there is no configuration point for such static properties, so it would be up to the user to set its custom formatters (maybe directly by switching the FormatStyle.Formatter setter to public) before the application starts using NHibernate.

A "complete" configurable solution would likely require quite more work, like moving the formatter choice handling to the session factory and allowing to customize it there.

Yufan Lou August 8, 2017 at 1:01 PM
Edited

The affected configuration interfaces are:

  • format_sql in XML

  • db.LogFormattedSql in loquacious

I think it is fine to add an additional interface called respectively

  • sql_formatter

  • db.SqlFormatter<IFormatter>()

I am new to NHibernate so please help me by pointing out other potential impact this may have.

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?

Created August 7, 2017 at 6:03 PM
Updated August 8, 2017 at 5:33 PM
Who's Looking?