Przeglądaj źródła

Kemalyst crystal pg full (#2784)

* initial checkin of kemalyst

* passing version

* add kemalyst to travis.yml

* remove unneeded files

* cleanup routes

* replace 127.0.0.1 with TFB-database
Dru Jensen 8 lat temu
rodzic
commit
fd2a004324

+ 1 - 0
.travis.yml

@@ -38,6 +38,7 @@ env:
     - "TESTDIR=Clojure/aleph"
     - "TESTDIR=Crystal/crystal"
     - "TESTDIR=Crystal/kemal"
+    - "TESTDIR=Crystal/kemalyst"
     - "TESTDIR=D/vibed"
     - "TESTDIR=D/hunt"
     - "TESTDIR=D/collie"

+ 8 - 0
frameworks/Crystal/kemalyst/.gitignore

@@ -0,0 +1,8 @@
+/doc/
+/libs/
+/lib/
+/.crystal/
+/.shards/
+.env
+
+

+ 21 - 0
frameworks/Crystal/kemalyst/LICENSE

@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 
+
+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.

+ 49 - 0
frameworks/Crystal/kemalyst/README.md

@@ -0,0 +1,49 @@
+# kemalyst
+
+Kemalyst is a Rails like framework for Crystal.  It provides many of the same capabilities as rails, written in a language similar to ruby but is compiled to native binary.  It gives you C speed but Ruby ease.
+
+## Installation
+
+Create a pg database called `demo` and configure the `config/database.yml`
+to provide the credentials to access the table.
+
+Then:
+```
+shards update
+kgen migrate up
+```
+
+## Usage
+
+To run the demo:
+```
+crystal build src/kemalyst.cr
+./kemalyst
+```
+
+## Docker and Docker Compose
+
+This will start an instance of postgres, migrate the database, run the specs,
+and launch the site at http://localhost:3000
+```
+docker-compose up -d
+```
+
+To view the logs:
+```
+docker-compose logs -f
+```
+
+Note: The Docker images are compatible with Heroku.  
+
+## Contributing
+
+1. Fork it ( https://github.com/drujensen/FrameworkBenchmarks/fork )
+2. Create your feature branch (git checkout -b my-new-feature)
+3. Commit your changes (git commit -am 'Add some feature')
+4. Push to the branch (git push origin my-new-feature)
+5. Create a new Pull Request
+
+## Contributors
+
+- [drujensen](https://github.com/drujensen) Dru Jensen - creator, maintainer

+ 29 - 0
frameworks/Crystal/kemalyst/benchmark_config.json

@@ -0,0 +1,29 @@
+{
+  "framework": "kemalyst",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/queries?queries=",
+      "fortune_url": "/fortunes",
+      "update_url": "/updates?queries=",
+      "plaintext_url": "/plaintext",
+      "port": 3000,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "Postgres",
+      "framework": "Kemalyst",
+      "language": "Crystal",
+      "flavor": "None",
+      "orm": "Full",
+      "platform": "None",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Kemalyst (MVC, Slang, PostgreSQL)",
+      "notes": "",
+      "versus": "kemal"
+    }
+  }]
+}

+ 19 - 0
frameworks/Crystal/kemalyst/config/application.cr

@@ -0,0 +1,19 @@
+require "../src/controllers/test_controller"
+
+Kemalyst::Application.config do |config|
+  # Set the binding host ip address.  Defaults to "0.0.0.0"
+  # config.host = "0.0.0.0"
+
+  # Set the port.  Defaults to 3000.
+  # config.port = 3000
+
+  # Configure reuse_port option
+  config.reuse_port = true
+
+  # Disable unused middleware
+  config.handlers = [] of HTTP::Handler
+  config.handlers << Kemalyst::Handler::Error.instance
+  config.handlers << Kemalyst::Handler::Params.instance
+  config.handlers << Kemalyst::Handler::Router.instance
+  config.handlers << TestController.instance
+end

+ 2 - 0
frameworks/Crystal/kemalyst/config/database.yml

@@ -0,0 +1,2 @@
+pg:
+  database: postgres://benchmarkdbuser:benchmarkdbpass@TFB-database/hello_world

+ 10 - 0
frameworks/Crystal/kemalyst/config/routes.cr

@@ -0,0 +1,10 @@
+require "../src/controllers/*"
+
+include Kemalyst::Handler
+
+get "/plaintext", test, plaintext
+get "/json", test, json
+get "/db", test, db
+get "/queries", test, queries
+get "/updates", test, updates
+get "/fortunes", test, fortunes

+ 13 - 0
frameworks/Crystal/kemalyst/setup.sh

@@ -0,0 +1,13 @@
+#!/bin/bash
+
+fw_depends postgresql crystal
+
+shards install
+
+crystal build --release src/kemalyst.cr
+
+for i in $(seq 1 $(nproc --all)); do
+  ./kemalyst &
+done
+
+wait

+ 38 - 0
frameworks/Crystal/kemalyst/shard.yml

@@ -0,0 +1,38 @@
+name: kemalyst
+version: 0.1.0
+
+authors:
+  - your_name <your_email>
+
+license: MIT
+
+dependencies:
+  kemalyst:
+    github: kemalyst/kemalyst
+    version: ~> 0.8.0
+  
+  kemalyst-model:
+    github: kemalyst/kemalyst-model
+    version: ~> 0.6.0
+
+  kemalyst-spec:
+    github: kemalyst/kemalyst-spec
+    version: ~> 0.1.0
+    
+
+  pg:
+    github: will/crystal-pg
+
+
+#  mysql:
+#    github: crystal-lang/crystal-mysql
+#  pg:
+#    github: will/crystal-pg
+#  sqlite3:
+#    github: crystal-lang/crystal-sqlite3
+
+development_dependencies:
+  expect:
+    github: dukex/expect.cr
+  mocks:
+    github: waterlink/mocks.cr

+ 69 - 0
frameworks/Crystal/kemalyst/src/controllers/test_controller.cr

@@ -0,0 +1,69 @@
+require "../models/*"
+
+class TestController < Kemalyst::Controller
+  def call(context)
+    context.response.headers["Server"] = "Kemalyst"
+    context.response.headers["Date"] = Time.now.to_s
+    call_next(context)
+  end
+
+  action plaintext do
+    text "Hello, World!"
+  end
+
+  action json do
+    results = {message: "Hello, World!"}
+    json results.to_json
+  end
+
+  action db do
+    results = {} of Symbol => Int32
+    if world = World.find rand(1..10_000)
+      results = {id: world.id, randomNumber: world.randomNumber}
+    end
+    json results.to_json
+  end
+
+  action queries do
+    queries = params["queries"].as(String)
+    queries = queries.to_i? || 1
+    queries = queries.clamp(1..500)
+
+    results = (1..queries).map do
+      if world = World.find rand(1..10_000)
+        {id: world.id, randomNumber: world.randomNumber}
+      end
+    end
+
+    json results.to_json
+  end
+
+  action updates do
+    queries = params["queries"].as(String)
+    queries = queries.to_i? || 1
+    queries = queries.clamp(1..500)
+
+    updated = (1..queries).map do
+      world = World.find rand(1..10_000)
+      if world
+        world.randomNumber = rand(1..10_000)
+        world.save
+        {id: world.id, randomNumber: world.randomNumber}
+      end
+    end
+
+    json updated.to_json
+  end
+
+  action fortunes do
+    fortune = Fortune.new
+    fortune.id = 0
+    fortune.message = "Additional fortune added at request time."
+
+    fortunes = Fortune.all
+    fortunes << fortune
+    fortunes.sort_by! { |fortune| fortune.not_nil!.message.not_nil! }
+
+    html render("fortune/index.slang", "main.slang")
+  end
+end

+ 4 - 0
frameworks/Crystal/kemalyst/src/kemalyst.cr

@@ -0,0 +1,4 @@
+require "kemalyst"
+require "../config/*"
+
+Kemalyst::Application.instance.start

+ 8 - 0
frameworks/Crystal/kemalyst/src/models/fortune.cr

@@ -0,0 +1,8 @@
+require "kemalyst-model/adapter/pg"
+
+class Fortune < Kemalyst::Model
+  adapter pg
+  table_name fortune
+  primary id : Int32
+  field message : String
+end

+ 9 - 0
frameworks/Crystal/kemalyst/src/models/world.cr

@@ -0,0 +1,9 @@
+require "kemalyst-model/adapter/pg"
+
+class World < Kemalyst::Model
+  adapter pg
+  table_name world
+  primary id : Int32
+  field randomNumber : Int32
+end
+

+ 8 - 0
frameworks/Crystal/kemalyst/src/views/fortune/index.slang

@@ -0,0 +1,8 @@
+table
+  tr
+    th id
+    th message
+  - fortunes.each do |fortune|
+    tr
+      td = fortune.id
+      td = fortune.message

+ 6 - 0
frameworks/Crystal/kemalyst/src/views/layouts/main.slang

@@ -0,0 +1,6 @@
+doctype html
+html
+  head
+    title Fortunes
+  body == content
+