Giter VIP home page Giter VIP logo

lucky_record's People

Contributors

actsasflinn avatar ajwann avatar bcardiff avatar calebuharrison avatar edwardloveall avatar hanneskaeufler avatar hfjallemark avatar hibachrach avatar jsteiner avatar mikeeus avatar oneiros avatar paulcsmith avatar perezperret avatar xosmond avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lucky_record's Issues

Add validations

Start with

  • validate_required
  • validate_acceptance_of
  • validate_confirmation_of

Add task for generating a migration from the model

lucky db.extract_migration User

It should inspect the database and the model schema and generate a migration for it. If it's not sure what to do, it can leave commented out code so the user can decide how to act on it

def change
  # The title field is no longer on `User`. You can remove it or rename it
  # remove_column :users, :title
  # rename_column :users, :title, to: :fill_in_new_column_name
  add_column :users, :body, type: String
end

Allow bypassing default save method

So if you want to make associations required you could.

class CommentForm < Comment::BaseForm
  create_default_save_method false

  def self.save(params, article : Article)
    new(params).article_id(article.id).save
  end
end

Add non-model/virtual forms

class SignInForm < LuckyRecord::VirtualForm
  allow_virtual email : String
  allow_virtual password : String

  def submit
    if valid_credentials?
      yield self, user_from_email
    else
      yield self, nil
    end
  end

  private def valid_credentials?
    if user_from_email && !passwords_match?
      password.add_error "is incorrect"
    elsif user_from_email.nil?
      email.add_error "was not found"
    end
  end

  private def user_from_email
    UserQuery.new.email(email.value).first?
  end

  private def passwords_match?; end # check the password
end

# in an action
SignInForm.new(params).submit do |form, user|
  if user
    session[:current_user_id] = user.id.to_s
    redirect to: Dashboard::Show
  else
    render SignInPage, form: form
  end
end

Filter preloads

ArticleQuery.new.preload_comments(&.newest_first.preload_author)

Allow passing extra params to save and update

class CommentForm < Comment::BaseForm
  allow body
  # Needs assoc will set the association automatically
  needs_assoc author, only: :save # Don't need to pass the author or project on updates
  needs_assoc project, only: :save
  needs something_else : String # sets up an argument on save/update and creates a `private getter` for it
end

CommentForm.save params, author: author, project: project, something_else: "HELLO"
CommentForm.update comment, something_else: "Hey-o!"

Preload associations

An idea:

posts = PostQuery.new
  # Posts belonging to a specific author
  .author(current_user)
  # Preload comments, and their authors
  .preload_comments(&.preload_author)
  # Just preload the comments
  .preload_comments
  # If you want to do a custom comment query AND preload the authors
  # Works since preload_author is on the query
  .preload_comments(CommentQuery.new.newest_first.not_spam.preload_author)

I think you should be able to call association methods without preloading but in dev/test it will raise if you forget to preload. That way if an N+1 gets to production it won't blow up, but in dev/test you can catch it.

I imagine that in prod you'd want to be able to hook it up to Honeybadger or whatever so that it logs an error though, that way you know an N+1 is happening and needs to be fixed.

I think this is a good balance of catching N+1, not introducing runtime errors, and not having an overly complex method for preloading and getting at your associations.

Add way to use raw WHERE query

So that if there is something not implemented by LuckyRecord, user's can still do what they need to do when joining, using OR, etc.

Something like:

UserQuery.new.raw_where("users.name = #{PG::EscapeHelper.escape_literal("Paul")}") 

This would likely be done by adding a @raw_where = [] of String to QueryBuilder that gets joined to the regular where clauses. Then adding a raw_where method to Queryable

Note

It will be helpful to add something to the guides that explains this AND explains how to generate a 100% custom query and parse with Lucky::Repo and DB.mapping. That's something that shouldn't require any code changes in LuckyRecord though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.