asopi tech
asopi techIndie Developer

Asopitech With · Cloud storage

Dropbox file sync with Alopex DB

Dropbox file sync is how Dropbox, the cloud storage service, keeps files and their version history in step across devices. How would we make it with Alopex DB?

Updated: Oct 12, 2026

What the service does

Dropbox syncs and shares files across devices. Saved files sync to every device automatically, and earlier versions can be restored. Edits made offline are applied once the device is back online. The data is file and folder details, version history and sharing settings.

Where the data lives

  • SQL tables: files, folders, versions and shares live in tables. The list of earlier versions comes from the versions table.
  • Transactions: moving or renaming a file and adding a version commit in the same transaction.

File contents sit in file storage, and the tables hold their details.

Deployment

Alopex DB is embedded in the device app, so the file list and versions are available offline. In the cloud, an Alopex DB server receives the sync, and scales out to an Alopex DB cluster as users grow. The device and the server use the same SQL.

Why Alopex DB fits

A sync service keeps the same file details on the device and in the cloud. Alopex DB uses the same data model and SQL embedded and on the server, so both sides are built the same way.

See it in code

Files and versions live in tables, and a rename plus a new version commit in one transaction. Just the core of keeping things consistent.

import alopex

# 端末にもサーバーにも同じSQL。ここでは端末側の .alopex ファイル
db = alopex.Database.open("dropbox.alopex")

db.execute_sql("""
    CREATE TABLE IF NOT EXISTS files (
        id INTEGER PRIMARY KEY,
        name TEXT
    )
""")
db.execute_sql("""
    CREATE TABLE IF NOT EXISTS versions (
        file_id INTEGER,
        rev INTEGER,
        note TEXT,
        created DATE
    )
""")

db.execute_sql("INSERT INTO files (id, name) VALUES (?, ?)", [1, "report.txt"])
db.execute_sql("INSERT INTO versions (file_id, rev, note, created) VALUES (?, ?, ?, ?)", [1, 1, "初版", "2026-10-18"])

# 改名と版の追加を、同じトランザクションでコミットする
tx = db.begin(alopex.TxnMode.READ_WRITE)
try:
    tx.execute_sql("UPDATE files SET name = ? WHERE id = ?", ["report-final.txt", 1])
    tx.execute_sql("INSERT INTO versions (file_id, rev, note, created) VALUES (?, ?, ?, ?)", [1, 2, "改名", "2026-10-20"])
    tx.commit()
except Exception:
    tx.rollback()
    raise

# 版の履歴を新しい順に引く
rows = db.execute_sql("""
    SELECT v.rev, v.note, v.created
    FROM versions AS v
    JOIN files AS f ON f.id = v.file_id
    WHERE f.name = ?
    ORDER BY v.rev DESC
""", ["report-final.txt"])

for row in rows:
    print(f"rev{row['rev']}", row["created"], row["note"])

The rename and the new version land in one transaction; no in-between state is ever visible.

Alopex DB uses the same SQL embedded and on the server, so both sides of a sync service line up. The quickstart lets you try both.