suburbia

Premshree's (品速力) Personal Weblog

etc.

Ruby code to generate SQL and docs
suburbia
[info]premshree
So here’s the Ruby code I’m using (that I said about) to generate SQL queries:

#!/usr/local/bin/ruby
# $premshree$ $2005-02-09 22:35$

require 'yaml'
tree = YAML::parse(File.open(file))
dbname = tree.transform.keys[0]
dbquery = "CREATE DATABASE IF NOT EXISTS #{dbname};\n\nUSE #{dbname};\n\n"
print dbquery

tables = tree.select("#{dbname}").transform[0]
tables.keys.each { |table|
	query = "CREATE TABLE #{table} (\n"
	fields = tree.select("#{dbname}/#{table}").transform[0]
        fields.keys.each { |field|
        	type = tree.select("#{dbname}/#{table}/#{field}/type").transform[0]
		isnotnull = tree.select("#{dbname}/#{table}/#{field}/isnotnull").transform[0]
		default = tree.select("#{dbname}/#{table}/#{field}/default").transform[0]
		description = tree.select("#{dbname}/#{table}/#{field}/description").transform[0]
		temp = field.split("-")[1]
		query = query + "   " + temp + " " + type
                if isnotnull
                	query = query + " NOT NULL"
		end
		if default != nil
			#print default.class
			if default.class == "String"
				query = query + " DEFAULT " + "'" + "#{default}" + "'"
			else
				query = query + " DEFAULT '#{default}'"
			end
		end
		if fields.keys[fields.keys.length - 1] != field
			query = query + ","
		end
		query = query + "\n"
        }
        query = query + ");"
        print query
}

The YAML schema that I’m using:

database_name:
   table_name:
      -field_name:
          type: type
          isnotnull: 0|1
          default:
          description:

	  ...

      -field_name:
          type: type
          isnotnull: 0|1
          default:
          description:

	  ...

   table_name:
      -field_name:
          type: type
          isnotnull: 0|1
          default:
          description:

	  ...

      -field_name:
          type: type
          isnotnull: 0|1
          default:
          description:

Ah, I have to come up with some neat documentation format.


Amazon and 43 Things
suburbia
[info]premshree
Amazon puts cash into blogging:

Amazon is dipping its toe in the web log phenomenon with an investment in 43 Things, a new website where people write about their goals and accomplishments and are linked to others with similar interests.

The Nice Thing, you ask? 43 Things is developed using Rails.


Ruby India User Group
suburbia
[info]premshree
So we have one now.

(no subject)
suburbia
[info]premshree
Deccan is consistent in its delays. My flight’s delayed by 35 minutes—that’s what they say. I’d much rather they tell me that the flight’s delayed by 12 hours than incrementally fuck my mind.

In that case I’ll have to book my ticket for a day before the Mark Knopfler concert (not sure yet if I’m going, though.) This year seems loaded with Good Stuff. The Eagles is one thing that even my dad—who prefers his music at home—wouldn’t wanna miss.

Update (18:20): Eventual delay: one hour.