Skip to content

Instantly share code, notes, and snippets.

@lizTheDeveloper
Created December 16, 2015 20:44
Show Gist options
  • Save lizTheDeveloper/3e0b1430e130ce074764 to your computer and use it in GitHub Desktop.
Save lizTheDeveloper/3e0b1430e130ce074764 to your computer and use it in GitHub Desktop.
var pg = require("pg");
var client = new pg.Client("postgres://localhost:5432/books");
client.connect(function(err) {
if (err) throw err;
client.query("SELECT title FROM books;", function(err, result) {
console.log(result.rows);
});
client.query("INSERT INTO books (title) VALUES ('Against The Fall of Night')", function(err, result) {
console.log(err);
if (!err) {
console.log("Inserted against the fall")
}
});
client.query("INSERT INTO books (title) VALUES ('Harry Potter and the Awesome Stone')", function(err, result) {
console.log(err);
if (!err) {
console.log("inserted harry potter")
}
});
var myBook = "Squirrel Seek's Chipmunk"
client.query("INSERT INTO books (title, author) VALUES ($1, $2)",[myBook, "David Sedaris"],function(err, result) {
console.log(err);
if (!err) {
console.log("inserted some kind of book")
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment