Skip to main content

A simple SQLite wrapper class based on Python sqlite3

Project description

๐Ÿ“š SimpleDB

SimpleDB๋Š” Python sqlite3๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๋Š” ๊ฐ„๋‹จํ•œ SQLite ๋ž˜ํผ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค.
๊ธฐ๋ณธ์ ์ธ ํ…Œ์ด๋ธ” ์ƒ์„ฑ, ๋ฐ์ดํ„ฐ ์‚ฝ์ž…, ์กฐํšŒ, ๊ฐฑ์‹ , ์‚ญ์ œ ๋“ฑ์„ ์‰ฝ๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


์ฃผ์š” ๊ธฐ๋Šฅ

  • SQLite ๊ฒฝ๋Ÿ‰ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ฒ˜๋ฆฌ
  • ํ…Œ์ด๋ธ” ์ž๋™ ์ƒ์„ฑ
  • ๊ฐ„ํŽธํ•œ CRUD ๋ฉ”์„œ๋“œ
  • ์กฐ๊ฑด ๊ธฐ๋ฐ˜ SELECT/UPDATE/DELETE
  • ๋‹จ์ผ ์ปฌ๋Ÿผ ๊ฐ’ ์‰ฝ๊ฒŒ ์ฐพ๊ธฐ (find)

์‚ฌ์šฉ ์˜ˆ์‹œ

from simpledb_wrapper.simpledb import SimpleDB

# ์„ค์น˜
# pip install simpledb-wrapper


# DB ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐ ์—ฐ๊ฒฐ
db = SimpleDB("example.db")
db.connect()

# ํ…Œ์ด๋ธ” ์ƒ์„ฑ
db.table("users", {
    "id": "INTEGER PRIMARY KEY AUTOINCREMENT",
    "name": "TEXT",
    "age": "INTEGER"
})

# ๋ฐ์ดํ„ฐ ์‚ฝ์ž…
db.insert("users", {"name": "Alice", "age": 25})

# ๋ฐ์ดํ„ฐ ์กฐํšŒ
results = db.select("users")
print(results)

# ์กฐ๊ฑด๋ถ€ ์กฐํšŒ
results = db.select("users", where="age > ?", where_params=(20,))
print(results)

# ๋ฐ์ดํ„ฐ ์ˆ˜์ •
db.update("users", {"age": 30}, where="name = ?", where_params=("Alice",))

# ๋‹จ์ผ ๊ฐ’ ์ฐพ๊ธฐ
age = db.find("users", "name", "Alice", "age")
print(f"Alice์˜ ๋‚˜์ด: {age}")

# ๋ฐ์ดํ„ฐ ์‚ญ์ œ
db.delete("users", where="name = ?", where_params=("Alice",))

# ์—ฐ๊ฒฐ ์ข…๋ฃŒ
db.close()

๋ฉ”์„œ๋“œ ์„ค๋ช…

connect()

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํŒŒ์ผ์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

table(table_name, columns)

ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

  • table_name: ํ…Œ์ด๋ธ” ์ด๋ฆ„
  • columns: {์ปฌ๋Ÿผ๋ช…: ํƒ€์ž…} ๋”•์…”๋„ˆ๋ฆฌ

insert(table, data)

๋ฐ์ดํ„ฐ๋ฅผ ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค.

  • table: ํ…Œ์ด๋ธ” ์ด๋ฆ„
  • data: {์ปฌ๋Ÿผ๋ช…: ๊ฐ’} ๋”•์…”๋„ˆ๋ฆฌ

select(...)

๋ฐ์ดํ„ฐ๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.

  • where, order_by, limit ๋“ฑ ์˜ต์…˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅ

update(...)

๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

delete(...)

๋ฐ์ดํ„ฐ๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.

find(...)

์กฐ๊ฑด์— ๋งž๋Š” ๋‹จ์ผ ๊ฐ’์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

close()

DB ์—ฐ๊ฒฐ์„ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simpledb_wrapper-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simpledb_wrapper-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file simpledb_wrapper-0.1.0.tar.gz.

File metadata

  • Download URL: simpledb_wrapper-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for simpledb_wrapper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6d1035e22b1b077bcf3b1cc577cdddf4da5e7512ead38155737d05a6063e04f0
MD5 9746cbaac8b1831842575ffe981ea8ec
BLAKE2b-256 acbdfa72f063c4535fc1740e1e2f155ba2b67a9713e44c02b5146cf7692471b9

See more details on using hashes here.

File details

Details for the file simpledb_wrapper-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simpledb_wrapper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea6c509d67538e63934d9f38b879eba16fc6ff1e199608f08012da9caebbe251
MD5 40e5b59b02fd6fd2083ebef79aa63914
BLAKE2b-256 2344193e4dd65bb30de7194d501edad1ca557f1c311e5ebb38988efe5767c462

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page