简体   繁体   English

使用Clojure / ClojureScript进行Web开发的后端

[英]Backend for Web Development using Clojure/ClojureScript

I'm familiar with developing desktop apps in Clojure (written a multithreaded interactive visualization system). 我熟悉在Clojure中开发桌面应用程序(编写多线程交互式可视化系统)。 However, I'm fairly new to Web development using Clojure. 但是,我对使用Clojure的Web开发相当陌生。

I plan to use Clojure on the server for handling logic; 我计划在服务器上使用Clojure来处理逻辑; and ClojureScript for handing client side work. 和ClojureScript用于处理客户端工作。 However, I don't know what to use for my database server. 但是,我不知道我的数据库服务器要使用什么。 Should I use something like Monogodb? 我应该使用像Monogodb这样的东西吗? or Hadoop? 还是Hadoop? Or .... ? 要么 .... ?

The app is something very simple; 该应用程序非常简单; a basic forum. 一个基本的论坛。 Total number of concurrent users will be < 100 at a given time. 在给定时间,并发用户总数将<100。 One thing that is important to me is the ability to easily backup / data consistency -- it's very very important to me that I can easily make daily backups (and not lose all the data.) 对我来说重要的一点是能够轻松备份/数据一致性 - 对我来说非常重要的是我可以轻松地进行日常备份(而不是丢失所有数据)。

Thanks! 谢谢!

You can use many databases; 你可以使用很多数据库; if the database has an API for Java, you should be good to go. 如果数据库有一个Java API,你应该好好去。 MySQL , MongoDB , Postgres , Hadoop … and more. MySQLMongoDBPostgresHadoop ......等等。

For a nice overview of the webstack in Clojure, check out brehaut's article on the matter . 有关Clojure中webstack的精彩概述,请查看brehaut 关于此事文章

For getting up and running quickly with Clojure and ClojureScript, try ClojureScriptOne . 要使用Clojure和ClojureScript快速启动和运行,请尝试使用ClojureScriptOne

There are many ways to write what you want to write; 有很多方法可以写出你想写的东西; if you're already familiar with Clojure, it shouldn't be too hard to get going. 如果你已经熟悉Clojure,那么开始它应该不会太难。

我自己没有使用它,但Datomic( http://datomic.com/ )看起来很适合来自Clojure的任何人。

Datomic is an amazing database, and I'd highly recommend it. Datomic是一个了不起的数据库,我强烈推荐它。 It has many features which set it apart from other database systems: 它具有许多功能,使其与其他数据库系统区别开来:

  • Like Clojure's data structures, it's persistent, meaning that by default, adding new facts to the database doesn't delete old facts, allowing you to query the state of the database at a previous point in time, enhancing audit-ability and assistance in debugging. 与Clojure的数据结构一样,它是持久的,这意味着默认情况下,向数据库添加新事实不会删除旧事实,允许您在以前的时间点查询数据库的状态,增强审计能力并协助调试。
  • The underlying Entity Attribute Value (EAV/triple) data model (at least partly inspired by RDF & the Semantic Web), is extremely flexible, allowing you to express arbitrary graph structures and effortlessly deal with polymorphism. 底层实体属性值(EAV / triple)数据模型(至少部分受RDF和语义Web启发)非常灵活,允许您表达任意图形结构并毫不费力地处理多态。
  • The query language is flavor of Datalog, a sort of pattern matching based query language strictly more expressive than SQL and the like in that it can do recursive queries, making it particularly well suited for dealing with graph data/queries. 查询语言是Datalog的味道,一种基于模式匹配的查询语言比SQL等更具表现力,因为它可以进行递归查询,使其特别适合处理图形数据/查询。
  • In addition to Datalog queries, there's a pull api, which let's you pull data out of the database more simply using a GraphQL like expression which specifies the shape of a document-like structure you'd like to pull out of the database. 除了Datalog查询之外,还有一个pull api,它允许您使用类似GraphQL的表达式从数据库中提取数据,该表达式指定了您想要从数据库中提取的类文档结构的形状。 These queries can even be used from within the :find clause of a Datalog query. 甚至可以在Datalog查询的:find子句中使用这些查询。
  • You can use Clojure functions from within your queries. 您可以在查询中使用Clojure函数。
  • The indexing system is very smart and more or less automatic, in stark contrast with the work that typically goes into tuning SQL databases for performance. 索引系统非常智能,或多或少都是自动化的,与通常用于调优SQL数据库性能的工作形成鲜明对比。
  • Transactions go through a different API/function call than queries, meaning that the number one security risk identified by OWASP (SQL injection) is literally impossible in Datomic. 事务通过与查询不同的API /函数调用,这意味着在Datomic中,OWASP识别的头号安全风险(SQL注入)实际上是不可能的。
  • The transactor/read-replica design makes it super easy to scale reads/queries, while keeping pressure off the transactor. transactor / read-replica设计使得扩展读取/查询变得非常容易,同时保持交易者的压力。
  • It's fun as hell. 太好玩了。

One of the things worth pointing out here is that by embracing the EAV data model and datalog/pull queries, Datomic ends up having structural flexibility closer to that of a NoSQL database, while still being fundamentally relational, and even more expressive in it's relational queries than SQL. 值得指出的一点是,通过采用EAV数据模型和数据记录/拉取查询,Datomic最终具有更接近NoSQL数据库的结构灵活性,同时仍然是基本的关系,并且在其关系查询中更具表现力比SQL。

It's amazing and you should absolutely give it a shot. 这太棒了,你绝对应该试一试。 It will melt your brain a little. 它会使你的大脑融化一点。 In the good way. 好的方式。

It's also worth noting that it's popularity has inspired a number of successful open source projects, so the underlying approach is not going anywhere any time soon: 值得注意的是,它的受欢迎程度激发了许多成功的开源项目,因此基础方法不会很快就会出现:

  • DataScript: In memory clj/cljs partial implementation DataScript:在内存clj / cljs中部分实现
  • Datahike: Fork of DataScript which queries over on disk indices, meaning you don't have to keep everything in memory to query Datahike:DataScript的分支,用于查询磁盘索引,这意味着您不必将所有内容都保留在内存中进行查询
  • Mentat: Mozilla project trying to make a Datomic-alike for a Mozilla project Mentat:Mozilla项目尝试为Mozilla项目制作类似Datomic的项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM