Пример #1
0
    def __init__(self, dbName, tablePrefix='', timeout=1000):
        SqliteDb.__init__(self)
        tablePrefix = tablePrefix.strip()
        if tablePrefix and not tablePrefix.endswith('_'): # Avoid having _ for empty prefix
            tablePrefix += '_'
        #NOTE (Jose Miguel, 2014/01/02
        # Reusing connections is a bit dangerous, since it have lead to
        # unexpected and hard to trace errors due to using an out-of-date
        # reused connection. That's why we are changing now the default to False
        # and only setting to True when the tablePrefix is non-empty, which is the
        # case for classes that are different tables in the same db and it logical
        # to reuse the connection.
        if tablePrefix:
            self._reuseConnections = True
        else:
            self._reuseConnections = False#True
        
        self.CHECK_TABLES = "SELECT name FROM sqlite_master WHERE type='table' AND name='%sObjects';" % tablePrefix
        self.SELECT = "SELECT * FROM %sObjects WHERE " % tablePrefix
        self.FROM   = "FROM %sObjects" % tablePrefix
        self.DELETE = "DELETE FROM %sObjects WHERE " % tablePrefix
        self.INSERT_CLASS = "INSERT INTO %sClasses (label_property, column_name, class_name) VALUES (?, ?, ?)" % tablePrefix
        self.SELECT_CLASS = "SELECT * FROM %sClasses;" % tablePrefix
        self.tablePrefix = tablePrefix
        self._createConnection(dbName, timeout)
        self.INSERT_OBJECT = None
        self.UPDATE_OBJECT = None
        self._columnsMapping = {}

        self.INSERT_PROPERTY = "INSERT INTO Properties (key, value) VALUES (?, ?)"
        self.DELETE_PROPERTY = "DELETE FROM Properties WHERE key=?"
        self.UPDATE_PROPERTY = "UPDATE Properties SET value=? WHERE key=?"
        self.SELECT_PROPERTY = "SELECT value FROM Properties WHERE key=?"
        self.SELECT_PROPERTY_KEYS = "SELECT key FROM Properties"
Пример #2
0
    def __init__(self, dbName, tablePrefix='', timeout=1000):
        SqliteDb.__init__(self)
        tablePrefix = tablePrefix.strip()
        if tablePrefix and not tablePrefix.endswith(
                '_'):  # Avoid having _ for empty prefix
            tablePrefix += '_'
        #NOTE (Jose Miguel, 2014/01/02
        # Reusing connections is a bit dangerous, since it have lead to
        # unexpected and hard to trace errors due to using an out-of-date
        # reused connection. That's why we are changing now the default to False
        # and only setting to True when the tablePrefix is non-empty, which is the
        # case for classes that are different tables in the same db and it logical
        # to reuse the connection.
        if tablePrefix:
            self._reuseConnections = True
        else:
            self._reuseConnections = False  #True

        self.CHECK_TABLES = "SELECT name FROM sqlite_master WHERE type='table' AND name='%sObjects';" % tablePrefix
        self.SELECT = "SELECT * FROM %sObjects WHERE " % tablePrefix
        self.FROM = "FROM %sObjects" % tablePrefix
        self.DELETE = "DELETE FROM %sObjects WHERE " % tablePrefix
        self.INSERT_CLASS = "INSERT INTO %sClasses (label_property, column_name, class_name) VALUES (?, ?, ?)" % tablePrefix
        self.SELECT_CLASS = "SELECT * FROM %sClasses;" % tablePrefix
        self.tablePrefix = tablePrefix
        self._createConnection(dbName, timeout)
        self.INSERT_OBJECT = None
        self.UPDATE_OBJECT = None
        self._columnsMapping = {}

        self.INSERT_PROPERTY = "INSERT INTO Properties (key, value) VALUES (?, ?)"
        self.DELETE_PROPERTY = "DELETE FROM Properties WHERE key=?"
        self.UPDATE_PROPERTY = "UPDATE Properties SET value=? WHERE key=?"
        self.SELECT_PROPERTY = "SELECT value FROM Properties WHERE key=?"
        self.SELECT_PROPERTY_KEYS = "SELECT key FROM Properties"
Пример #3
0
 def __init__(self, dbName, timeout=1000):
     SqliteDb.__init__(self)
     self._createConnection(dbName, timeout)
     self._initialize()
Пример #4
0
    elif tokens[0] == 'rename':
        if '.' in tokens[1]:
            pass
        else:
            db.rename_table(tokens[1], tokens[2])

    elif tokens[0] == 'schema':
        print_schema(db)

    elif tokens[0] == 'serve':
        server.run()


if __name__ == '__main__':
    db = Db('app.db')
    print(db.info())

    if not os.path.isfile('app.json'):
        open('app.json', 'a').close()

    app = json.load(open('app.json'))

    args = sys.argv

    if len(args) > 1:
        process_cmd(args[1:], db)

    app['schema'] = db.schema
    db.close()
    json.dump(app, open('app.json', 'w'), indent=4, sort_keys=True)
Пример #5
0
 def __init__(self, dbName, timeout=1000):
     SqliteDb.__init__(self)
     self._createConnection(dbName, timeout)
     self._initialize()
Пример #6
0
from sqlite_db import SqliteDb

app = Flask(__name__)
api = Api(app)

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

CORS(app)

json_file = Path("db/Simple-Notes-DB.json")
if json_file.is_file():
    db = SheetsDb()
    logger.info("Using Google Sheets as DB")
else:
    db = SqliteDb()
    logger.info("Using local DB")


@app.route("/notes", methods=["GET"])
def get_notes():
    search = request.args.get("search", default=None, type=str)
    if search is not None:
        return jsonify(db.get_filtered_notes(search))
    else:
        return jsonify(db.get_all_notes())


@app.route("/notes/add", methods=["POST"])
def add_note():
    data = request.data.decode("utf-8")