Created
October 4, 2013 22:14
-
-
Save hyrmn/6833706 to your computer and use it in GitHub Desktop.
Showing cats with Dapper and PostgreSQL and NancyFX
This file contains hidden or 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
| CREATE DATABASE demo | |
| WITH OWNER = postgres | |
| ENCODING = 'UTF8' | |
| TABLESPACE = pg_default | |
| LC_COLLATE = 'English_United States.1252' | |
| LC_CTYPE = 'English_United States.1252' | |
| CONNECTION LIMIT = -1; |
This file contains hidden or 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
| CREATE TABLE cats | |
| ( | |
| catid serial NOT NULL, | |
| name character varying(50) NOT NULL, | |
| CONSTRAINT pk_cats PRIMARY KEY (catid) | |
| ) | |
| WITH ( | |
| OIDS=FALSE | |
| ); | |
| ALTER TABLE cats | |
| OWNER TO postgres; |
This file contains hidden or 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
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>NancyApplication1</title> | |
| </head> | |
| <body> | |
| Cats:<br/> | |
| @foreach (var cat in Model.Cats) | |
| { | |
| @cat.name <br /> | |
| } | |
| </body> | |
| </html> |
This file contains hidden or 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
| using System.Data; | |
| using Npgsql; | |
| using Nancy; | |
| using Dapper; | |
| namespace NancyApplication1 | |
| { | |
| public class IndexModule : NancyModule | |
| { | |
| private const string ConnectionString = "Server=localhost;User Id=postgres;password=Postgres1234;database=demo"; | |
| public IndexModule() | |
| { | |
| Get["/"] = (ಠʃಠ) => | |
| { | |
| using (IDbConnection connection = new NpgsqlConnection(ConnectionString)) | |
| { | |
| var cats = connection.Query("select catId, Name from cats"); | |
| return View["index", new {Cats = cats}]; | |
| } | |
| }; | |
| } | |
| } | |
| } |
This file contains hidden or 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
| INSERT INTO cats(name) | |
| VALUES ('Bob'); | |
| INSERT INTO cats(name) | |
| VALUES ('Garfield'); | |
| INSERT INTO cats(name) | |
| VALUES ('Nermele'); | |
| INSERT INTO cats(name) | |
| VALUES ('Sue Ellen'); | |
| INSERT INTO cats(name) | |
| VALUES ('Patches'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment