コード例 #1
0
import pytest
from starlette_core.database import Database, DatabaseURL

url = DatabaseURL("sqlite://")
database = Database(url)


@pytest.fixture()
def db():
    yield database
    database.truncate_all(force=True)
コード例 #2
0
from starlette_core.database import Database, metadata

from app.settings import DATABASE_URL

# set db config options
if DATABASE_URL.driver == "psycopg2":
    engine_kwargs = {"pool_size": 20, "max_overflow": 0}
else:
    engine_kwargs = {}

# setup database url
db = Database(DATABASE_URL, engine_kwargs=engine_kwargs)

# print all running queries to the console
# see https://docs.sqlalchemy.org/en/13/core/engines.html
# db.engine.echo = True

# The following will need to be added to your first revision to enable the
# uuid extension. Using this will mean packages that interact with the db
# will not need to worry about setting a default uuid. I have seen cases where
# default=uuid.uuid4 does not work.

# op.execute("create EXTENSION if not EXISTS \"uuid-ossp\"")

# change the id pk's to a postgres uuid type
# from sqlalchemy import Column, text  # noqa isort:skip
# from sqlalchemy.dialects.postgresql import UUID  # noqa isort:skip
# from starlette_core.database import Base  # noqa isort:skip

# Base.id = Column(
#     UUID(as_uuid=True), primary_key=True, server_default=text("uuid_generate_v4()")
コード例 #3
0
ファイル: main.py プロジェクト: bigmassa/starlette-files
        session.add(rendition)
        session.commit()

        return rendition


class MyImageRenditionModel(Base):
    file = sa.Column(MyImageRendition.as_mutable(sa.JSON))
    image_id = sa.Column(sa.Integer,
                         sa.ForeignKey("myimagemodel.id"),
                         nullable=False)
    image = orm.relationship("MyImageModel")
    filter_spec = sa.Column(sa.Text)


db = Database("sqlite:///")
db.create_all()

app = Starlette(debug=True)
app.mount("/fs",
          StaticFiles(directory=root_directory, check_dir=False),
          name="fs")

templates = Jinja2Templates(loader=jinja2.FileSystemLoader(templates_path))


@app.route("/")
class Homepage(HTTPEndpoint):
    async def get(self, request):
        return templates.TemplateResponse("home.html", {"request": request})
コード例 #4
0
ファイル: main.py プロジェクト: stuartaccent/starlette-audit
templates = Jinja2Templates(loader=jinja2.ChoiceLoader([
    jinja2.PackageLoader("starlette_admin", "templates"),
    jinja2.PackageLoader("starlette_audit", "templates"),
]))

# config
starlette_admin.config.logout_url = '/auth/logout'
starlette_admin.config.templates = templates
starlette_auth.config.change_pw_template = "starlette_admin/auth/change_password.html"
starlette_auth.config.login_template = "starlette_admin/auth/login.html"
starlette_auth.config.templates = templates

url = DatabaseURL("sqlite:///example/db.sqlite3")

db = Database(url)
db.create_all()

# create an admin site
adminsite = AdminSite(name="admin", permission_scopes=[])
# register admins
adminsite.register(ChildAdmin)
adminsite.register(ParentAdmin)
adminsite.register(AuditAdmin)

# create app
app = Starlette(debug=DEBUG)

app.mount(path="/static",
          app=StaticFiles(directory="static", packages=["starlette_admin"]),
          name="static")
コード例 #5
0
ファイル: db.py プロジェクト: davidaccent/charts-starlette
from starlette_core.database import Database, metadata

from app import settings

# setup database url
db = Database(settings.DATABASE_URL)

# print all running queries to the console
# see https://docs.sqlalchemy.org/en/13/core/engines.html
# db.engine.echo = True

# import project and external tables
from starlette_auth import tables  # noqa isort:skip
コード例 #6
0
from starlette_auth.tables import User

# basic config for auth app
starlette_auth.config.templates = Jinja2Templates(
    loader=jinja2.FileSystemLoader("tests/templates"))
starlette_auth.config.login_template = "form.html"
starlette_auth.config.change_pw_template = "form.html"
starlette_auth.config.reset_pw_template = "form.html"
starlette_auth.config.reset_pw_done_template = "thanks.html"
starlette_auth.config.reset_pw_email_subject_template = "password_reset_subject.txt"
starlette_auth.config.reset_pw_email_template = "password_reset_body.txt"
starlette_auth.config.reset_pw_confirm_template = "form.html"
starlette_auth.config.reset_pw_complete_template = "thanks.html"

url = DatabaseURL("sqlite://")
db = Database(url)


@pytest.fixture(scope="session", autouse=True)
def database():
    if database_exists(str(url)):
        drop_database(str(url))

    create_database(str(url))

    db.drop_all()
    db.create_all()

    return db