· 8 years ago · Apr 30, 2018, 09:08 PM
1import autumn
2import autumn.util
3from autumn.util import create_table
4
5# get a database connection object
6my_test_db = autumn.util.AutoConn("my_test.db")
7
8
9# code to create the database table
10_create_sql = """
11DROP TABLE IF EXISTS mytest;
12CREATE TABLE mytest (
13 id INTEGER PRIMARY KEY AUTOINCREMENT,
14 value INTEGER NOT NULL,
15 UNIQUE(value)
16);"""
17
18# create the table, dropping any previous table of same name
19create_table(my_test_db, _create_sql)
20
21# create ORM class; Autumn introspects the database to find out columns
22class MyTest(autumn.model.Model):
23 db = my_test_db
24
25
26lst = [3, 6, 9, 2, 4, 8, 1, 5, 7] # list of 9 unique values
27
28for n in lst:
29 row = MyTest(value=n) # create MyTest() row instance with value initialized
30 row.save() # write the data to the database
31
321|3
332|6
343|9
354|2
365|4
376|8
387|1
398|5
409|7