def file_read file filetoget=file.to_s if File.exist?(filetoget) filetosend= File.read(filetoget) else filetosend= File.read("./userpages/utilpages/pagenotfound") end return filetosend end def file_write file end site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3") # create an items table if !site_DB.table_exists? :pages site_DB.create_table :pages do primary_key :id String :title String :content string :modules_on_page string :menus_on_page end site_DB.create_table :images do primary_key :id String :title String :content end site_DB.create_table :modules do primary_key :id String :title String :content String :tagcontent end site_DB.create_table :menu do primary_key :id String :title String :content end site_DB.create_table :maintable do primary_key :id String :title String :content end end def quick_save(datas) key, value = datas.first title=key content= value save(:maintable, :title => title, :content => content) end def quick_read (datas) datas={:title => datas} read(:maintable, datas) end def read_page(tablename, datas) key, value = datas.first site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3") return current_item = site_DB[tablename][datas] end def save(tablename, datas) site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3") key, value = datas.first if site_DB[tablename][key => value].nil? site_DB[tablename].insert(datas) else current_item = site_DB[tablename].where(key => value) current_item.update(datas) end end def read_modules_list site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3") modules_list=[] site_DB.fetch "SELECT * from modules" do |data| modules_list<< data[:title] end return modules_list end def read_modules_on_page (tablename, column=:title) site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3") begin module_found= site_DB[tablename][column][:modules_on_page] rescue module_found="" end return module_found end def get_modules_content (tablename, column=:title) site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3") begin content_found= site_DB[tablename][column][:content] rescue content_found="" end return content_found end # les tests # def dbtest # datatitle="myfile" # quick_save({datatitle => "my saved content"}) # currentpage= quick_read (datatitle) # # puts "************" # puts currentpage # puts "************" # puts currentpage[:content] # # save(:pages, :title => "filetofound", :content => "pagecontent", :modules_on_page => "module_on_page", :menus_on_page => "menus_on_page") # save(:modules, :title => "module_on_page", :content => "pagecontent") # puts "##############" # puts read(:pages, :title => "filetofound") # puts "##############" # puts "ok, test ended" # # end