Import Data from SQLite

Hello,

I would like to import a SQLite data to the data table of Anvil.

Please help.

Thank you,
Joey

Hi Joey

The best way to do this is to use the Uplink. Write a script on the machine that’s running SQLite and use app_tables.my_table.add_row directly inside the Uplink script to write the data into your Data Table.

Hi Shaun,

Thanks for responding. The SQLite DB is actually a file I’ve just downloaded. So it is on my local machine.

Great! In that case, you can connect to it using sqlite3 from a script on your local machine (and use the Uplink to write the data into a Data Table).

(Here are the sqlite3 docs)

Your script will look something like this:

import sqlite3
import anvil.server

anvil.server.connect('your-uplink-key')

conn = sqlite3.connect('/path/to/my-database.db')
c = conn.cursor()

for row in c.execute('SELECT col1, col2 FROM my_table'):
    app_tables.my_table.add_row(co1=row[0], col2=row[1])
1 Like