About the SQL to YAML
Test fixtures and seed data read better in YAML than in SQL. A reviewer sees named fields instead of counting positions in a tuple, and a change to one value produces a one line diff. This converter reads the INSERT statements from a dump and emits a list of records with the column names as keys.
Types survive the trip. Numbers stay numbers, NULL becomes an empty YAML value rather than the string "NULL", and text is quoted only when the YAML rules require it, which keeps the file uncluttered. Turn on Quote every string when a downstream parser is fussy, or when values such as yes, no and on would otherwise be read as booleans by an older YAML 1.1 loader.
A single table produces a plain list, which drops straight into a fixture loader. Tick the table name option and the list is nested under the table name instead, which is what fixture formats want when a file seeds several tables at once. Sorting keys makes two generated files comparable when only the column order differed.
The indent, quote style, flow style and document marker options exist because YAML house styles vary and a linter will complain about the wrong one. Validate the result with the YAML Validator, or convert to a structure instead with SQL to JSON.
How to use
- Paste the INSERT statements, or press Sample to load a shift roster.
- Set the indent and quote style your project linter expects.
- Tick the table name option when the file seeds more than one table.
- Copy the YAML, or download
rows.yaml.
Common questions
- How does NULL come out?
- As an empty YAML value, which a loader reads as null. It never becomes the four letter string NULL.
- Why are only some strings quoted?
- YAML needs quotes only where a value would otherwise be read as a number, a boolean or a special token. Tick Quote every string to force them everywhere.
- Can I convert several tables at once?
- Yes. Tick the table name option and each table becomes a top level key holding its own list of records.
- What does the flow style option do?
- It writes nested values inline with braces and brackets instead of indented blocks, which makes a compact file at some cost in readability.