-
Notifications
You must be signed in to change notification settings - Fork 12
Home
With your filemaker.yml
file, you can load the configuration into the registry.
require 'filemaker'
Filemaker.load!('./filemaker.yml', :production)
server = Filemaker.registry['default']
server.databases.all # Show all your databases
The registry will give you back a single server
instance where you can use to tag which database and layout you want to query and write data for. Note: You can have multiple registry if you have many FileMaker server with different hostname.
api = server.database[:candidates].layout[:profile]
api = server.db[:candidates].lay[:profile] # Shortcut
api = server.db[:candidates][:profile] # The same
With the api
instance, you can perform find
, new
, edit
, and delete
CRUD requests.
resultset = api.find({ name: 'Bob' }, { max: 10 })
resultset.params # Useful for debugging the parameters that get send to FileMaker
resultset.xml # The raw XML
resultset.count
resultset.total_count
You will get back a resultset
which is enumerable so you can directly iterate over your records.
resultset.each do |record|
name1 = record[:name]
name2 = record['NaMe']
name3 = record.name
# Access your portals hash
record.portals
end
As you can see, to get back the individual field, you do not have to worry about String
, Symbol
, or case sensitivity.
Using those low-level api
can get frustrating pretty fast. If you want some sort of ORM mapping, you can include Filemaker::Model
to your data model. This will give you many conveniences like a query DSL and persistence framework. You can expect your Rails form to work as well as JSON and XML serialization. Callbacks and validations are also provided.
#!/usr/bin/env ruby
require 'bundler/setup'
Bundler.require
Filemaker.registry['default'] = Filemaker::Server.new do |config|
config.host = ENV['FILEMAKER_HOST']
config.account_name = ENV['FILEMAKER_ACCOUNT_NAME']
config.password = ENV['FILEMAKER_PASSWORD']
end
class Job
include Filemaker::Model
before_save :geotag_location
database :jobs
layout :job
# Make use of kaminari gem
paginates_per 50
# Taken from filemaker.yml config file, default to :default
# Only use registry if you have multiple FileMaker servers you want to connect
registry :read_slave
string :job_id, fm_name: 'JobOrderID', identity: true
string :title, :requirements
datetime :created_at
datetime :published_at, fm_name: 'ModifiedDate'
money :salary
validates :title, presence: true
belongs_to :company
has_many :applicants, class_name: 'JobApplication', reference_key: 'job_id'
def geotag_location
# before_save callback
end
end
The following data types are available:
-
string
ortext
-String
as TEXT -
integer
-Integer
as NUMBER -
number
ormoney
-BigDecimal
as NUMBER -
date
-Date
as DATE -
datetime
-DateTime
as TIME/TIMESTAMP -
object
-Filemaker::Model::Types::Attachment
as CONTAINER -
email
-Filemaker::Model::Types::Email
CONTAINER will just be a URL string.
The following data type options are available:
-
fm_name
- Map the attribute name to the FileMaker field name -
identity
- Identify which attribute is to be act as an ID
The following relations are available:
-
has_many
- Will automatically infer the identity attribute to be thereference_key
-
belongs_to
- Will append_id
to the foreign key as thereference_key
has_portal
For relation, class_name
and reference_key
are typically inferred, but you can override.
In your Gemfile
gem 'filemaker'
gem 'kaminari' # For pagination
Place filemaker.yml
file into your config
folder and write your data models as you would normally.
As always, the model is just for data model, it is your judgement how your want to tightly coupled it to your domain models.