Overview
The @atxp/sqlite package provides a SQLite-based OAuth database implementation for ATXP. It offers persistent OAuth token storage using SQLite, ensuring data retention across application restarts.This package is designed to work seamlessly with
@atxp/client
and @atxp/express
packages when you need persistent storage that survives application restarts. For high-scale applications, consider using @atxp/redis instead.Installation
The
@atxp/sqlite
package includes TypeScript definitions and requires Node.js 16 or higher. It automatically installs @atxp/common
as a dependency.API Reference
Classes
SQLiteOAuthDatabase
The main class for managing OAuth tokens in a SQLite database.
Configuration options for the SQLite database connection.
Saves an OAuth access token in the database.
Retrieves an OAuth access token from the database.
Deletes an OAuth token from the database.
Unique identifier for the token to delete.
Checks if a token exists in the database.
Unique identifier for the token to check.
Lists all token keys stored in the database.
Closes the database connection and releases resources.
Interfaces
SQLiteOAuthDatabaseOptions
Configuration options for the SQLite OAuth database.
Path to the SQLite database file. Can be a relative or absolute path.
Whether to automatically create the required database tables on initialization.
Connection timeout in milliseconds.
Usage Examples
Integration with ATXP Client
Use SQLite storage with the ATXP client for persistent token management:Integration with ATXP Server
Use SQLite storage with the ATXP server for persistent session management:Configuration
Database File Location
The SQLite database file can be placed anywhere on your filesystem:Environment Variables
Configure the database path using environment variables:Database Schema
The package automatically creates the following table structure:The database schema is automatically created when
autoCreateTables
is set to true
(default). You can disable this behavior if you want to manage the schema manually.Troubleshooting
Common Issues
Database file permission errors
Database file permission errors
If you encounter permission errors when creating or accessing the database file:
- Ensure the directory exists and has write permissions
- Check that the user running the application has access to the database path
- Consider using an absolute path instead of a relative path
Connection timeout errors
Connection timeout errors
If you’re experiencing connection timeouts:
- Increase the
connectionTimeout
value - Check if the database file is locked by another process
- Ensure sufficient disk space is available