This is a SQL database mainly designed for providing an interface for JSON processing with the SQL syntax. It works with the syntax library node-jql
Note: It's still under development. Please avoid using it in production
Note: It's not fully optimized, and may be slow. Please avoid doing intensive computation with this engine
Note: NodeJS version 8 or higher is highly recommended due to the native support of async/await
(async () => {
// initialize core
const core = new ApplicationCore({ defaultEngine: new InMemoryDatabaseEngine({ logger: new Logger('InMemoryDatabaseEngine') }) })
await core.init()
// create session
const session = core.createSession()
/**
* USE database
*/
session.use(string)
/**
* ID of the last running task
*/
session.lastTaskId
/**
* CRETAE, INSERT, UPDATE, ALTER etc.
*/
session.update(JQL)
/**
* Predict SELECT result structure
*/
session.predict(JQL)
/**
* SELECT
*/
session.query(JQL)
/**
* Kill running task
*/
session.kill(string)
/**
* Close the session
*/
session.close(boolean?)
})()
You can develop your custom engine.
Please check CancelablePromise
abstract class DatabaseEngine {
protected initing = false
protected inited = false
/**
* Initialize the engine
*/
public abstract async init(): Promise<void>
/**
* Retrieve all rows from a table
* @param database [string] database name
* @param table [string] table name
*/
public abstract retrieveRowsFor(database: string, table: string): CancelablePromise<any[]>
/**
* Get the row count of a table
* @param database [string] database name
* @param table [string] table name
*/
public abstract getCountOf(database: string, table: string): CancelablePromise<number>
/**
* Create a database
* @param name [string]
*/
public abstract createDatabase(name: string): TaskFn<IUpdateResult>
/**
* Drop a database
* @param name [string]
*/
public abstract dropDatabase(name: string): TaskFn<IUpdateResult>
/**
* Execute an UPDATE JQL
* @param jql [JQL]
*/
public abstract executeUpdate(jql: JQL): TaskFn<IUpdateResult>
/**
* Execute a SELECT JQL
* @param jql [AnalyzedQuery]
*/
public abstract executeQuery(jql: AnalyzedQuery): TaskFn<IQueryResult>
}
type TaskFn<T> = (task: Task<T>) => CancelablePromise<T>
class Task {
/**
* Task ID
*/
public readonly id = uuid()
/**
* Task that can be canceled
*/
public readonly promise: CancelablePromise<T>
/**
* Start time of the task
*/
public readonly startFrom = Date.now()
/**
* Task status
*/
public statusCode = StatusCode.PREPARING
}
Try it with npm run test
or yarn test
. It will traverse 200000 rows of data at maximum in specific cases.