database

relational-database-bridge grammar version 109

'tables': dictionary {
	'source': [ : table = ] group {
		'scoped': stategroup (
			'yes' {
				'namespace': text
				'selection': component 'table selector'
			}
			'no' { }
		)
		'source': text
		'inline tables': stategroup (
			'yes' { [ inline-tables (experimental) ]
				'sub tables': dictionary {
					'fields': [ fields ] dictionary {
						'definition': component 'field'
					}
					'join key': [ join ] dictionary {
						'contra field': [ == ] reference
					}
				}
			}
			'no' { }
		)
	}
	'fields': [ fields ] dictionary {
		'source': [ = ] stategroup (
			'reference' {
				'field': text
				'definition': component 'field'
			}
			'inline reference' { [ inline ]
				'inline table': reference
				'inline field': [ . ] reference
			}
		)
	}
	'has primary key': stategroup (
		'yes' { [ primary-key ]
			'primary key': dictionary { }
		}
		'no' { }
	)
	'unique indices': dictionary { [ unique-index ]
		'fields': [ (, ) ] dictionary { }
	}
	'foreign keys': [ foreign-keys ] dictionary {
		'table': [ => table ] reference
		'on': [ where ] stategroup (
			'primary key' { [ primary-key ]
				'key fields': [ (, ) ] dictionary {
					'contra field': [ == ] reference
				}
			}
			'unique index' { [ unique-index ]
				'index': reference
				'key fields': [ (, ) ] dictionary {
					'contra field': [ == ] reference
				}
			}
		)
	}
	'text encoding': stategroup (
		'ascii' { }
		'utf8' { [ text-encoding : utf8 ] }
	)
	'prefilters': group {
		'join statements': dictionary { [ join ] }
		'has where clause': stategroup (
			'yes' { [ where ]
				'where statement': component 'filter statement list'
			}
			'no' { }
		)
	}
}
'field' {
	'data type': [ as ] stategroup (
		'text' { [ text ]
			'import rule': stategroup (
				'fixed length' { [ (, ) ]
					'rule: trim': stategroup (
						'both' { [ trim-both ] }
						'left' { [ trim-left ] }
						'right' { [ trim-right ] }
						'none' { }
					)
					'length': integer
				}
				'no' { }
			)
		}
		'floating point' { [ float ] }
		'decimal' { [ decimal ]
			'rounding': stategroup (
				'ordinary' { }
				'ceil' { [ ceil ] }
				'floor' { [ floor ] }
			)
			'scale': [ (, ) ] integer
		}
		'integer' { [ integer ] }
		'boolean' { [ bool ] }
		'enum' { [ enum ]
			'values': [ (, ) ] dictionary { }
		}
	)
	'nullable': stategroup (
		'yes' { [ (nullable) ] }
		'no' { }
	)
	'has description': stategroup (
		'yes' {
			'description': [ </, /> ] text
		}
		'no' { }
	)
}
'table selector' {
	'has step': stategroup (
		'yes' {
			'name': [ . ] text
			'tail': component 'table selector'
		}
		'no' { }
	)
}
'number list' {
	'step type': stategroup (
		'single value' {
			'value': integer
		}
		'range' {
			'begin value': integer
			'end value': [ ... ] integer
		}
	)
	'has more steps': stategroup (
		'yes' {
			'tail': component 'number list'
		}
		'no' { }
	)
}
'filter statement' {
	'type': stategroup (
		'contains' {
			'field': [ . ] reference
			'comparison': stategroup (
				'in' { [ in ]
					'arguments': [ (, ) ] dictionary { }
				}
				'not in' { [ not in ]
					'arguments': [ (, ) ] dictionary { }
				}
			)
		}
		'search' {
			'field': [ . ] reference
			'type': stategroup (
				'starts with' { [ starts-with ] }
				'contains' { [ contains ] }
				'equals' { [ equals ] }
			)
			'substring': text
		}
		'compare' {
			'field': [ . ] reference
			'operator': stategroup (
				'smaller' { [ < ] }
				'greater' { [ > ] }
				'equal' { [ == ] }
				'not equal' { [ != ] }
			)
			'right': stategroup (
				'property' {
					'right': [ . ] reference
				}
				'static number' {
					'value': integer
				}
				'static text' {
					'value': text
				}
				'time span' {
					'days': [ current-date - ] integer
				}
			)
		}
		'null' {
			'field': [ ., is null ] reference
		}
		'in list' {
			'field': [ . ] reference
			'number list': [ (, ) ] component 'number list'
		}
		'foreign key' { [ foreign-key ]
			'foreign key': reference
		}
		'incoming foreign key' { [ this ]
			'source table': [ in table ] reference
			'incoming link': [ >> ] reference
		}
		'invert' { [ not ]
			'statement': component 'filter statement'
		}
		'list' { [ (, ) ]
			'statements': component 'filter statement list'
		}
	)
}
'filter statement list' {
	'statement': component 'filter statement'
	'has more statements': stategroup (
		'yes' {
			'operator': stategroup (
				'and' { [ and ] }
				'or' { [ or ] }
			)
			'tail': component 'filter statement list'
		}
		'no' { }
	)
}