| Premshree Pillai ( @ 2005-01-30 22:13:00 |
| Current music: | Dido - White Flag |
No XML here
So I’m at office on a Sunday, designing a database schema. I started out with writing the structures as SQL queries; I figured I’d write a parser—to generate formatted documentation. Bad idea. For one, I wouldn’t have been able to add any metadata.
I’m using YAML now, instead. I’m using a simple schema to design the tables:
tables:
table_name:
-field:
type: type
isnotnull: 0|1
default:
description:Constructing the queries and generating formatted documentation is simple now. I’m using yaml4r:
#!/usr/local/bin/ruby
require 'yaml'
tree = YAML::parse(File.open('tables.yaml'))
table_name = 'foo'
types = tree.select('/tables/' + table_name + '/*/type').transform
isnotnulls = tree.select('/tables/' + table_name + '/*/isnotnull').transform
defaults = tree.select('/tables/' + table_name + '/*/default').transform
descriptions = tree.select('/tables/' + table_name + '/*/description').transform
all_data = [types, isnotnulls, defaults, descriptions]
all_data.each { |data|
# do stuff
}Less work than XML. A similar format, based on Python, is SLiP. My problem with SLiP is that blocks are separated using indentation—I’m somehow not happy with the idea of block separation using indentation for the purpose of representing semantic information. YAML, on the other hand, gives you the option of using block styles or flow styles.