examples/sql.rb in github-ds-0.1.0 vs examples/sql.rb in github-ds-0.2.0

- old
+ new

@@ -1,44 +1,55 @@ require File.expand_path("../example_setup", __FILE__) require "github/sql" -insert_statement = "INSERT INTO example_key_values (`key`, `value`) VALUES (:key, :value)" -select_statement = "SELECT value FROM example_key_values WHERE `key` = :key" -update_statement = "UPDATE example_key_values SET value = :value WHERE `key` = :key" -delete_statement = "DELETE FROM example_key_values WHERE `key` = :key" - ################################# Class Style ################################## -sql = GitHub::SQL.run insert_statement, key: "foo", value: "bar" +sql = GitHub::SQL.run <<-SQL, key: "foo", value: "bar" + INSERT INTO example_key_values (`key`, `value`) VALUES (:key, :value) +SQL p sql.last_insert_id # 1 -p GitHub::SQL.value select_statement, key: "foo" +p GitHub::SQL.value <<-SQL, key: "foo" + SELECT value FROM example_key_values WHERE `key` = :key +SQL # "bar" -sql = GitHub::SQL.run update_statement, key: "foo", value: "new value" +sql = GitHub::SQL.run <<-SQL, key: "foo", value: "new value" + UPDATE example_key_values SET value = :value WHERE `key` = :key +SQL p sql.affected_rows # 1 -sql = GitHub::SQL.run delete_statement, key: "foo" +sql = GitHub::SQL.run <<-SQL, key: "foo" + DELETE FROM example_key_values WHERE `key` = :key +SQL p sql.affected_rows # 1 ################################ Instance Style ################################ -sql = GitHub::SQL.new insert_statement, key: "foo", value: "bar" +sql = GitHub::SQL.new <<-SQL, key: "foo", value: "bar" + INSERT INTO example_key_values (`key`, `value`) VALUES (:key, :value) +SQL sql.run p sql.last_insert_id # 2 -sql = GitHub::SQL.new select_statement, key: "foo" +sql = GitHub::SQL.new <<-SQL, key: "foo" + SELECT value FROM example_key_values WHERE `key` = :key +SQL p sql.value # "bar" -sql = GitHub::SQL.new update_statement, key: "foo", value: "new value" +sql = GitHub::SQL.new <<-SQL, key: "foo", value: "new value" + UPDATE example_key_values SET value = :value WHERE `key` = :key +SQL sql.run p sql.affected_rows # 1 -sql = GitHub::SQL.new delete_statement, key: "foo" +sql = GitHub::SQL.new <<-SQL, key: "foo" + DELETE FROM example_key_values WHERE `key` = :key +SQL sql.run p sql.affected_rows # 1