Lovefield is a relational database written entirely in JavaScript, designed for web applications. It provides a SQL-like query API, leveraging IndexedDB for persistent storage in the browser environment. Developed by Google, the package reached its last published version, 2.1.12, in February 2017. While the GitHub repository saw minor updates until January 2023, active feature development and official maintenance appear to have ceased significantly earlier, around 2015-2017, as indicated by project videos and publishing dates. Lovefield offers cross-browser compatibility (supporting older versions of Chrome, Firefox, IE, and Safari) but explicitly does not support Node.js due to its reliance on IndexedDB. Its key differentiators were bringing a relational model and SQL-like syntax to client-side data management before more modern alternatives emerged, offering atomic transactions and a query optimizer.
npm install lovefieldVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a database schema, connect to the database, insert data, and query data using Lovefield's SQL-like API in a browser environment, including a simple update operation.
Consider migrating to actively maintained client-side database solutions like IndexedDB directly, Dexie.js, PouchDB, or other state management libraries with persistence layers.
Do not attempt to use Lovefield in Node.js. For server-side or desktop applications, choose a different database solution.
Ensure your entire schema is fully defined before calling `schemaBuilder.connect()`. For schema changes in existing databases, implement the `onUpgrade` callback within `connect()` options, providing logic for data migration between versions.
If modifications are needed, clone the result objects explicitly or perform updates via Lovefield's `update()` API, which ensures data integrity and proper persistence.
To achieve `HAVING` functionality, perform a `select` query with `groupBy`, then filter the results in JavaScript. For complex `GROUP BY` scenarios, multiple queries or client-side aggregation may be necessary.
Database deletion must be performed manually through browser developer tools (e.g., Application -> IndexedDB in Chrome DevTools) or by clearing site data, which will remove all IndexedDB databases for the origin.
Ensure `<script src="path/to/lovefield.min.js"></script>` is correctly placed in your HTML, preferably before any inline scripts that use `lf`. Verify the path to `lovefield.min.js` is correct and accessible.
Ensure `schemaBuilder.connect()` is called only once. Store the returned database instance (`db`) and reuse it for all subsequent operations. You might need a global or module-scoped variable to hold the database connection promise or instance.
Double-check that `lf` is defined and accessible. This often happens if the `lovefield.min.js` script failed to load or a module system (e.g., CommonJS `require`) was incorrectly used in a browser context. Ensure `lf.schema.create()` is called to get a schema builder before attempting `schemaBuilder.connect()`.
No dependency data recorded yet.