Skip to content

Type conversions

Vlad edited this page Nov 29, 2017 · 15 revisions

Yaml and SQL(and different SQL dialects, of course) have slightly different system of types and it means that some of YML types could not be easily converted to SQL "as is" or "one to one".

String literals

YAML Strings will be implicitly converted to SQL string literals and formatted depending on the selected SQL dialect. For SQL99, for instance, the string value will be surrounded with single quotes: Hello in YAML turns into 'Hello' in SQL.

There is also an explicit way to declare a string literal - it is a text: prefix. So text:hello turns into 'hello', text:text turns into 'text', etc.

Plain SQL values

As it was described above, string values will be converted to SQL string literals(Homer turns to 'Homer'), but what if we need to write a SQL expression itself as a value? String values may have a special sql: prefix for these purposes: sql:DEFAULT turns to DEFAULT, sql:NOW() turns to NOW() and so on.

Having sql: and text: prefixes it is possible to express any string literal and any plain SQL expression.

NULL

YAML nulls (~, null, Null, NULL or just empty value) will be converted to NULL

Booleans

YAML booleans will be converted to either TRUE or FALSE literals.

Integer and floats

Integers and floats will be converted to SQL as they are like 5, 200 and 3.14 numeric literals

Not supported types

Following YAML types are not supported by JFixtures at the moment and an exception will be thrown if they occur:

We plan to support these types in the future, at least partially and for some SQL dialects, but for now, please use plain SQL values to express complicated and non trivial SQL types.

References