尝试haskell

本文介绍了一款基于Haskell的简易SQL解释器,实现了select、from和where等基本功能,并探讨了进一步增强功能的可能性,如支持CSV、group by及流式处理。

尝试用haskell编写一个SQL解释器,做了一个初步的后端

代码:

module Funs where
import Data.List
import Monad
import System.Directory
import System.FilePath
import System.IO
import Text.Regex.PCRE

data Store t p = Text p 
               | Csv p
               | Bin p
               | File p

selectFrom (Text store) = do
  content <- readFile store
  return$lines content

unionIt :: IO [[String]] -> IO[String]
unionIt = liftM concat

select :: IO [FilePath] -> IO [String]
select paths = paths 
               >>= /ps -> unionIt(filterM doesFileExist ps 
                              >>= mapM (/p -> selectFrom (Text p)))

from :: FilePath -> IO [FilePath]
from path = let (dir, files) = splitFileName path
            in liftM(/lines->[dir++line | line <- lines, line=~files])
                   ((getDirectoryContents.takeDirectory) dir)

whereLines :: String -> [String] -> IO [String]
whereLines reg lines = return $filter (/line -> line =~ reg :: Bool) lines

这段代码已经包含了基本的 select from where 模式,甚至可以说已经是一个实 用的实现,但是对于我来说,期待它有进一步的功能:

  • 有真正的前端脚本
  • 可以在 select 后设定输出字段,如匹配文件字和行号,以及进一步用正则对行 文件分组
  • 将 where 嵌入 select 过程,真正实现流式过滤
  • 支持 limit offset
  • 支持CSV
  • 支持 group by … having
  • 支持 order by
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值