llama-stack-mirror/tests/unit/utils/test_sqlstore.py
ehhuang 2603f10f95
Some checks failed
Integration Auth Tests / test-matrix (oauth2_token) (push) Failing after 3s
Integration Tests / test-matrix (http, post_training) (push) Failing after 11s
Integration Tests / test-matrix (library, inference) (push) Failing after 13s
Integration Tests / test-matrix (http, providers) (push) Failing after 15s
Integration Tests / test-matrix (http, tool_runtime) (push) Failing after 16s
Integration Tests / test-matrix (http, datasets) (push) Failing after 18s
Integration Tests / test-matrix (http, scoring) (push) Failing after 16s
Integration Tests / test-matrix (http, agents) (push) Failing after 19s
Integration Tests / test-matrix (library, datasets) (push) Failing after 16s
Integration Tests / test-matrix (http, inspect) (push) Failing after 18s
Integration Tests / test-matrix (library, agents) (push) Failing after 18s
Integration Tests / test-matrix (http, inference) (push) Failing after 20s
Integration Tests / test-matrix (library, inspect) (push) Failing after 9s
Integration Tests / test-matrix (library, post_training) (push) Failing after 10s
Integration Tests / test-matrix (library, tool_runtime) (push) Failing after 8s
Test External Providers / test-external-providers (venv) (push) Failing after 8s
Integration Tests / test-matrix (library, scoring) (push) Failing after 9s
Integration Tests / test-matrix (library, providers) (push) Failing after 11s
Unit Tests / unit-tests (3.11) (push) Failing after 8s
Unit Tests / unit-tests (3.10) (push) Failing after 8s
Unit Tests / unit-tests (3.12) (push) Failing after 8s
Unit Tests / unit-tests (3.13) (push) Failing after 8s
Pre-commit / pre-commit (push) Successful in 57s
feat: support postgresql inference store (#2310)
# What does this PR do?
* Added support postgresql inference store
* Added 'oracle' template that demos how to config postgresql stores
(except for telemetry, which is not supported currently)


## Test Plan

llama stack build --template oracle --image-type conda --run
LLAMA_STACK_CONFIG=http://localhost:8321 pytest -s -v tests/integration/
--text-model accounts/fireworks/models/llama-v3p3-70b-instruct -k
'inference_store'
2025-05-29 14:33:09 -07:00

62 lines
2.2 KiB
Python

# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.
from tempfile import TemporaryDirectory
import pytest
from llama_stack.providers.utils.sqlstore.api import ColumnType
from llama_stack.providers.utils.sqlstore.sqlalchemy_sqlstore import SqlAlchemySqlStoreImpl
from llama_stack.providers.utils.sqlstore.sqlstore import SqliteSqlStoreConfig
@pytest.mark.asyncio
async def test_sqlite_sqlstore():
with TemporaryDirectory() as tmp_dir:
db_name = "test.db"
sqlstore = SqlAlchemySqlStoreImpl(
SqliteSqlStoreConfig(
db_path=tmp_dir + "/" + db_name,
)
)
await sqlstore.create_table(
table="test",
schema={
"id": ColumnType.INTEGER,
"name": ColumnType.STRING,
},
)
await sqlstore.insert("test", {"id": 1, "name": "test"})
await sqlstore.insert("test", {"id": 12, "name": "test12"})
rows = await sqlstore.fetch_all("test")
assert rows == [{"id": 1, "name": "test"}, {"id": 12, "name": "test12"}]
row = await sqlstore.fetch_one("test", {"id": 1})
assert row == {"id": 1, "name": "test"}
row = await sqlstore.fetch_one("test", {"name": "test12"})
assert row == {"id": 12, "name": "test12"}
# order by
rows = await sqlstore.fetch_all("test", order_by=[("id", "asc")])
assert rows == [{"id": 1, "name": "test"}, {"id": 12, "name": "test12"}]
rows = await sqlstore.fetch_all("test", order_by=[("id", "desc")])
assert rows == [{"id": 12, "name": "test12"}, {"id": 1, "name": "test"}]
# limit
rows = await sqlstore.fetch_all("test", limit=1)
assert rows == [{"id": 1, "name": "test"}]
# update
await sqlstore.update("test", {"name": "test123"}, {"id": 1})
row = await sqlstore.fetch_one("test", {"id": 1})
assert row == {"id": 1, "name": "test123"}
# delete
await sqlstore.delete("test", {"id": 1})
rows = await sqlstore.fetch_all("test")
assert rows == [{"id": 12, "name": "test12"}]