Class: Rubylite
- Inherits:
-
Object
- Object
- Rubylite
- Defined in:
- lib/rubylite.rb
Overview
this is class Rubylite
Instance Method Summary collapse
- #code ⇒ Object
- #create(table_name, hash) ⇒ Object
- #db_close ⇒ Object
- #db_open(db_name) ⇒ Object
- #eval_this(input) ⇒ Object
- #exec_this(db_name, query) ⇒ Object
- #make_class ⇒ Object
- #make_query(hash) ⇒ Object
- #make_query2(hash) ⇒ Object
Instance Method Details
#code ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/rubylite.rb', line 54 def code print "#{@current_db}>>" input = gets exit if input =~ /^q$/ puts eval_this(input) code end |
#create(table_name, hash) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/rubylite.rb', line 10 def create(table_name, hash) str = make_query(hash) @db.execute("create table #{table_name.downcase}(#{str})") str2 = make_query2(hash) @db.execute("insert into #{table_name} values(#{str2})") db_name = @current_db db_close db_open(db_name) end |
#db_close ⇒ Object
34 35 36 |
# File 'lib/rubylite.rb', line 34 def db_close @current_db = '' end |
#db_open(db_name) ⇒ Object
4 5 6 7 8 |
# File 'lib/rubylite.rb', line 4 def db_open(db_name) @db = Amalgalite::Database.new "#{db_name}.db" @current_db = db_name make_class end |
#eval_this(input) ⇒ Object
50 51 52 |
# File 'lib/rubylite.rb', line 50 def eval_this(input) instance_eval(input) end |
#exec_this(db_name, query) ⇒ Object
30 31 32 |
# File 'lib/rubylite.rb', line 30 def exec_this(db_name, query) db_name.execute(query) end |
#make_class ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rubylite.rb', line 38 def make_class tables_list = exec_this(@db, "select name from sqlite_master where type='table'") tables_list.each do |table| @class_created = Object.const_set((table[0])[0..-2].capitalize, Class.new) @class_created.instance_variable_set(:@database, @db) @class_created.class_eval do extend Functions end end end |
#make_query(hash) ⇒ Object
25 26 27 28 |
# File 'lib/rubylite.rb', line 25 def make_query(hash) column = hash.inject('') { |col, (key, _v)| col + "'#{key}', " } column[0..-3] end |
#make_query2(hash) ⇒ Object
20 21 22 23 |
# File 'lib/rubylite.rb', line 20 def make_query2(hash) column = hash.inject('') { |col, (_k, value)| col + "'#{value}', " } column[0..-3] end |