Ejemplo n.º 1
0
		def setUp(self):
			database = db.database.get_frontend_db_rw()

			ident1 = database.query(db.sqldb.Ident)\
				.filter(db.sqldb.Ident.title == self.main_ident)\
				.first()
			if ident1 == None:
				ident1 = db.sqldb.Ident(self.main_ident, self.idents_tag)
				database.add(ident1)

			ident2 = database.query(db.sqldb.Ident)\
				.filter(db.sqldb.Ident.title == self.secondary_ident)\
				.first()
			if ident2 == None:
				ident2 = db.sqldb.Ident(self.secondary_ident, self.idents_tag)
				database.add(ident2)

			node = database.query(db.sqldb.Node)\
				.filter(db.sqldb.Node.ident_1_id == ident1.id)\
				.filter(db.sqldb.Node.ident_2_id == ident2.id)\
				.first()
			if node == None:
				url = database.query(db.sqldb.Url)\
					.filter(db.sqldb.Url.ref == self.ref)\
					.first()
				if url == None:
					url = db.sqldb.Url(self.ref, '')
					database.add(url)
					database.commit()

				node = db.sqldb.Node(ident1, ident2, url, 0)
				database.add(node)

			link = database.query(db.sqldb.Link)\
				.filter(db.sqldb.Link.ident_1_id == ident1.id)\
				.filter(db.sqldb.Link.ident_2_id == ident2.id)\
				.first()
			if link == None:
				link = db.sqldb.Link(ident1, ident2)
				database.add(link)

			database.commit()
Ejemplo n.º 2
0
def stats(frontend, args):
	'''List DB statistics'''

	database = db.database.get_frontend_db_ro()

	db_stats = database.query(db.sqldb.Stat).all()

	stats = {}
	for db_stat in db_stats:
		stats[db_stat.key] = db_stat.value

	return frontend((stats, ))
Ejemplo n.º 3
0
def get_ident(database, title, tag):
	return database.query(db.sqldb.Ident)\
		.filter(db.sqldb.Ident.title == title)\
		.filter(db.sqldb.Ident.tag == tag)\
		.one()
Ejemplo n.º 4
0
		or None)

	if not api.utils.sql_valid(valid_pattern):
		raise QueryError('Invalid argument: ' + pattern)

	if len(tags) > MAX_TAGS:
		raise QueryError("Invalid argument: 'tags' list should include not more than " + MAX_TAGS + " entries")

	valid_tags = [ api.utils.sql_escape(tag) for tag in tags ]
	for tag, original_tag in zip(valid_tags, tags):
		if not tag or not api.utils.sql_valid(tag):
			raise QueryError('Invalid argument: ' + original_tag)

	database = db.database.get_frontend_db_ro()

	db_idents = database.query(db.sqldb.Ident)\
		.filter(db.sqldb.Ident.title.like(valid_pattern + '%'))

	if valid_tags:
		db_idents = db_idents\
			.filter(db.sqldb.Ident.tag.in_(valid_tags))

	db_idents = db_idents\
		.order_by(db.sqldb.Ident.score.desc())\
		.offset(offset)\
		.limit(limit)

	return frontend((
		{
			'title' : ident.title,
			'tag' : ident.tag,
			'score' : ident.score,