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