SQLite
Installation​
- for SQLite:
npm install sqlite3
- for Better SQLite:
npm install better-sqlite3
- for sql.js:
npm install sql.js
- for Capacitor, Cordova, Expo, NativeScript and React Native, check the supported platforms.
Data Source Options​
See Data Source Options for the common data source options.
sqlite
data source options​
database
- Database path. For example, "mydb.sql"
better-sqlite3
data source options​
database
- Database path. For example, "mydb.sql"statementCacheSize
- Cache size of the SQLite statement to speed up queries (default 100).prepareDatabase
- Function to run before a database is used in typeorm. You can access the original better-sqlite3 Database object here.nativeBinding
- Relative or absolute path to the native addon (better_sqlite3.node).
sql.js
data source options​
database
: The raw UInt8Array database that should be imported.sqlJsConfig
: Optional initialize config for sql.js.autoSave
: Enable automatic persistence of database changes, requires eitherlocation
orautoSaveCallback
. When set totrue
, every change is saved to the file system (Node.js) or tolocalStorage
/indexedDB
(browser) iflocation
is specified, or theautoSaveCallback
is invoked otherwise.autoSaveCallback
: A function that gets called when changes to the database are made andautoSave
is enabled. The function gets aUInt8Array
that represents the database.location
: The file location to load and save the database to.useLocalForage
: Enables the usage of the localforage library to save and load the database asynchronously from the indexedDB instead of using the synchrony local storage methods in a browser environment. The localforage node module needs to be added to your project, and the localforage.js should be imported in your page.
capacitor
data source options​
database
- Database name (capacitor-sqlite will add the suffixSQLite.db
)driver
- The capacitor-sqlite instance. For example,new SQLiteConnection(CapacitorSQLite)
.mode
- Set the mode for database encryption: "no-encryption" | "encryption" | "secret" | "newsecret"version
- Database versionjournalMode
- The SQLite journal mode (optional)
cordova
data source options​
database
- Database namelocation
- Where to save the database. See cordova-sqlite-storage for options.
expo
data source options​
database
- Name of the database. For example, "mydb".driver
- The Expo SQLite module. For example,require('expo-sqlite')
.
nativescript
data source options​
database
- Database name
react-native
data source options​
database
- Database namelocation
- Where to save the database. See react-native-sqlite-storage for options.
Column Types​
int
, int2
, int8
, integer
, tinyint
, smallint
, mediumint
, bigint
, decimal
, numeric
, float
, double
, real
, double precision
, datetime
, varying character
, character
, native character
, varchar
, nchar
, nvarchar2
, unsigned big int
, boolean
, blob
, text
, clob
, date