sentiql 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +66 -0
 - data/lib/sentiql/version.rb +1 -1
 - data/lib/sentiql.rb +1 -0
 - data/spec/sentiql_spec.rb +3 -3
 - data/spec/spec_helper.rb +2 -2
 - metadata +3 -2
 
    
        data/README.rdoc
    ADDED
    
    | 
         @@ -0,0 +1,66 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            == SentiQL
         
     | 
| 
      
 2 
     | 
    
         
            +
            A minimalistic Ruby wrapper for MySQL. I love using SQL for data selection, except for basic selects (e.g. finding something by id), I love using OM interface to create, update and delete records in the database and I love when lib is not "overcoded". When you combine all this love, you get SentiQL.
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            == Why SentiQL
         
     | 
| 
      
 5 
     | 
    
         
            +
            I don't like using ActiveRecord or other fat ORMs because I think they are breaking following rules:
         
     | 
| 
      
 6 
     | 
    
         
            +
            1. "Make everything as simple as possible, but not simpler" - Albert Einstein.
         
     | 
| 
      
 7 
     | 
    
         
            +
            2. Rule of Clarity. Clarity is better than cleverness. (Unix Philosophy)
         
     | 
| 
      
 8 
     | 
    
         
            +
            3. Rule of Simplicity: Design for simplicity; add complexity only where you must. (Unix Philosophy)
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            Plus. I think it is wrong to put a thick abstraction layer on one of the biggest web application's performance bottlenecks.
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            == Notice
         
     | 
| 
      
 13 
     | 
    
         
            +
            This is REALY a work in progress, I wrote this lib during one evening after reading "Metaprogramming Ruby: Program Like a Ruby Pros". It is less then 140 LOCs, so even if it is missing one or other thing, just open the sentiql.rb file and happy hacking.
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            == Instalation
         
     | 
| 
      
 16 
     | 
    
         
            +
                gem install sentiql 
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            == How To
         
     | 
| 
      
 19 
     | 
    
         
            +
            1. Connect to database
         
     | 
| 
      
 20 
     | 
    
         
            +
                DB = Mysql2::Client.new( 
         
     | 
| 
      
 21 
     | 
    
         
            +
                      :host=>'localhost', 
         
     | 
| 
      
 22 
     | 
    
         
            +
                      :username=>'username', 
         
     | 
| 
      
 23 
     | 
    
         
            +
                      :password=>'password', 
         
     | 
| 
      
 24 
     | 
    
         
            +
                      :database=>'db'
         
     | 
| 
      
 25 
     | 
    
         
            +
                    )
         
     | 
| 
      
 26 
     | 
    
         
            +
                DB.query_options.merge!(:symbolize_keys=>true)
         
     | 
| 
      
 27 
     | 
    
         
            +
                SentiQL::Base.connection = DB
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            2. Working with User data
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                # creating
         
     | 
| 
      
 32 
     | 
    
         
            +
                u = User.new :name=>'Tyler Durden', :password=>'project_mayhem'
         
     | 
| 
      
 33 
     | 
    
         
            +
                u.save  
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                # updating
         
     | 
| 
      
 36 
     | 
    
         
            +
                u[:name] = 'Tyler'
         
     | 
| 
      
 37 
     | 
    
         
            +
                u.save
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                # reading
         
     | 
| 
      
 40 
     | 
    
         
            +
                t = User.find_by :name=>'Tyler' # -> and instance of User
         
     | 
| 
      
 41 
     | 
    
         
            +
                t = SentiQL::Base.first 'SELECT name FROM users where name=? LIMIT 1', ['Tyler'] # -> {:name=>'Tyler', :password=>'project_mayhem'}
         
     | 
| 
      
 42 
     | 
    
         
            +
                users = SentiQL::Base.all 'SELECT name FROM users' # -> [{:name=>'Tyler'}]
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                # runing SQL query
         
     | 
| 
      
 45 
     | 
    
         
            +
                SentiQL::Base.execute 'DELETE FROM users WHERE name=?', ['Robert Paulson']
         
     | 
| 
      
 46 
     | 
    
         
            +
                
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            3. User model
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                class User < SentiQL::Base
         
     | 
| 
      
 51 
     | 
    
         
            +
                  
         
     | 
| 
      
 52 
     | 
    
         
            +
                  set_schema :name, :password, :created_at            # column names of the table that you will play with
         
     | 
| 
      
 53 
     | 
    
         
            +
                  set_table :users                                    # table name
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                  before_create :set_timestamp
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                  protected 
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                  def set_timestamp
         
     | 
| 
      
 60 
     | 
    
         
            +
                    self[:created_at] = Time.now
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            == Licence
         
     | 
| 
      
 66 
     | 
    
         
            +
            I have no idea about this sort of things.
         
     | 
    
        data/lib/sentiql/version.rb
    CHANGED
    
    
    
        data/lib/sentiql.rb
    CHANGED
    
    
    
        data/spec/sentiql_spec.rb
    CHANGED
    
    | 
         @@ -111,12 +111,12 @@ describe SentiQL::Base do 
     | 
|
| 
       111 
111 
     | 
    
         | 
| 
       112 
112 
     | 
    
         
             
              describe '.first' do
         
     | 
| 
       113 
113 
     | 
    
         
             
                it 'returns nil when no records found' do
         
     | 
| 
       114 
     | 
    
         
            -
                  r = SentiQL.first 'SHOW TABLES LIKE ?', ['non_existing_tbl%']
         
     | 
| 
      
 114 
     | 
    
         
            +
                  r = SentiQL::Base.first 'SHOW TABLES LIKE ?', ['non_existing_tbl%']
         
     | 
| 
       115 
115 
     | 
    
         
             
                  r.should == nil
         
     | 
| 
       116 
116 
     | 
    
         
             
                end
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                it 'returns a hash if record found with keys representing column values' do
         
     | 
| 
       119 
     | 
    
         
            -
                  r = SentiQL.first 'SELECT CONCAT(?,?) AS str', ['a','b']
         
     | 
| 
      
 119 
     | 
    
         
            +
                  r = SentiQL::Base.first 'SELECT CONCAT(?,?) AS str', ['a','b']
         
     | 
| 
       120 
120 
     | 
    
         
             
                  r.should be_an_instance_of(Hash)
         
     | 
| 
       121 
121 
     | 
    
         
             
                  r[:str].should == 'ab'
         
     | 
| 
       122 
122 
     | 
    
         
             
                end
         
     | 
| 
         @@ -124,7 +124,7 @@ describe SentiQL::Base do 
     | 
|
| 
       124 
124 
     | 
    
         | 
| 
       125 
125 
     | 
    
         
             
              describe '.all' do
         
     | 
| 
       126 
126 
     | 
    
         
             
                it 'returns Mysql2::Result which holds data in Hashes' do
         
     | 
| 
       127 
     | 
    
         
            -
                  r = SentiQL.all 'SHOW OPEN TABLES'
         
     | 
| 
      
 127 
     | 
    
         
            +
                  r = SentiQL::Base.all 'SHOW OPEN TABLES'
         
     | 
| 
       128 
128 
     | 
    
         
             
                  r.should be_an_instance_of(Mysql2::Result)
         
     | 
| 
       129 
129 
     | 
    
         
             
                  r.first.should be_an_instance_of(Hash)
         
     | 
| 
       130 
130 
     | 
    
         
             
                end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -4,11 +4,11 @@ require 'rspec' 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'active_record'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'mysql2'
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
            require 'sentiql'
         
     | 
| 
      
 7 
     | 
    
         
            +
            #require 'sentiql'
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            ROOT_PATH = File.dirname(__FILE__)
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
            require File.join(ROOT_PATH, '..', 'lib', 'sentiql')
         
     | 
| 
       12 
12 
     | 
    
         
             
            @config = YAML.load_file(File.join(ROOT_PATH, '..', "config/database.yml"))['test']
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
            DB = Mysql2::Client.new( 
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: sentiql
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.1.3
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors: 
         
     | 
| 
       8 
8 
     | 
    
         
             
            - Martynas Miliauskas
         
     | 
| 
         @@ -10,7 +10,7 @@ autorequire: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            date: 2011-05- 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2011-05-23 00:00:00 +01:00
         
     | 
| 
       14 
14 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       15 
15 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       16 
16 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -69,6 +69,7 @@ extra_rdoc_files: [] 
     | 
|
| 
       69 
69 
     | 
    
         
             
            files: 
         
     | 
| 
       70 
70 
     | 
    
         
             
            - .gitignore
         
     | 
| 
       71 
71 
     | 
    
         
             
            - Gemfile
         
     | 
| 
      
 72 
     | 
    
         
            +
            - README.rdoc
         
     | 
| 
       72 
73 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       73 
74 
     | 
    
         
             
            - config/database.yml
         
     | 
| 
       74 
75 
     | 
    
         
             
            - db/migrate/20110515_test_tables.rb
         
     |