We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent af54996 commit fa18184Copy full SHA for fa18184
backend/PyMatcha/utils/orm/_model.py
@@ -372,6 +372,25 @@ def select_all(cls):
372
for item in data:
373
yield cls(item)
374
375
+ @classmethod
376
+ def select_random(cls, count):
377
+ logging.debug(f"Getting {count} random entries from {cls.table_name}")
378
+ temp = cls()
379
+ with temp.db.cursor() as c:
380
+ c.execute(
381
+ """
382
+ SELECT * FROM {}
383
+ ORDER BY RAND()
384
+ LIMIT {}
385
+ """.format(
386
+ temp.table_name, count
387
+ )
388
389
+ data = c.fetchall()
390
+ c.close()
391
+ for item in data:
392
+ yield cls(item)
393
+
394
@classmethod
395
def drop_table(cls):
396
logging.warning("Dropping table {}".format(cls.table_name))
0 commit comments