Last active
August 29, 2015 14:02
-
-
Save krainboltgreene/95e33bee5fa91298e514 to your computer and use it in GitHub Desktop.
A dragon pg gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
needs("postgresql") | |
needs("orm") | |
client: PostgreSQL Client clone(url: ENV POSTGRESQL_URL) | |
table: PostgreSQL Table clone(client: client, name: "accounts") | |
query: PostgreSQL Query Select clone(fields: ["id", "name"], table: table, where: { name: "?" }, parameters: ["%urtis%"]) | |
query to_s() # => SELECT id, name FROM accounts WHERE name = "%urtis%"; | |
request: PostgreSQL Request clone(client: client, database: database, query: query) | |
request to_a() # => [(id: 4, name: "Kurtis Rainbolt-Greene"), { ... }] | |
query2: PostgreSQL Query Update clone(fields: (name: "James Rainbolt-Greene", age: 42) table: table, where: (id: 4)) | |
query2 to_s() # => UPDATE accounts SET name = "James Rainbolt-Greene", age = 42 WHERE id = 4; | |
Account: Object clone() with -> | |
mimics(ORM Model) | |
database(ENV["DATABASE_NAME"]) | |
table("accounts") | |
schema | |
schema.create_table(table.name) | |
table.column(name: "id", type: "uuid", primary_key: true) | |
table.column(name: "age", type: "number", index: true) | |
Account.where | |
name.like("urtis") | |
# => [Account(id: 4, name: "Kurtis Rainbolt-Greene")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment