Larascript Framework is in Beta
This project is currently in beta stage and under active development.
It is not recommended for use in production environments at this time.
We suggest using it only for small-scale applications and experimental projects while we work on stabilizing the features and APIs.
Database
The framework supports multiple database connections and adapters out of the box. You can configure different database connections in your configuration file.
import databaseConfig from '@src/config/database.config';
Default Configuration
The default database configuration setup:
const DATABASE_DEFAULT_CONNECTION = (process.env.DATABASE_DEFAULT_CONNECTION as string) ?? 'default';
const config: IDatabaseConfig = {
/**
* Default database connection name
*/
defaultConnectionName: DATABASE_DEFAULT_CONNECTION,
/**
* Additional database connections to be kept alive
* Comma-separated list of connection names
*/
keepAliveConnections: (process.env.DATABASE_CONNECTIONS_KEEP_ALIVE as string) ?? '',
/**
* Enable logging for the database operations
*/
enableLogging: parseBooleanFromString(process.env.DATABASE_ENABLE_LOGGING, 'true'),
/**
* Database connections configuration.
* Define multiple connections here if needed.
*/
connections: DatabaseConfig.createConnections([
/**
* Default Postgres connection
*/
DatabaseConfig.createConfig({
connectionName: process.env.DATABASE_POSTGRES_CONNECTION as string,
adapter: PostgresAdapter,
uri: process.env.DATABASE_POSTGRES_URI as string,
options: {}, // Additional connection options can be specified here
}),
/**
* Default MongoDB connection
*/
DatabaseConfig.createConfig({
connectionName: process.env.DATABASE_MONGODB_CONNECTION as string,
adapter: MongoDbAdapter,
uri: process.env.DATABASE_MONGODB_URI as string,
options: {} // Additional connection options can be specified here
}),
])
};
Basic Configuration
defaultConnectionName
The primary database connection to use when no specific connection is specified.
keepAliveConnections
A comma-separated list of connection names that should be kept alive.
enableLogging
Enable or disable database operation logging.
connections
An array of database connection configurations.
connectionName
Unique identifier for the connection
adapter
Database adapter class (PostgresAdapter, MongoDbAdapter, etc.)
uri
Database connection URI
options
Additional connection-specific options
Environment Variables
DATABASE_DEFAULT_CONNECTION
Specifies which connection from your connections array should be used as the default.
DATABASE_CONNECTIONS_KEEP_ALIVE
A comma-separated list of connection names that should be kept alive (persistent connections).
postgres,mongodb
DATABASE_POSTGRES_URI
URI for the Postgres database connection.
postgres://root:example@localhost:5432/app
DATABASE_MONGODB_URI
URI for the MongoDB database connection.
mongodb://localhost:27017/app
DATABASE_ENABLE_LOGGING
Enable or disable database operation logging.