def showall(input_collection): url = request.url collection = Structure(url) documents = mongoFindAll(input_collection) collection_exists = False data_exists = False for element in documents: collection_exists = True item = {} data = [] for key, value in element.items(): if('id' in key): mod_path = '/table/showone/' + input_collection + '/' + str(value) item['href'] = getCurrentPath(url, mod_path) data.append(generateNameValuePair('id', str(value))) elif(type(value) is list): list_values = ', '.join(map(str, value)) data.append(generateNameValuePair(key, list_values)) else: data.append(generateNameValuePair(key, value)) item['data'] = data collection.appendItem(item) if(collection_exists == False): collection.setError(getError(-1, "Collection does not exist!")) else: collection.setPostTemplate(returnTemplateFromData(input_collection)) return packageResponse(collection)
def showall(table): url = request.url collection = Structure(url) collection.setPostTemplate(generateTemplate(table)) query = "SELECT * FROM {0}".format(table) column_query = "SHOW COLUMNS FROM {0}".format(table) rows = runSQLQuery(query, 0) column_flags = runSQLQuery(column_query, 0) for i in rows: item = {} unique_ref = str(i[0]) mod_path = '/table/showone/' + table + "/" + unique_ref item['href'] = getCurrentPath(url, mod_path) data = [] counter=0 for x in column_flags: data.append(generateNameValuePair(x[0], i[counter])) counter=counter+1 item['data'] = data collection.appendItem(item) return packageResponse(collection)
def root(obj): url = request.url data = Structure(url) results = mongoDBQuery(obj) for item in results: entry = {} entry['href'] = "" entry['data'] = [] for key, value in item.items(): if(key == '_id'): mod_path = '/test/' + db + '/' + str(value) entry['href'] = getCurrentPath(url, mod_path) entry['data'].append(generateNameValuePair(key, str(value))) else: entry['data'].append(generateNameValuePair(key, str(value))) #entry['href'] = "/test/" + obj + "/" + item key = item value = item data.appendItem(entry) return packageResponse(data)
def showDatabases(): url = request.url collection = Structure(url) query = "SHOW DATABASES" data = runSQLQuery(query, 0) for x in data: collection.appendItem(generateNameValuePair('database', x[0])) return packageResponse(collection)
def showallByColumn(table, column): url = request.url collection = Structure(url) collection.setPostTemplate(generateTemplate(table)) query = "SELECT {0} FROM {1}".format(column, table) query_result = runSQLQuery(query, 0) for item in query_result: collection.appendItem({'name': column, 'value': item[0]}) return packageResponse(collection)
def getTableList(): url = request.url collection = Structure(url) results = mongoGetCollections() for i in results: item = {} mod_path = '/table/post/' + i item['href'] = getCurrentPath(url, mod_path) item['data'] = generateNameValuePair('collection', i) collection.appendItem(item) return packageResponse(collection)
def getTableList(): url = request.url collection = Structure(url) query_results = getTables() for i in query_results: item = {} mod_path = '/table/post/' + i[0] item['href'] = getCurrentPath(url, mod_path) item['data'] = [] item['data'].append(generateNameValuePair('table', i[0])) collection.appendItem(item) return packageResponse(collection)
def showone(input_collection, id): url = request.url collection = Structure(url) # API for RDBMS code - Deprecated for ORM MongoDB #column_query = "SHOW COLUMNS FROM {0}".format(table) #columns = runSQLQuery(column_query, 0) #query = "SELECT * FROM {0} WHERE {1} = {2}".format(table, columns[0][0], id) #rows = runSQLQuery(query, 0) document = mongoFindOne(input_collection, id) item = {} mod_path = '/table/showone/' + input_collection + '/' + id item['href'] = getCurrentPath(url, mod_path) row_item_data = [] counter=0 if document is None: collection.setError(getError(3, "")) else: for element in document: for key, value in element.items(): if('id' in key): row_item_data.append(generateNameValuePair(key, str(value))) else: row_item_data.append(generateNameValuePair(key, value)) link = getCurrentPath(url, mod_path) collection.appendLink(generateLink(link, 'showone')) link = getCurrentPath(url, '/table/showall/' + input_collection) collection.appendLink(generateLink(link, 'showall')) link = getCurrentPath(url, '/table/post/' + input_collection) collection.appendLink(generateLink(link, 'post')) item['data'] = row_item_data collection.appendItem(item) collection.setPostTemplate(returnTemplateFromData(input_collection)) return packageResponse(collection)
def showone(table, id): url = request.url collection = Structure(url) column_query = "SHOW COLUMNS FROM {0}".format(table) columns = runSQLQuery(column_query, 0) query = "SELECT * FROM {0} WHERE {1} = {2}".format(table, columns[0][0], id) rows = runSQLQuery(query, 0) item = {} data = [] mod_path = '/table/showone/' + id item['href'] = getCurrentPath(url, mod_path) #row_item={} row_item_data = [] counter=0 if len(rows) == 0: collection.setError(getError(3, "")) else: for x in columns: data_item = generateNameValuePair(x[0], rows[0][counter]) row_item_data.append(data_item) counter=counter+1 link = getCurrentPath(url, mod_path) collection.appendLink(generateLink(link, 'showone')) link = getCurrentPath(url, '/table/showall/' + table) collection.appendLink(generateLink(link, 'showall')) link = getCurrentPath(url, '/table/post/' + table) collection.appendLink(generateLink(link, 'post')) item['data'] = row_item_data collection.appendItem(item) collection.setPostTemplate(generateTemplate(table)) return packageResponse(collection)