洞察探索如何利用兼容微信生态的小程序容器,实现跨平台开发,助力金融和车联网行业的数字化转型。
620
2022-10-25
Joy是用janet编写的全栈Web框架
You Found Joy!
Joy is a full stack web framework written in janet
(use joy)(defn home [request] (render :text "You found joy!"))(defroutes routes [:get "/" home])(def app (handler routes))(server app 8000)
Getting Started
First make sure janet is installed
Next, install the joy cli like this
jpm install joy
Hopefully the joy executable will be on your path and ready to roll. Now, run the following from your terminal
joy new my-joy-project
This should create a new directory called my-joy-project and it should create a few files and things to get you started. Next, let's create a database, a table and connect it with routes and a few functions for handling requests.
Create a new sqlite database
If you aren't already in the my-joy-project directory, go ahead and get in there. Now run
joy create db
This creates a new empty database named dev.sqlite3. Let's fill it up.
Taking it for a spin
Alright now that we have a project and a sqlite database set up, it's time to test it out in the browser:
joy server
This should start an http server that's listening at http://localhost:8000.
Create a database table
Run this to create a new migration with a table with a few columns:
joy create table account 'email text not null unique' 'password text not null'
This has created one file in your db/migrations folder that is waiting to get applied to the database.
Run database migrations
Run this from your terminal
joy migrate
This will output what just happened to your database and create a new file db/schema.sql.
Create a route file
In joy there are no ORMs, no classes, and no objects, just functions that take in requests and return responses.
Let's make a route file that corresponds to the table from earlier
joy create route account
Those commands have created another new file: src/routes/account.janet and updated your src/routes.janet file with a few helpful routes.
Go ahead and check out the new account routes in the browser now: http://localhost:8000/account
Joy can do a lot more than that, check out the docs here
Why?
I wanted something that felt like coast but took so little resources (memory + cpu) I could run dozens (if not hundreds) of websites on a cheap VPS.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~