SQLite データ ソース
はじめに
SQLite は、データを 1 つのデータベース ファイルに格納する軽量なファイルベースのリレーショナル データベース エンジンです。このトピックでは、Reveal アプリケーションで SQLite データ ソースに接続してローカル アプリケーション データを視覚化および分析する方法について説明します。
サーバー構成
インストール
- ASP.NET
- Node.js
- Node.js - TS
- Java
手順 1 - Reveal SQLite コネクタ パッケージをインストールします。
ASP.NET アプリケーションの場合、SQLite サポートを有効にするには、別の NuGet パッケージをインストールする必要があります。
dotnet add package Reveal.Sdk.Data.SQLite
手順 2 - アプリケーションに SQLite データ ソースを登録します。
builder.Services.AddControllers().AddReveal( builder =>
{
builder.DataSources.RegisterSQLite();
});
Node.js アプリケーションの場合、SQLite データ ソースはメインの Reveal SDK パッケージに既に含まれています。標準の Reveal SDK セットアップ以外に追加のインストールは必要ありません。
Node.js TypeScript アプリケーションの場合、SQLite データ ソース はメインの Reveal SDK パッケージに既に含まれています。標準の Reveal SDK セットアップ以外に追加のインストールは必要ありません。
Java アプリケーションの場合、SQLite データ ソースはメインの Reveal SDK パッケージに既に含まれています。標準の Reveal SDK セットアップ以外に追加のインストールは必要ありません。
接続構成
- ASP.NET
- Node.js
- Node.js - TS
- Java
// Create a data source provider
public class DataSourceProvider : IRVDataSourceProvider
{
public async Task<RVDataSourceItem> ChangeDataSourceItemAsync(IRVUserContext userContext, string dashboardId, RVDataSourceItem dataSourceItem)
{
// Required: Update the underlying data source
await ChangeDataSourceAsync(userContext, dataSourceItem.DataSource);
if (dataSourceItem is RVSQLiteDataSourceItem sqliteItem)
{
// Configure specific item properties if needed
if (sqliteItem.Id == "sqlite_customers")
{
sqliteItem.Table = "Customers";
// Optional: override date inference for this item only
// sqliteItem.DisableDateTypeInference = true;
}
}
return dataSourceItem;
}
public Task<RVDashboardDataSource> ChangeDataSourceAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
if (dataSource is RVSQLiteDataSource sqliteDS)
{
// Configure connection properties
sqliteDS.Database = "your-sqlite-database-path";
// Optional: keep ISO date strings and Unix epoch values as raw types
// sqliteDS.DisableDateTypeInference = true;
}
return Task.FromResult(dataSource);
}
}
// Create data source providers
const dataSourceItemProvider = async (userContext, dataSourceItem) => {
// Required: Update the underlying data source
await dataSourceProvider(userContext, dataSourceItem.dataSource);
if (dataSourceItem instanceof reveal.RVSQLiteDataSourceItem) {
// Configure specific item properties if needed
if (dataSourceItem.id === "sqlite_customers") {
dataSourceItem.table = "Customers";
// Optional: override date inference for this item only
// dataSourceItem.disableDateTypeInference = true;
}
}
return dataSourceItem;
}
const dataSourceProvider = async (userContext, dataSource) => {
if (dataSource instanceof reveal.RVSQLiteDataSource) {
// Configure connection properties
dataSource.database = "your-sqlite-database-path";
// Optional: keep ISO date strings and Unix epoch values as raw types
// dataSource.disableDateTypeInference = true;
}
return dataSource;
}
// Create data source providers
const dataSourceItemProvider = async (userContext: IRVUserContext | null, dataSourceItem: RVDataSourceItem) => {
// Required: Update the underlying data source
await dataSourceProvider(userContext, dataSourceItem.dataSource);
if (dataSourceItem instanceof RVSQLiteDataSourceItem) {
// Configure specific item properties if needed
if (dataSourceItem.id === "sqlite_customers") {
dataSourceItem.table = "Customers";
// Optional: override date inference for this item only
// dataSourceItem.disableDateTypeInference = true;
}
}
return dataSourceItem;
}
const dataSourceProvider = async (userContext: IRVUserContext | null, dataSource: RVDashboardDataSource) => {
if (dataSource instanceof RVSQLiteDataSource) {
// Configure connection properties
dataSource.database = "your-sqlite-database-path";
// Optional: keep ISO date strings and Unix epoch values as raw types
// dataSource.disableDateTypeInference = true;
}
return dataSource;
}
// Create a data source provider
public class DataSourceProvider implements IRVDataSourceProvider {
public RVDataSourceItem changeDataSourceItem(IRVUserContext userContext, String dashboardId, RVDataSourceItem dataSourceItem) {
// Required: Update the underlying data source
changeDataSource(userContext, dataSourceItem.getDataSource());
if (dataSourceItem instanceof RVSQLiteDataSourceItem sqliteItem) {
// Configure specific item properties if needed
if ("sqlite_customers".equals(sqliteItem.getId())) {
sqliteItem.setTable("Customers");
// Optional: override date inference for this item only
// sqliteItem.setDisableDateTypeInference(true);
}
}
return dataSourceItem;
}
public RVDashboardDataSource changeDataSource(IRVUserContext userContext, RVDashboardDataSource dataSource) {
if (dataSource instanceof RVSQLiteDataSource sqliteDS) {
// Configure connection properties
sqliteDS.setDatabase("your-sqlite-database-path");
// Optional: keep ISO date strings and Unix epoch values as raw types
// sqliteDS.setDisableDateTypeInference(true);
}
return dataSource;
}
}
Database は SQLite データベース ファイルを指し、絶対パスと相対パスの両方を指定できます。.NET の場合、相対パスは AppContext.BaseDirectory を基準に解決されます。Node.js および Java の場合、相対パスはアプリケーションの作業ディレクトリを基準に解決されます。
DisableDateTypeInference は RVSQLiteDataSource と RVSQLiteDataSourceItem の両方でオプシ ョンです。有効にすると、Reveal は SQLite の日付に似た値を、自動的に日付/日時フィールドに昇格させる代わりに、生の文字列または数値型のまま保持します。
ChangeDataSourceAsync メソッドでデータ ソースに加えた変更は、ChangeDataSourceItemAsync メソッドには引き継がれません。両方のメソッドでデータ ソースのプロパティを更新する必要があります。上記の例に示すように、ChangeDataSourceItemAsync メソッド内で、データ ソース項目の基になるデータ ソースをパラメーターとして渡して ChangeDataSourceAsync メソッドを呼び出すことをお勧めします。
認証
SQLite は認証を必要としません。Database プロパティを Reveal でクエリする SQLite ファイルに設定することで、サーバー側でアクセスを構成します。