title: Strongly-typed database access with Node.JS and TypeScript
body: <p>When we use <code>C#</code>, we can access our database in a strongly-typed manner using Code-First approach:</p>
  
  <pre><code>public class Blog 
  { 
      public int BlogId { get; set; } 
      public string Name { get; set; } 
      public virtual List&lt;Post&gt; Posts { get; set; } 
  }
  ...
  public class Database : DbContext 
  { 
      public DbSet&lt;Blog&gt; Blogs { get; set; } 
      public DbSet&lt;Post&gt; Posts { get; set; } 
  }
  var db = new Database()
  var blog = new Blog { Name = "My new blog", BlogId = 1 }; 
  db.Blogs.Add(blog); 
  db.SaveChanges(); // save object to database
  </code></pre>
  
  <p>The compiler will encure that we only access existing properties/methods and also that we use correct types everywhere in our code.</p>
  
  <p>How can I do the same with <code>TypeScript</code> and <code>Node.JS</code>?</p>
  
  <p>I found <code>Knex.JS</code> and <code>bookshelf</code> libraries for database access, but I cannot find any samples on how to uses them with strongly-typed <code>TypeScript</code> objects and classes.</p>