Comments (6)
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.
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.
Added! Let's me know what do you think about.
from mini_record.
Nice, good syntax improvement. Now reminds me of mongoid or datamapper a lot more.
from mini_record.
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.
Very cool! Is this slated for an upcoming release?
from mini_record.
Related Issues (20)
- Issue about primary keys HOT 2
- ActiveRecord - Abstract class bug. HOT 1
- mini_record incompatible with Rails 4.0 HOT 4
- Idea for handling changing column names HOT 6
- macro facility - useful/interesting? HOT 3
- sqlite3 rewrites the table on every auto_upgrade HOT 2
- Problems with SQLite HOT 2
- MiniRecord don't work without logger HOT 4
- has_and_belongs_to_many join table name issues HOT 1
- wrong table name. bug introduced in my last PR HOT 1
- auto_upgrade! fails because of attempting to add duplicate indexes
- Auto changing column type don't work on PostgreSQL HOT 5
- auto_upgrade! sometimes breaks has_and_belongs_to_many associations
- Partial indexes for PostgreSQL?
- PostgreSQL limitless columns? HOT 3
- how to use mini_record in sinatra?
- "Unsupported number of args for ActiveRecord::ConnectionAdapters::TableDefinition.new() (ArgumentError)" HOT 2
- PostgreSQL booleans not supported HOT 1
- Not related: GoTasks for Mac
- auto_upgrade! NameError: no member 'limit' in struct HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mini_record.