Updates
This commit is contained in:
parent
c7f2f22b32
commit
a1d14fa2b2
58
README.md
58
README.md
@ -120,27 +120,27 @@ This creates the SQLite database file and creates/updates all tables to match yo
|
|||||||
### 4. Use the CRUD API
|
### 4. Use the CRUD API
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import NodeSQLite from "@moduletrace/nsqlite";
|
import NSQLite from "@moduletrace/nsqlite";
|
||||||
|
|
||||||
// Insert
|
// Insert
|
||||||
await NodeSQLite.insert({
|
await NSQLite.insert({
|
||||||
table: "users",
|
table: "users",
|
||||||
data: [{ first_name: "Alice", email: "alice@example.com" }],
|
data: [{ first_name: "Alice", email: "alice@example.com" }],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Select
|
// Select
|
||||||
const result = await NodeSQLite.select({ table: "users" });
|
const result = await NSQLite.select({ table: "users" });
|
||||||
console.log(result.payload); // Alice's row
|
console.log(result.payload); // Alice's row
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
await NodeSQLite.update({
|
await NSQLite.update({
|
||||||
table: "users",
|
table: "users",
|
||||||
targetId: 1,
|
targetId: 1,
|
||||||
data: { first_name: "Alicia" },
|
data: { first_name: "Alicia" },
|
||||||
});
|
});
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
await NodeSQLite.delete({ table: "users", targetId: 1 });
|
await NSQLite.delete({ table: "users", targetId: 1 });
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -323,7 +323,7 @@ npx nsqlite restore
|
|||||||
Import the default export:
|
Import the default export:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import NodeSQLite from "@moduletrace/nsqlite";
|
import NSQLite from "@moduletrace/nsqlite";
|
||||||
```
|
```
|
||||||
|
|
||||||
All methods return an `APIResponseObject<T>`:
|
All methods return an `APIResponseObject<T>`:
|
||||||
@ -349,7 +349,7 @@ All methods return an `APIResponseObject<T>`:
|
|||||||
### Select
|
### Select
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
NodeSQLite.select<T>({ table, query?, count?, targetId? })
|
NSQLite.select<T>({ table, query?, count?, targetId? })
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -363,13 +363,13 @@ NodeSQLite.select<T>({ table, query?, count?, targetId? })
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
// Get all users
|
// Get all users
|
||||||
const res = await NodeSQLite.select({ table: "users" });
|
const res = await NSQLite.select({ table: "users" });
|
||||||
|
|
||||||
// Get by ID
|
// Get by ID
|
||||||
const res = await NodeSQLite.select({ table: "users", targetId: 42 });
|
const res = await NSQLite.select({ table: "users", targetId: 42 });
|
||||||
|
|
||||||
// Filter with LIKE
|
// Filter with LIKE
|
||||||
const res = await NodeSQLite.select<UserType>({
|
const res = await NSQLite.select<UserType>({
|
||||||
table: "users",
|
table: "users",
|
||||||
query: {
|
query: {
|
||||||
query: {
|
query: {
|
||||||
@ -379,11 +379,11 @@ const res = await NodeSQLite.select<UserType>({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Count rows
|
// Count rows
|
||||||
const res = await NodeSQLite.select({ table: "users", count: true });
|
const res = await NSQLite.select({ table: "users", count: true });
|
||||||
console.log(res.count);
|
console.log(res.count);
|
||||||
|
|
||||||
// Pagination
|
// Pagination
|
||||||
const res = await NodeSQLite.select({
|
const res = await NSQLite.select({
|
||||||
table: "users",
|
table: "users",
|
||||||
query: { limit: 10, page: 2 },
|
query: { limit: 10, page: 2 },
|
||||||
});
|
});
|
||||||
@ -394,7 +394,7 @@ const res = await NodeSQLite.select({
|
|||||||
### Insert
|
### Insert
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
NodeSQLite.insert<T>({ table, data });
|
NSQLite.insert<T>({ table, data });
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -407,7 +407,7 @@ NodeSQLite.insert<T>({ table, data });
|
|||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const res = await NodeSQLite.insert({
|
const res = await NSQLite.insert({
|
||||||
table: "users",
|
table: "users",
|
||||||
data: [
|
data: [
|
||||||
{ first_name: "Alice", last_name: "Smith", email: "alice@example.com" },
|
{ first_name: "Alice", last_name: "Smith", email: "alice@example.com" },
|
||||||
@ -423,7 +423,7 @@ console.log(res.postInsertReturn?.insertId); // last inserted row ID
|
|||||||
### Update
|
### Update
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
NodeSQLite.update<T>({ table, data, query?, targetId? })
|
NSQLite.update<T>({ table, data, query?, targetId? })
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -441,14 +441,14 @@ A WHERE clause is required. If no condition matches, `success` is `false`.
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
// Update by ID
|
// Update by ID
|
||||||
await NodeSQLite.update({
|
await NSQLite.update({
|
||||||
table: "users",
|
table: "users",
|
||||||
targetId: 1,
|
targetId: 1,
|
||||||
data: { first_name: "Alicia" },
|
data: { first_name: "Alicia" },
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update with custom query
|
// Update with custom query
|
||||||
await NodeSQLite.update({
|
await NSQLite.update({
|
||||||
table: "users",
|
table: "users",
|
||||||
data: { last_name: "Doe" },
|
data: { last_name: "Doe" },
|
||||||
query: {
|
query: {
|
||||||
@ -464,7 +464,7 @@ await NodeSQLite.update({
|
|||||||
### Delete
|
### Delete
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
NodeSQLite.delete<T>({ table, query?, targetId? })
|
NSQLite.delete<T>({ table, query?, targetId? })
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -479,10 +479,10 @@ A WHERE clause is required. If no condition is provided, `success` is `false`.
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
// Delete by ID
|
// Delete by ID
|
||||||
await NodeSQLite.delete({ table: "users", targetId: 1 });
|
await NSQLite.delete({ table: "users", targetId: 1 });
|
||||||
|
|
||||||
// Delete with condition
|
// Delete with condition
|
||||||
await NodeSQLite.delete({
|
await NSQLite.delete({
|
||||||
table: "users",
|
table: "users",
|
||||||
query: {
|
query: {
|
||||||
query: {
|
query: {
|
||||||
@ -497,7 +497,7 @@ await NodeSQLite.delete({
|
|||||||
### Raw SQL
|
### Raw SQL
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
NodeSQLite.sql<T>({ sql, values? })
|
NSQLite.sql<T>({ sql, values? })
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -511,11 +511,11 @@ SELECT statements return rows; all other statements return `postInsertReturn`.
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
// SELECT
|
// SELECT
|
||||||
const res = await NodeSQLite.sql<UserType>({ sql: "SELECT * FROM users" });
|
const res = await NSQLite.sql<UserType>({ sql: "SELECT * FROM users" });
|
||||||
console.log(res.payload);
|
console.log(res.payload);
|
||||||
|
|
||||||
// INSERT with params
|
// INSERT with params
|
||||||
await NodeSQLite.sql({
|
await NSQLite.sql({
|
||||||
sql: "INSERT INTO users (first_name, email) VALUES (?, ?)",
|
sql: "INSERT INTO users (first_name, email) VALUES (?, ?)",
|
||||||
values: ["Charlie", "charlie@example.com"],
|
values: ["Charlie", "charlie@example.com"],
|
||||||
});
|
});
|
||||||
@ -590,7 +590,7 @@ Set `equality` on any query field to control the comparison:
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
// Find users with email NOT NULL, ordered by created_at DESC, limit 20
|
// Find users with email NOT NULL, ordered by created_at DESC, limit 20
|
||||||
const res = await NodeSQLite.select<UserType>({
|
const res = await NSQLite.select<UserType>({
|
||||||
table: "users",
|
table: "users",
|
||||||
query: {
|
query: {
|
||||||
query: {
|
query: {
|
||||||
@ -605,7 +605,7 @@ const res = await NodeSQLite.select<UserType>({
|
|||||||
### JOIN
|
### JOIN
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const res = await NodeSQLite.select({
|
const res = await NSQLite.select({
|
||||||
table: "posts",
|
table: "posts",
|
||||||
query: {
|
query: {
|
||||||
join: [
|
join: [
|
||||||
@ -669,7 +669,7 @@ npx nsqlite schema --vector
|
|||||||
### Query vectors
|
### Query vectors
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const res = await NodeSQLite.select({
|
const res = await NSQLite.select({
|
||||||
table: "documents",
|
table: "documents",
|
||||||
query: {
|
query: {
|
||||||
query: {
|
query: {
|
||||||
@ -718,10 +718,10 @@ export type NSQLITE_MY_APP_ALL_TYPEDEFS = NSQLITE_MY_APP_USERS; // intersection
|
|||||||
Use the generated types with the CRUD API for full type safety:
|
Use the generated types with the CRUD API for full type safety:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import NodeSQLite from "@moduletrace/nsqlite";
|
import NSQLite from "@moduletrace/nsqlite";
|
||||||
import { NSQLITE_MY_APP_USERS, NSQLiteTables } from "./db/types/db";
|
import { NSQLITE_MY_APP_USERS, NSQLiteTables } from "./db/types/db";
|
||||||
|
|
||||||
const res = await NodeSQLite.select<NSQLITE_MY_APP_USERS>({
|
const res = await NSQLite.select<NSQLITE_MY_APP_USERS>({
|
||||||
table: "users" as (typeof NSQLiteTables)[number],
|
table: "users" as (typeof NSQLiteTables)[number],
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@ -745,7 +745,7 @@ Every table automatically receives the following fields — you do not need to d
|
|||||||
```
|
```
|
||||||
node-sqlite/
|
node-sqlite/
|
||||||
├── src/
|
├── src/
|
||||||
│ ├── index.ts # Main export (NodeSQLite object)
|
│ ├── index.ts # Main export (NSQLite object)
|
||||||
│ ├── commands/
|
│ ├── commands/
|
||||||
│ │ ├── index.ts # CLI entry point
|
│ │ ├── index.ts # CLI entry point
|
||||||
│ │ ├── schema.ts # `schema` command
|
│ │ ├── schema.ts # `schema` command
|
||||||
|
|||||||
4
dist/index.d.ts
vendored
4
dist/index.d.ts
vendored
@ -3,11 +3,11 @@ import DbInsert from "./lib/sqlite/db-insert";
|
|||||||
import DbSelect from "./lib/sqlite/db-select";
|
import DbSelect from "./lib/sqlite/db-select";
|
||||||
import DbSQL from "./lib/sqlite/db-sql";
|
import DbSQL from "./lib/sqlite/db-sql";
|
||||||
import DbUpdate from "./lib/sqlite/db-update";
|
import DbUpdate from "./lib/sqlite/db-update";
|
||||||
declare const NodeSQLite: {
|
declare const NSQLite: {
|
||||||
readonly select: typeof DbSelect;
|
readonly select: typeof DbSelect;
|
||||||
readonly insert: typeof DbInsert;
|
readonly insert: typeof DbInsert;
|
||||||
readonly update: typeof DbUpdate;
|
readonly update: typeof DbUpdate;
|
||||||
readonly delete: typeof DbDelete;
|
readonly delete: typeof DbDelete;
|
||||||
readonly sql: typeof DbSQL;
|
readonly sql: typeof DbSQL;
|
||||||
};
|
};
|
||||||
export default NodeSQLite;
|
export default NSQLite;
|
||||||
|
|||||||
4
dist/index.js
vendored
4
dist/index.js
vendored
@ -8,11 +8,11 @@ const db_insert_1 = __importDefault(require("./lib/sqlite/db-insert"));
|
|||||||
const db_select_1 = __importDefault(require("./lib/sqlite/db-select"));
|
const db_select_1 = __importDefault(require("./lib/sqlite/db-select"));
|
||||||
const db_sql_1 = __importDefault(require("./lib/sqlite/db-sql"));
|
const db_sql_1 = __importDefault(require("./lib/sqlite/db-sql"));
|
||||||
const db_update_1 = __importDefault(require("./lib/sqlite/db-update"));
|
const db_update_1 = __importDefault(require("./lib/sqlite/db-update"));
|
||||||
const NodeSQLite = {
|
const NSQLite = {
|
||||||
select: db_select_1.default,
|
select: db_select_1.default,
|
||||||
insert: db_insert_1.default,
|
insert: db_insert_1.default,
|
||||||
update: db_update_1.default,
|
update: db_update_1.default,
|
||||||
delete: db_delete_1.default,
|
delete: db_delete_1.default,
|
||||||
sql: db_sql_1.default,
|
sql: db_sql_1.default,
|
||||||
};
|
};
|
||||||
exports.default = NodeSQLite;
|
exports.default = NSQLite;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/nsqlite",
|
"name": "@moduletrace/nsqlite",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"description": "SQLite manager for Node JS",
|
"description": "SQLite manager for Node JS",
|
||||||
"author": "Benjamin Toby",
|
"author": "Benjamin Toby",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import DbSelect from "./lib/sqlite/db-select";
|
|||||||
import DbSQL from "./lib/sqlite/db-sql";
|
import DbSQL from "./lib/sqlite/db-sql";
|
||||||
import DbUpdate from "./lib/sqlite/db-update";
|
import DbUpdate from "./lib/sqlite/db-update";
|
||||||
|
|
||||||
const NodeSQLite = {
|
const NSQLite = {
|
||||||
select: DbSelect,
|
select: DbSelect,
|
||||||
insert: DbInsert,
|
insert: DbInsert,
|
||||||
update: DbUpdate,
|
update: DbUpdate,
|
||||||
@ -12,4 +12,4 @@ const NodeSQLite = {
|
|||||||
sql: DbSQL,
|
sql: DbSQL,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default NodeSQLite;
|
export default NSQLite;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user