Giter VIP home page Giter VIP logo

Comments (6)

mrrooijen avatar mrrooijen commented on July 19, 2024

You could even use field as a wrapper around your current solution probably.

def self.field(name, options = {})
  table_definition.send(options.delete(:type), name, options)
end

Something like that would probably work out of the box, since you pass the type in through :type => :string|:text|:integer|:date|etc.

from mini_record.

mrrooijen avatar mrrooijen commented on July 19, 2024

I just tested it and it works.

def self.field(name, options = {})
  table_definition.send(options.delete(:type) || :string, name, options)
end

Small adjustment options.delete(:type) || :string to define to :string type if no type is set.

Of course, this doesn't apply any :index => true functionality, but simply wraps around the current functionality, acting as an alternative DSL/syntax.

from mini_record.

DAddYE avatar DAddYE commented on July 19, 2024

Added! Let's me know what do you think about.

from mini_record.

nesquena avatar nesquena commented on July 19, 2024

Nice, good syntax improvement. Now reminds me of mongoid or datamapper a lot more.

from mini_record.

mrrooijen avatar mrrooijen commented on July 19, 2024

Very nice improvement. I like single method invocations more (key :attribute, options rather than col.string :attribute) and adding the hash of options at the end makes it very flexible since you can pass in more than simply what ActiveRecord's migration engine is capable of accepting, like MiniRecord's options for indexes.

Also like how you have both :type and :as since :type in my eyes is more for defining the "data type" and :as feels more for adding references/association columns, although they are the same thing, it makes for nicer DSL reading in the model again.

Can't wait to use this DSL along with PostgreSQL in my next project.

Thanks!

from mini_record.

nateware avatar nateware commented on July 19, 2024

Very cool! Is this slated for an upcoming release?

from mini_record.

Related Issues (20)

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.