I have written a functional grammar to exchange dbunit in scala known as ScalaDBTest. The entire program works - only required a couple of days to create. I acquired lots of sprucing up to complete.

Anyway, the grammar I am using for that DSL to input data in to the database is malleable and I would like some feedback onto it.

The fundamental syntax appears like this. It's really quite simple:

country:
- country_id: 1, name: "Canada"
- country_id: 2, name: "United States"

This is really much better than XML or SQL place claims.

I debated using ":" or "=". The previous looks better, however the latter appears automatic that i can type.

Gleam concept where one can "label" an archive. In this way, the above mentioned syntax was anonymous records. Labels is going to be a fascinating feature because they are utilized in a number of ways.

country:
    record: Canada -> country_id: 1, name: $label # produces "Canada"
    record: UnitedStates -> country_id: 2, name: $label.uncamel # produces "United States"

I dislike this syntax. It is a little two wordy. While using "-" does not look right, but when I personally use a real command word like "record", I have to place the "->" to split up them otherwise it appears really bad (you no longer need for technical reasons).

$label only will repeat the label, so that you can make use of the label in the minimum as method to reuse the string. $label.uncamel will prove to add spaces where it appears like camel situation.

The concept behind labels is to own APIs a method to access records without needing to recall the ids. Knowing the nation object you need to get is "Canada", you'll be able to just pass the label "Canada" and it'll convert it to some unique id and pull it from the database.

Here's a good example where one can specify default parameters:

province:
? country_id: 1, nice_weather: true
- province_id: 1, name: "British Columbia"
- province_id: 2, name: "Manitoba", nice_weather: false
- province_id: 3, name: "New York", country_id: 2

Here's had you been see some real energy. Many of these 3 'province' records may have 4 posts. Since 2 from the provinces come from Canada, they're instantly inherited in the default values. Within the 3rd situation, we override it with U . s . States for brand new You are able to. We are able to mix/match as needed.

Used, this will save lots of typing and cognitive load once we frequently only worry about a couple of values used, and also the relaxation could be mere placeholders to obtain the database to seal up about missing needed fields and so forth. This really aids in testing polymorphic objects too.

Here's another:

article:
? date_create: $now
- article_id: 1, title: "The Fed Sucks"
- article_id: 2, title: null

This snippet shows that you could really place null values without having done any methods as with dbUnit. In DbUnit, you need to first produce a transformer that translates a custom string (like "[NULL]") to actual null value.

Actually, we are able to be a lot more significant and provide a number of expressions and processes to assist generate data. For instance, $now returns a correctly formatted sql date of present day date/time. I'll expand on most of these features to make writing test data simpler.

Anyway, I am searching for assistance to really cleanup the syntax. I'm able to make any change, and as this is fresh, Let me allow it to be really snazzy from the beginning instead of change it out later.

Thanks

I'd consider embedding this in Scala instead of creating an exterior DSL. Features that will help are situation classes, default parameters, compiler produced copy techniques.

I'll suggest to extent the first syntax for that label within the following ways:

  1. Segment/Group label by column title.
    country: [label:title]
    - country_id: 1, title: "Canada"
    - country_id: 2, title: "U . s . States"
  2. Segment/Group label by column index, to reduce typing.
    country: [label:2]
    - country_id: 1, title: "Canada"
    - country_id: 2, title: "U . s . States"
  3. Single Recod
    country:
    -[label:2] country_id: 1, title: "Canada"
    -[label:title] country_id: 2, title: "U . s . States"

You are able to get rid of the index based labels if you do not wish to track the amount of posts within the record.

If you want to increase the tool you can include another characteristics like concurrency for that record groups, for example create 5K rows with 5 Threads is going to be something similar to this:


country: [label:title] [concurrency:5]
-[label:2] country_id: 1, title: "Canada"
-[label:title] country_id: 2, title: "U . s . States"