The SQLite3 connector enables LoopBack applications to connect to SQLite3 data sources.Note: This page was generated from the loopback-connector-sqlite3/README.md.

loopback-connector-sqlite3

SQLite is a self-contained, high-reliability, embedded, full-featured, public-domain, SQL database engine. This is the official SQLite3 connector module for the LoopBack framework.

Installation

Enter the following in the top-level directory of your LoopBack application:

  1. $ npm install loopback-connector-sqlite3 --save

The —save option adds the dependency to the application’s package.json file.

Connector settings

Configure the connector with the following data source properties:

  • file: The path to the database file or :memory:
  • debug: Display debug information. Default is false.The SQLite3 connector uses node-sqlite3 as the driver.

Model definition for SQLite3

The model definition consists of the following properties:

  • name: Name of the model, by default, it’s the camel case of the table
  • properties: Property definitions, including default value mapping
  1. {"name": "Inventory", "options": {
  2. "idInjection": false,
  3. }, "properties": {
  4. "id": {
  5. "type": "String",
  6. "required": false,
  7. "length": 64,
  8. "precision": null,
  9. "scale": null
  10. },
  11. "productId": {
  12. "type": "String",
  13. "required": false,
  14. "length": 20,
  15. "precision": null,
  16. "scale": null,
  17. "id": 1
  18. },
  19. "locationId": {
  20. "type": "String",
  21. "required": false,
  22. "length": 20,
  23. "precision": null,
  24. "scale": null,
  25. "id": 1
  26. },
  27. "available": {
  28. "type": "Number",
  29. "required": false,
  30. "length": null,
  31. "precision": 32,
  32. "scale": 0
  33. },
  34. "total": {
  35. "type": "Number",
  36. "required": false,
  37. "length": null,
  38. "precision": 32,
  39. "scale": 0
  40. },
  41. "createdOn": {
  42. "type": "Date",
  43. "required": false,
  44. "sqlite3": {
  45. "dbDefault": "now"
  46. }
  47. }
  48. }}

Type Mapping

LoopBack typeMapped to SQLite3 type
NumberPrimary key stored as INTEGER, others as REAL
BooleanINTEGER 1 or 0
DateINTEGER (ms since Jan 01 1970 00:00:00 0000)
String?
Complex types: GeoPoint, Point, List, Array, Object, and sub-modelsTEXT in JSON format
JSONTEXT

SQLite3 does not enforce types. Any data can be stored in any column regardless of definiton.This connector attempts to check for invalid Date, Number and JSON types.

Unsupported features

Discovering Models

The SQLite3 connector does not currently support model discovery.

Auto Migrate / Auto Update

The SQLite3 connector does not currently support auto-migrate or auto-upgrade.

Running tests

The tests in this repository are mainly integration tests, meaning you will needto run them using our preconfigured test server.

  • Ask a core developer for instructions on how to set up test servercredentials on your machine
  • npm testTags: readme