You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
1.0 KiB

  1. import sqlite3
  2. import os
  3. osp = os.path
  4. DB_PATH = osp.join(osp.dirname(__file__),'ext.db')
  5. ext_database = sqlite3.connect(DB_PATH)
  6. def init_db():
  7. cur = ext_database.cursor()
  8. cur.execute('CREATE TABLE "updates" ( `ext` TEXT, `update_time` INTEGER, `file_count` INTEGER, PRIMARY KEY(`ext`) )')
  9. class Searcher:
  10. def __init__(self,ext):
  11. self.cur = ext_database.cursor()
  12. self.ext = ext
  13. self.index = '{}_index'.format(ext)
  14. def __init_table__(self):
  15. self.cur.execute('CREATE TABLE IF NOT EXISTS ? (`name` TEXT,`fullpath` TEXT,UNIQUE(name,fullpath));',[self.ext])
  16. self.cur.execute('CREATE INDEX IF NOT EXISTS ? ON ? ( `name`, `fullpath` )',[self.index,self.ext])
  17. def _update_(self,update_mtimes):
  18. # update logic
  19. self.cur.executemany('INSERT OR IGNORE INTO ? VALUES (?,?)',params)
  20. self.cur.execute('INSERT INTO updates VALUES (?, ?, ?)',[self.ext,time,count])
  21. def _commit_(self):
  22. ext_database.commit()
  23. def search(query,regex=False):
  24. pass