Пример #1
0
def faker(con: sqlite3.Connection, count=100_000):
    con.execute('BEGIN')
    for _ in range(count):
        age = get_random_age()
        active = get_random_active()
        # switch for area code
        if get_random_bool():
            # random 6 digit number
            area = get_random_area_code()
            con.execute('INSERT INTO user VALUES (NULL,?,?,?)', (area, age, active))
        else:
            con.execute('INSERT INTO user VALUES (NULL,NULL,?,?)', (age, active))
    con.commit()
Пример #2
0
def faker(count=100_000):
    min_batch_size = 1_000_000
    for _ in range(int(count / min_batch_size)):
        with_area = get_random_bool()
        current_batch = []
        for _ in range(min_batch_size):
            age = get_random_age()
            active = get_random_active()
            # switch for area code
            if with_area:
                # random 6 digit number
                area = get_random_area_code()
                current_batch.append((area, age, active))
            else:
                current_batch.append((age, active))
Пример #3
0
def producer(count: int):
    min_batch_size = 1_000_000
    for _ in range(int(count / min_batch_size)):
        with_area = get_random_bool()
        current_batch = []
        for _ in range(min_batch_size):
            age = get_random_age()
            active = get_random_active()
            # switch for area code
            if with_area:
                # random 6 digit number
                area = get_random_area_code()
                current_batch.append((area, age, active))
            else:
                current_batch.append((age, active))
        if with_area:
            q.put(('INSERT INTO user VALUES (NULL,?,?,?)', current_batch))
        else:
            q.put(('INSERT INTO user VALUES (NULL,NULL,?,?)', current_batch))
def faker(con: sqlite3.Connection, count=100_000):
    min_batch_size = 1_00_000
    for _ in range(int(count / min_batch_size)):
        with_area = get_random_bool()
        current_batch = []
        for _ in range(min_batch_size):
            age = get_random_age()
            active = get_random_active()
            if with_area:
                area = get_random_area_code()
                current_batch.append((area, age, active))
            else:
                current_batch.append((age, active))

        if with_area:
            con.executemany('INSERT INTO user VALUES (NULL,?,?,?)',
                            current_batch)
        else:
            con.executemany('INSERT INTO user VALUES (NULL,NULL,?,?)',
                            current_batch)
        con.commit()