-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Purpose/add store #14
Open
radiospiel
wants to merge
14
commits into
master
Choose a base branch
from
purpose/add-store
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
radiospiel
force-pushed
the
purpose/add-store
branch
3 times, most recently
from
November 27, 2018 21:49
b1d247b
to
09d8423
Compare
radiospiel
force-pushed
the
purpose/add-store
branch
2 times, most recently
from
November 27, 2018 23:04
e6337c8
to
21a76ed
Compare
If an object is passed in that implements a "from_complete_row" method, and the query results are complete - i.e. all columns in the underlying table (via fq_table_name) are in the resulting records - this mode uses the +into+ object's +from_complete_row+ method to convert the records. This mode is used by Simple::Store. If the records are not complete, and contain more than a single value this mode behaves like <tt>:immutable</tt>, i.e. they are read only. If the records are not complete and contain only a single value this mode returns that value for each record.
Simple::Store allows to easily define object “types”. A typical use case could look like this: ``` # This file is loaded when running bin/console. Simple::SQL.exec <<~SQL CREATE SCHEMA IF NOT EXISTS store; CREATE TABLE IF NOT EXISTS store.organizations ( id SERIAL PRIMARY KEY, name VARCHAR ); CREATE TABLE IF NOT EXISTS store.users ( id SERIAL PRIMARY KEY, organization_id INTEGER REFERENCES store.organizations (id), role_id INTEGER, first_name VARCHAR, last_name VARCHAR, metadata JSONB, created_at timestamp, updated_at timestamp ); SQL Simple::Store.ask "DELETE FROM store.users" Simple::Store.ask "DELETE FROM store.organizations" Simple::Store::Metamodel.register "User", table_name: "store.users" do attribute :full_name, kind: :virtual end Simple::Store::Metamodel.register_virtual_attributes "User" do def full_name(user) "#{user.first_name} #{user.last_name}" end end Simple::Store::Metamodel.register "Organization", table_name: "store.organizations" do attribute :city, writable: false end user = Simple::Store.create! "User", first_name: "foo" p user # -> <User#33: created_at: 2018-11-28 09:52:37 +0100, first_name: "foo", full_name: "foo ", last_name: nil, organization_id: nil, role_id: nil, updated_at: 2018-11-28 09:52:37 +0100> ```
This is according to the “simple/sql Properly deal w/incomplete models, w/custom type converters” commit in Simple::SQL
Virtual attributes are resolved via method_missing.
radiospiel
force-pushed
the
purpose/add-store
branch
from
November 28, 2018 12:52
21a76ed
to
aa98458
Compare
… , options ] Also changes the default text type from :text to :string
After all this method meeds knowledge of the Storage backend (i.e. the Database.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.