Git Product home page Git Product logo

dune's Introduction

Dune

Dune is a minimal value storing database built in Python 3.10+

Note: I made this project for my personnal use, but it can be used for any purpose. Be also careful about get_func method which is 'vulnerable' to code injection by design.

FastAPI example

import fastapi
import uvicorn
import pydantic

from .database import Database
from .table import Table, TableStr


app = fastapi.FastAPI()


class User(pydantic.BaseModel):
    """User model"""

    name: str
    age: int


class MyDatabase(Database):
    """Database object"""

    users: Table[User] = Table("users")
    countries: TableStr = TableStr("countries")


@app.get("/")
def _():
    return {"message": "Welcome to DuneDB demo"}


@app.post("/users")
def _(name: str, age: int):
    """Add a new user"""
    MyDatabase.users.insert(User(name=name, age=age))
    return {}


@app.get("/users")
def _():
    """Get last 100 users"""
    return MyDatabase.users.get_func(lambda _: True, limit=100)


@app.get("/users/{key}")
def _(key: int):
    """Get a user"""
    return MyDatabase.users.get(key)


@app.delete("/users/{key}")
def _(key: int):
    """Delete a user"""
    MyDatabase.users.pop(key)
    return {}


@app.patch("/users/{key}")
def _(key: int, name: str, age: int):
    """Update a user"""
    MyDatabase.users.update(key, User(name=name, age=age))
    return {}


if __name__ == "__main__":
    uvicorn.run(
        "dune.__main__:app",
        host="127.0.0.1",
        port=2000,
        reload=True,
    )

dune's People

Contributors

traumatism avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

eldar4ikyt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.