herefishyfish / nativescript-sqlite Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
This repository is designed to consolidate various API layers for SQLite into a unified interface that can seamlessly transition between embedded and system APIs. One of the biggest challenges is the absence of a standard approach towards this goal. Numerous frameworks including Web, React Native, Capacitor, Cordova, and various existing NativeScript implementations have developed their own solutions. Previously, I was aligning our efforts with the React Native Quick SQLite API design. However, I've reconsidered this path as it may not be the best approach.
This is the type for the options argument in the class constructor. It contains properties that determine how the SQLite database is opened.
export interface SqliteOpenOptions {
name: string; // Name of the database.
path: string; // Path to the database file.
version: number; // Version of the database.
flags: any // Database flags
multithread: boolean; // Whether to allow multiple threads to access the database.
readOnly: boolean; // Whether to open the database in read-only mode.
}
This class encapsulates all interactions with the SQLite database, with the instance being instantiated by the constructor
const sqlite = new NSCSQLite(options);
export declare class NSCSQLite {
constructor(options: SqliteOpenOptions);
// Returns true if the database connection is open.
isOpen(): boolean;
// Executes a SQL query with optional parameters and returns the results.
// When a single query is provided, it returns an array of results.
// When an array of queries is provided it's treated as a transaction and returns an array of arrays of results.
execute<T = any>(query: string, params?: any[]): QueryResult<T>;
execute<T = any>(query: string[], params?: any[][]): QueryResult<T>[];
// Executes a transaction. The action argument is a function that should return a promise.
// If the action function calls the optional cancel function, the transaction is rolled back.
// Returns a promise that resolves to the return value of the action function.
transaction<T = any>(action: (cancel?: () => void) => Promise<T>): Promise<T>
// Returns the database version number.
getVersion( ): number;
// Attaches another database file to the current database connection.
attach(alias: string, path: string): void;
// Detaches an attached database from the current database connection.
detach(alias: string): void;
// Closes the database connection.
close(): void;
// Deletes the database file.
delete(): void;
// Imports JSON file
importJson(json: string): void;
// Exports JSON file
exportJson(): string;
}
export type QueryResult<T = any> = {
insertId?: number; // The ID of the last inserted row.
rowsAffected: number; // The number of rows affected by the last query.
rows?: T[]; // Array of results as T.
};
The proposed SQLite class and API provides a middle ground. It provides a user-friendly and idiomatic JavaScript API while also exposing the power and flexibility of SQLite. It handles the details of the V8 and SQLite integration, freeing developers from the need to write low-level code or deal directly with the SQLite C API. This makes it a convenient and effective solution for most NativeScript developers.
NativeScript
React Native
Capacitor
Cordova
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.