diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2015, Nikita Volkov
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/hasql-th.cabal b/hasql-th.cabal
new file mode 100644
--- /dev/null
+++ b/hasql-th.cabal
@@ -0,0 +1,64 @@
+name:
+  hasql-th
+version:
+  0.1
+category:
+  Hasql, Database, PostgreSQL, Template Haskell
+synopsis:
+  Template Haskell utilities for Hasql
+homepage:
+  https://github.com/nikita-volkov/hasql-th 
+bug-reports:
+  https://github.com/nikita-volkov/hasql-th/issues 
+author:
+  Nikita Volkov <nikita.y.volkov@mail.ru>
+maintainer:
+  Nikita Volkov <nikita.y.volkov@mail.ru>
+copyright:
+  (c) 2015, Nikita Volkov
+license:
+  MIT
+license-file:
+  LICENSE
+build-type:
+  Simple
+cabal-version:
+  >=1.10
+
+
+source-repository head
+  type:
+    git
+  location:
+    git://github.com/nikita-volkov/hasql-th.git
+
+
+library
+  hs-source-dirs:
+    library
+  ghc-options:
+  default-extensions:
+    Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples
+  default-language:
+    Haskell2010
+  other-modules:
+    Hasql.TH.Prelude
+    Hasql.TH.Queries
+    Hasql.TH.Transactions
+    Hasql.TH.Parsers
+    Hasql.TH.Renderers
+  exposed-modules:
+    Hasql.TH
+  build-depends:
+    -- database:
+    hasql >= 0.15 && < 0.16,
+    hasql-transaction >= 0.3 && < 0.4,
+    -- template-haskell:
+    template-haskell >= 2.8 && < 3,
+    -- parsers:
+    attoparsec >= 0.10 && < 0.14,
+    -- data:
+    bytestring >= 0.10 && < 0.11,
+    text >= 1 && < 2,
+    -- general:
+    base-prelude >= 0.1.19 && < 0.2
diff --git a/library/Hasql/TH.hs b/library/Hasql/TH.hs
new file mode 100644
--- /dev/null
+++ b/library/Hasql/TH.hs
@@ -0,0 +1,31 @@
+module Hasql.TH where
+
+import Hasql.TH.Prelude
+import Language.Haskell.TH
+import qualified Hasql.TH.Parsers as Parsers
+import qualified Hasql.TH.Renderers as Renderers
+import qualified Data.Text.IO
+
+
+-- |
+-- Read an SQL-file, containing multiple statements,
+-- and produce a transaction expression.
+-- 
+-- Allows to store plain SQL in external files and read it at compile time.
+-- 
+-- E.g.,
+-- 
+-- >migration1 :: Transaction ()
+-- >migration1 =
+-- >  $(Hasql.TH.readFileAsTransaction "sql/migration-1.sql")
+-- 
+readFileAsTransaction :: String -> Q Exp
+readFileAsTransaction path =
+  do
+    contents <-
+      runIO $ Data.Text.IO.readFile path
+    statements <- 
+      either (fail . showString ("Parsing failure: ")) return $
+      Parsers.run Parsers.statements contents
+    return $
+      Renderers.statementsTransactionExp statements
diff --git a/library/Hasql/TH/Parsers.hs b/library/Hasql/TH/Parsers.hs
new file mode 100644
--- /dev/null
+++ b/library/Hasql/TH/Parsers.hs
@@ -0,0 +1,23 @@
+module Hasql.TH.Parsers where
+
+import Hasql.TH.Prelude
+import Data.Attoparsec.Text
+import qualified Data.Text.Encoding
+
+
+run :: Parser a -> Text -> Either String a
+run parser input =
+  parseOnly parser input
+
+statements :: Parser [ByteString]
+statements =
+  sepBy' statement separator
+  where
+    separator =
+      char ';' *> skipSpace
+
+statement :: Parser ByteString
+statement =
+  fmap Data.Text.Encoding.encodeUtf8 $
+  takeWhile1 (/= ';')
+
diff --git a/library/Hasql/TH/Prelude.hs b/library/Hasql/TH/Prelude.hs
new file mode 100644
--- /dev/null
+++ b/library/Hasql/TH/Prelude.hs
@@ -0,0 +1,18 @@
+module Hasql.TH.Prelude
+( 
+  module Exports,
+)
+where
+
+
+-- base-prelude
+-------------------------
+import BasePrelude as Exports hiding (assert, left, right, isLeft, isRight, error)
+
+-- bytestring
+-------------------------
+import Data.ByteString as Exports (ByteString)
+
+-- text
+-------------------------
+import Data.Text as Exports (Text)
diff --git a/library/Hasql/TH/Queries.hs b/library/Hasql/TH/Queries.hs
new file mode 100644
--- /dev/null
+++ b/library/Hasql/TH/Queries.hs
@@ -0,0 +1,14 @@
+module Hasql.TH.Queries where
+
+import Hasql.TH.Prelude
+import Hasql.Query
+import qualified Hasql.Encoders as Encoders
+import qualified Hasql.Decoders as Decoders
+
+
+statement :: ByteString -> Query () ()
+statement sql =
+  Query sql Encoders.unit Decoders.unit False
+
+
+
diff --git a/library/Hasql/TH/Renderers.hs b/library/Hasql/TH/Renderers.hs
new file mode 100644
--- /dev/null
+++ b/library/Hasql/TH/Renderers.hs
@@ -0,0 +1,48 @@
+module Hasql.TH.Renderers where
+
+import Hasql.TH.Prelude
+import Language.Haskell.TH
+import qualified Hasql.Transaction as Transaction
+import qualified Hasql.TH.Transactions as Transactions
+import qualified Data.ByteString as ByteString
+
+
+statementsTransactionExp :: [ByteString] -> Exp
+statementsTransactionExp x =
+  sequenceExp_ (map statementTransactionExp x)
+
+statementTransactionExp :: ByteString -> Exp
+statementTransactionExp x =
+  AppE (VarE 'Transactions.statement) (byteStringExp x)
+
+byteStringExp :: ByteString -> Exp
+byteStringExp x =
+  AppE (VarE 'ByteString.pack) (listExp integralExp (ByteString.unpack x))
+
+integralExp :: Integral a => a -> Exp
+integralExp x =
+  LitE (IntegerL (fromIntegral x))
+
+listExp :: (a -> Exp) -> [a] -> Exp
+listExp renderer x =
+  ListE (map renderer x)
+
+stringExp :: String -> Exp
+stringExp x =
+  LitE (StringL x)
+
+charExp :: Char -> Exp
+charExp x =
+  LitE (CharL x)
+
+sequenceExp_ :: [Exp] -> Exp
+sequenceExp_ =
+  foldl' andThenExp pureExp_
+
+pureExp_ :: Exp
+pureExp_ =
+  AppE (VarE 'pure) (TupE [])
+
+andThenExp :: Exp -> Exp -> Exp
+andThenExp exp1 exp2 =
+  AppE (AppE (VarE '(*>)) exp1) exp2
diff --git a/library/Hasql/TH/Transactions.hs b/library/Hasql/TH/Transactions.hs
new file mode 100644
--- /dev/null
+++ b/library/Hasql/TH/Transactions.hs
@@ -0,0 +1,16 @@
+module Hasql.TH.Transactions where
+
+import Hasql.TH.Prelude
+import Hasql.Transaction
+import qualified Hasql.TH.Queries as Queries
+import qualified Data.ByteString
+
+
+statement :: ByteString -> Transaction ()
+statement sql =
+  query () (Queries.statement sql)
+
+statements :: ByteString -> Transaction ()
+statements =
+  traverse_ statement .
+  Data.ByteString.split (fromIntegral (ord ';'))
