Lucky is a web framework written in Crystal that helps you build apps quickly, catches bugs for you, and runs incredibly fast.
I’ve been blown away by all the progress that has been made in the last month thanks to many new contributors. 👊
We’ve added over 130 commits and 20+ new features across the Lucky libraries since the initial announcement. The website has also been improved with a new Why Lucky? page, and some fresh new guides. All these changes bring us closer to production ready version of Lucky.
👋 Hey! If you’re interested in helping out with Lucky, or just want to see what’s new, check out Lucky’s GitHub repo.
Highlights in this release
Negate queries with not
:
# Get users who don't work at Facebook
UserQuery.new.company.not(“Facebook”)
# Can be chained
UserQuery.new.last_name.not.ilike("Mc%")
Virtual fields for when you want users to fill something out, but not save to the database:
class SignUpForm < User::BaseForm
# This is a field users should fill in, but is not saved to the database
allow_virtual password_confirmation : String
end
Virtual forms were added so you can process data that isn’t ever saved to a database:
class SignInForm < LuckyRecord::VirtualForm
allow_virtual email : String
allow_virtual password : String
def self.submit
# authenticate the user
end
end
Tons of new migration helpers
# An example of a few of the new methods
def migrate
create users do
# Add indices at the same time as adding a field
add company_id : Int32, index: true
# Add unique indexes
add email : String, unique: true
# Set default values
add admin : Bool, default: false
end
# Create foreign keys with cascading deletes
create_foreign_key :users, :companies, on_delete: :cascade
end
Improved logger in development
New JSON serializers
class Api::Users::Show < ApiAction
action do
user = UserQuery.new.find(id)
json User::ShowJSON.new(user)
end
end
class Users::ShowJSON < LuckyWeb::Serializer
# This is a shortcut for setting instance vars in Crystal
# https://crystal-lang.org/docs/syntax_and_semantics/methods_and_instance_variables.html
def initialize(@user : User); end
def render
{ name: @user.name, email: @user.email }
end
end
Other additions
- Typed HTTP status codes
- Allow outputting more types in HTML
- 10x performance boost in LuckyRecord
- Massively simplified pages and layouts
- Nested serializers
- Raise RecordNotFound error
if
Queryable#find
fails Form.create!/update!
for raising if a form fails to save- Checkbox helper
- Add
on
option to form needs - Custom validation messages
- Generate bin/setup script for easy setup
- Add lucky gen.secret_key
And more! See the comparison view below if you want to see a comprehensive list of changes.
All changes in this release
- Lucky
- LuckyRecord
- LuckyMigrator
- Lucky CLI
- A brand new library, LuckyInflector
- Lucky’s website