Module: JSONdb::Commands

Includes:
Validations::Records
Included in:
Db
Defined in:
lib/jsondb/commands.rb

Constant Summary

Constants included from Validations::Records

Validations::Records::FieldsToNotVerify

Constants included from Validations::Types

Validations::Types::AllowedTypes

Instance Method Summary collapse

Methods included from Validations::Records

#record_validates?

Methods included from Validations::Types

#allowed_type?, #validate_type

Methods included from Logger

#allowed_log_level?, #log, #log_enabled?, #log_this?

Instance Method Details

#delete(table_name, record) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/jsondb/commands.rb', line 39

def delete(table_name, record)
  if JSONdb.tables[table_name].exists?(record)
    log("Deleting record: #{record.inspect}", :debug)
    JSONdb.tables[table_name].drop_record(record)
    return true
  else
    log("Record does not exists, so we can delete it", :error)
    return false
  end
end

#delete_by_id(table_name, id) ⇒ Object



50
51
52
# File 'lib/jsondb/commands.rb', line 50

def delete_by_id(table_name, id)
  return delete(table_name, JSONdb.records[table_name][id])
end

#insert_into(table_name, record) ⇒ Object Also known as: insert



13
14
15
16
17
18
19
20
21
22
# File 'lib/jsondb/commands.rb', line 13

def insert_into(table_name, record)
  if record_validates?(table_name, record)
    JSONdb.tables[table_name].insert_record(record)
    log("Inserted record: #{record.inspect}", :debug)
    return true
  else
    log("Record do not pass validations: #{record.inspect}", :error)
    return false
  end
end

#select_from(table_name) ⇒ Object Also known as: select



7
8
9
# File 'lib/jsondb/commands.rb', line 7

def select_from(table_name)
  return ResultSet.new(table_name)
end

#update_set(table_name, record) ⇒ Object Also known as: update



26
27
28
29
30
31
32
33
34
35
# File 'lib/jsondb/commands.rb', line 26

def update_set(table_name, record)
  if record_validates?(table_name, record)
    JSONdb.tables[table_name].update_record(record)
    log("Inserted record: #{record.inspect}", :debug)
    return true
  else
    log("Record do not pass validations: #{record.inspect}", :error)
    return false
  end
end