Created
February 22, 2017 17:23
-
-
Save rishavs/9c26b23f14c3729274688a216c29f515 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "kemal" | |
require "./Kemal_mvc_design/controllers/post_controller.cr" | |
require "./Kemal_mvc_design/models/posts.cr" | |
require "./Kemal_mvc_design/*" | |
Kemal.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /Kemal_mvc_design/controllers/post_controller.cr | |
require "crecto" | |
module PostController | |
extend self | |
def index(env) | |
query = Crecto::Repo::Query | |
.order_by("posts.id DESC") | |
dataset = Crecto::Repo.all(Models::Post, query) | |
dataset.as(Array) | |
pp(dataset) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /Kemal_mvc_design/models/posts.cr | |
module Models | |
class Post < Crecto::Model | |
schema "posts" do | |
field :title, String | |
field :is_link, Bool | |
field :link, String | |
field :content, String | |
field :author_username, String | |
field :is_viewable, Bool | |
field :is_approved, Bool | |
field :is_deleted, Bool | |
field :last_read_at, Time | |
end | |
validate_required [:title] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /Kemal_mvc_design/routes.cr | |
module Main | |
get "/" do |env| | |
PostController.index(env) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
error is