@iamkirbki/database-handler-core 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/Database.d.ts +98 -0
  2. package/dist/Database.d.ts.map +1 -0
  3. package/dist/Database.js +0 -0
  4. package/dist/Query.d.ts +139 -0
  5. package/dist/Query.d.ts.map +1 -0
  6. package/dist/Query.js +0 -0
  7. package/dist/Record.d.ts +125 -0
  8. package/dist/Record.d.ts.map +1 -0
  9. package/dist/Record.js +0 -0
  10. package/dist/Schema.d.ts +14 -0
  11. package/dist/Schema.d.ts.map +1 -0
  12. package/dist/Schema.js +0 -0
  13. package/dist/Table.d.ts +158 -0
  14. package/dist/Table.d.ts.map +1 -0
  15. package/dist/Table.js +0 -0
  16. package/dist/abstract/Model.d.ts +513 -0
  17. package/dist/abstract/Model.d.ts.map +1 -0
  18. package/dist/abstract/Model.js +0 -0
  19. package/dist/abstract/User.d.ts +8 -0
  20. package/dist/abstract/User.d.ts.map +1 -0
  21. package/dist/abstract/User.js +0 -0
  22. package/dist/helpers/QueryStatementBuilder.d.ts +333 -0
  23. package/dist/helpers/QueryStatementBuilder.d.ts.map +1 -0
  24. package/dist/helpers/QueryStatementBuilder.js +0 -0
  25. package/dist/helpers/Validator.d.ts +210 -0
  26. package/dist/helpers/Validator.d.ts.map +1 -0
  27. package/dist/helpers/Validator.js +0 -0
  28. package/dist/index.d.ts +56 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +5 -1
  31. package/dist/interfaces/IDatabaseAdapter.d.ts +11 -0
  32. package/dist/interfaces/IDatabaseAdapter.d.ts.map +1 -0
  33. package/dist/interfaces/IDatabaseAdapter.js +0 -0
  34. package/dist/interfaces/IStatementAdapter.d.ts +7 -0
  35. package/dist/interfaces/IStatementAdapter.d.ts.map +1 -0
  36. package/dist/interfaces/IStatementAdapter.js +0 -0
  37. package/dist/types/index.d.ts +6 -0
  38. package/dist/types/index.d.ts.map +1 -0
  39. package/dist/types/index.js +0 -0
  40. package/dist/types/query.d.ts +14 -0
  41. package/dist/types/query.d.ts.map +1 -0
  42. package/dist/types/query.js +0 -0
  43. package/dist/types/table.d.ts +23 -0
  44. package/dist/types/table.d.ts.map +1 -0
  45. package/dist/types/table.js +0 -0
  46. package/package.json +1 -1
@@ -0,0 +1,98 @@
1
+ import Table from "./Table";
2
+ import Query from "./Query";
3
+ import IDatabaseAdapter from "@core/interfaces/IDatabaseAdapter";
4
+ /**
5
+ * Main Database class for interacting with SQLite databases
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { Database } from 'kirbkis-bettersqlite3-handler';
10
+ *
11
+ * // Create or open a database
12
+ * const db = new Database('./myapp.db');
13
+ *
14
+ * // Access a table
15
+ * const users = db.Table('users');
16
+ *
17
+ * // Create a new table
18
+ * const posts = db.CreateTable('posts');
19
+ * ```
20
+ */
21
+ export default class Database {
22
+ private adapter;
23
+ /**
24
+ * Creates a new Database instance
25
+ *
26
+ * @param dbPath - Path to the SQLite database file (absolute or relative to process.cwd())
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * // Relative path
31
+ * const db = new Database('./data/app.db');
32
+ *
33
+ * // Absolute path
34
+ * const db = new Database('/var/data/app.db');
35
+ *
36
+ * // In-memory database
37
+ * const db = new Database(':memory:');
38
+ * ```
39
+ */
40
+ constructor(adapter: IDatabaseAdapter);
41
+ /**
42
+ * Get a Table instance to interact with an existing table
43
+ *
44
+ * @param name - Name of the table
45
+ * @returns Table instance for querying and manipulating data
46
+ * @throws Error if the table does not exist
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const users = await db.Table('users');
51
+ * const allUsers = await users.Records();
52
+ * ```
53
+ */
54
+ Table(name: string): Promise<Table>;
55
+ /**
56
+ * Create a new table with specified columns
57
+ * Validates table name, column names, and column types before creation
58
+ * Uses CREATE TABLE IF NOT EXISTS to avoid errors if table already exists
59
+ *
60
+ * @param name - Name of the table to create
61
+ * @param columns - Object mapping column names to their type definitions
62
+ * @returns Table instance for the newly created table
63
+ * @throws Error if table name, column names, or column types are invalid
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * // Create a users table
68
+ * const users = await db.CreateTable('users', {
69
+ * id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
70
+ * name: 'TEXT NOT NULL',
71
+ * email: 'TEXT UNIQUE',
72
+ * age: 'INTEGER',
73
+ * created_at: 'DATETIME DEFAULT CURRENT_TIMESTAMP'
74
+ * });
75
+ *
76
+ * // Table is now ready to use
77
+ * await users.Insert({ name: 'John', email: 'john@example.com', age: 30 });
78
+ * ```
79
+ */
80
+ CreateTable(name: string, columns: object): Promise<Table>;
81
+ /**
82
+ * Create a Query object for executing custom SQL queries
83
+ *
84
+ * @param table - Table object for validation and context
85
+ * @param query - The SQL query string with ? placeholders
86
+ * @returns Query instance for executing the query
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const users = db.Table('users');
91
+ * const query = db.Query(users, 'SELECT * FROM users WHERE age > ? AND status = ?');
92
+ * query.Parameters = { age: 18, status: 'active' };
93
+ * const results = query.All();
94
+ * ```
95
+ */
96
+ Query(table: Table, query: string): Query;
97
+ }
98
+ //# sourceMappingURL=Database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../src/Database.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,OAAO,gBAAgB,MAAM,mCAAmC,CAAC;AAEjE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,OAAO,CAAC,OAAO,CAAmB;IAElC;;;;;;;;;;;;;;;;OAgBG;gBACS,OAAO,EAAE,gBAAgB;IAIrC;;;;;;;;;;;;OAYG;IACU,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAMhD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACU,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAsBvE;;;;;;;;;;;;;;OAcG;IACI,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK;CAGjD"}
package/dist/Database.js CHANGED
File without changes
@@ -0,0 +1,139 @@
1
+ import Table from "@core/Table";
2
+ import { QueryParameters } from "./types/index";
3
+ import Record from "@core/Record";
4
+ import IDatabaseAdapter from "@core/interfaces/IDatabaseAdapter";
5
+ /**
6
+ * Query class for executing custom SQL queries
7
+ *
8
+ * Features:
9
+ * - Supports named parameters using @fieldName syntax
10
+ * - Provides type-safe query execution (Run, All, Get)
11
+ * - Transaction support for atomic multi-insert/update operations
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const users = db.Table('users');
16
+ *
17
+ * // SELECT query with parameters
18
+ * const query = db.Query(users, 'SELECT * FROM users WHERE age > @age AND status = @status');
19
+ * query.Parameters = { age: 18, status: 'active' };
20
+ * const results = query.All();
21
+ *
22
+ * // INSERT query
23
+ * const insert = db.Query(users, 'INSERT INTO users (name, email) VALUES (@name, @email)');
24
+ * insert.Parameters = { name: 'John', email: 'john@example.com' };
25
+ * insert.Run();
26
+ *
27
+ * // Transaction for multiple inserts
28
+ * insert.Transaction([
29
+ * { name: 'John', email: 'john@example.com' },
30
+ * { name: 'Jane', email: 'jane@example.com' }
31
+ * ]);
32
+ * ```
33
+ */
34
+ export default class Query {
35
+ readonly Table: Table;
36
+ private readonly adapter;
37
+ private query;
38
+ Parameters: QueryParameters;
39
+ /**
40
+ * Creates a Query instance (usually called via db.Query() method)
41
+ *
42
+ * @param Table - Table instance for validation context
43
+ * @param Query - SQL query string with @fieldName placeholders for parameters
44
+ * @param DB - Database connection instance
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // Direct instantiation (not recommended - use db.Query() instead)
49
+ * const query = new Query(
50
+ * usersTable,
51
+ * 'SELECT * FROM users WHERE id = @id',
52
+ * db
53
+ * );
54
+ * query.Parameters = { id: 1 };
55
+ *
56
+ * // Recommended approach
57
+ * const query = db.Query(usersTable, 'SELECT * FROM users WHERE id = @id');
58
+ * query.Parameters = { id: 1 };
59
+ * ```
60
+ */
61
+ constructor(Table: Table, Query: string, adapter: IDatabaseAdapter);
62
+ /**
63
+ * Execute a query that modifies data (INSERT, UPDATE, DELETE)
64
+ *
65
+ * @template Type - Expected return type (typically { lastInsertRowid: number, changes: number })
66
+ * @returns Result object with lastInsertRowid and changes count
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * // INSERT query
71
+ * const query = db.Query(users, 'INSERT INTO users (name, age) VALUES (@name, @age)');
72
+ * query.Parameters = { name: 'John', age: 30 };
73
+ * const result = query.Run<{ lastInsertRowid: number, changes: number }>();
74
+ * console.log(`Inserted ID: ${result.lastInsertRowid}`);
75
+ *
76
+ * // UPDATE query
77
+ * const update = db.Query(users, 'UPDATE users SET age = @age WHERE id = @id');
78
+ * update.Parameters = { age: 31, id: 1 };
79
+ * const updateResult = update.Run<{ changes: number }>();
80
+ * console.log(`Updated ${updateResult.changes} rows`);
81
+ * ```
82
+ */
83
+ Run<Type>(): Promise<Type>;
84
+ /**
85
+ * Execute a SELECT query and return all matching rows as Record objects
86
+ * Each row is wrapped in a Record instance for convenient updates/deletes
87
+ *
88
+ * @template Type - Expected row type
89
+ * @returns Array of Record objects containing the query results
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * interface User {
94
+ * id: number;
95
+ * name: string;
96
+ * age: number;
97
+ * }
98
+ *
99
+ * const query = db.Query(users, 'SELECT * FROM users WHERE age > @age');
100
+ * query.Parameters = { age: 18 };
101
+ * const results = query.All<User>();
102
+ *
103
+ * // Each result is a Record object
104
+ * results.forEach(user => {
105
+ * console.log(user.values); // { id: 1, name: 'John', age: 30 }
106
+ * user.Update({ age: 31 }); // Can update directly
107
+ * });
108
+ * ```
109
+ */
110
+ All<Type>(): Promise<Record<Type>[]>;
111
+ /**
112
+ * Execute a SELECT query and return the first matching row as a Record object
113
+ * Returns undefined if no rows match the query
114
+ *
115
+ * @template Type - Expected row type
116
+ * @returns Single Record object or undefined if no match found
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * interface User {
121
+ * id: number;
122
+ * name: string;
123
+ * email: string;
124
+ * }
125
+ *
126
+ * const query = db.Query(users, 'SELECT * FROM users WHERE id = @id');
127
+ * query.Parameters = { id: 1 };
128
+ * const user = query.Get<User>();
129
+ *
130
+ * if (user) {
131
+ * console.log(user.values); // { id: 1, name: 'John', email: 'john@example.com' }
132
+ * user.Update({ email: 'newemail@example.com' });
133
+ * }
134
+ * ```
135
+ */
136
+ Get<Type>(): Promise<Record<Type> | undefined>;
137
+ Transaction(paramList: QueryParameters[]): Promise<void>;
138
+ }
139
+ //# sourceMappingURL=Query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Query.d.ts","sourceRoot":"","sources":["../src/Query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,gBAAgB,MAAM,mCAAmC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB,SAAgB,KAAK,EAAE,KAAK,CAAC;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,KAAK,CAAc;IACpB,UAAU,EAAE,eAAe,CAAM;IAExC;;;;;;;;;;;;;;;;;;;;;OAqBG;gBACS,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB;IAMlE;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC;IAKvC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;IAajD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACU,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IAM9C,WAAW,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBtE"}
package/dist/Query.js CHANGED
File without changes
@@ -0,0 +1,125 @@
1
+ import { inspect } from "util";
2
+ import Table from "@core/Table";
3
+ import IDatabaseAdapter from "@core/interfaces/IDatabaseAdapter";
4
+ /**
5
+ * Record class represents a single database row with methods for updates and deletion
6
+ * Automatically returned by Table.Records() and Table.Record() methods
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const user = table.Record({ where: { id: 1 } });
11
+ *
12
+ * // Access values
13
+ * console.log(user?.values);
14
+ *
15
+ * // Update the record
16
+ * user?.Update({ name: 'John Doe', age: 31 });
17
+ *
18
+ * // Delete the record
19
+ * user?.Delete();
20
+ *
21
+ * // JSON serialization works automatically
22
+ * console.log(JSON.stringify(user)); // {"id": 1, "name": "John Doe", ...}
23
+ * ```
24
+ */
25
+ export default class Record<ColumnValuesType> {
26
+ private readonly adapter;
27
+ private _values;
28
+ private readonly _table;
29
+ /**
30
+ * Creates a Record instance (typically called internally by Table methods)
31
+ *
32
+ * @param values - Object containing column names and their values
33
+ * @param db - Database connection instance
34
+ * @param tableName - Name of the table this record belongs to
35
+ */
36
+ constructor(values: ColumnValuesType, adapter: IDatabaseAdapter, table: Table);
37
+ /**
38
+ * Get the raw values object for this record
39
+ *
40
+ * @returns Object containing all column values
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const user = table.Record({ where: { id: 1 } });
45
+ * console.log(user?.values); // { id: 1, name: 'John', email: 'john@example.com' }
46
+ * ```
47
+ */
48
+ get values(): ColumnValuesType;
49
+ /**
50
+ * Update this record in the database
51
+ * Updates both the database and the local values
52
+ *
53
+ * @template TEntity - Record type that must include an 'id' property (number or string)
54
+ * @param newValues - Object with column names and new values to update
55
+ * @throws Error if the record doesn't have an 'id' field
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const user = table.Record({ where: { id: 1 } });
60
+ * user?.Update({ name: 'Jane Doe', age: 28 });
61
+ * // Database is updated and user.values reflects the changes
62
+ * ```
63
+ */
64
+ Update(newValues: object): Promise<void>;
65
+ /**
66
+ * Delete this record from the database
67
+ * Uses all current field values as WHERE clause conditions
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const user = table.Record({ where: { id: 1 } });
72
+ * user?.Delete();
73
+ * // Record is permanently deleted from the database
74
+ * ```
75
+ */
76
+ Delete(): Promise<void>;
77
+ /**
78
+ * Returns the values object when JSON.stringify() is called
79
+ * Allows seamless JSON serialization of Record objects
80
+ *
81
+ * @returns The values object
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const user = table.Record({ where: { id: 1 } });
86
+ * console.log(JSON.stringify(user));
87
+ * // Output: {"id":1,"name":"John","email":"john@example.com"}
88
+ * ```
89
+ */
90
+ toJSON(): ColumnValuesType;
91
+ /**
92
+ * Returns a formatted string representation of the record
93
+ *
94
+ * @returns Pretty-printed JSON string of the values
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const user = table.Record({ where: { id: 1 } });
99
+ * console.log(user?.toString());
100
+ * // Output:
101
+ * // {
102
+ * // "id": 1,
103
+ * // "name": "John",
104
+ * // "email": "john@example.com"
105
+ * // }
106
+ * ```
107
+ */
108
+ toString(): string;
109
+ /**
110
+ * Custom inspect method for console.log() and Node.js REPL
111
+ * Makes Record objects display their values directly instead of the class structure
112
+ *
113
+ * @returns The values object for display
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const user = table.Record({ where: { id: 1 } });
118
+ * console.log(user);
119
+ * // Output: { id: 1, name: 'John', email: 'john@example.com' }
120
+ * // Instead of: Record { _db: ..., _values: {...}, _tableName: '...' }
121
+ * ```
122
+ */
123
+ [inspect.custom](): ColumnValuesType;
124
+ }
125
+ //# sourceMappingURL=Record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Record.d.ts","sourceRoot":"","sources":["../src/Record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,KAAK,MAAM,aAAa,CAAC;AAGhC,OAAO,gBAAgB,MAAM,mCAAmC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM,CAAC,gBAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,OAAO,CAA4C;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAE/B;;;;;;OAMG;gBACS,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK;IAM7E;;;;;;;;;;OAUG;IACH,IAAW,MAAM,IAAI,gBAAgB,CAEpC;IAED;;;;;;;;;;;;;;OAcG;IACU,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBrD;;;;;;;;;;OAUG;IACU,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAUpC;;;;;;;;;;;;OAYG;IACI,MAAM,IAAI,gBAAgB;IAIjC;;;;;;;;;;;;;;;;OAgBG;IACI,QAAQ,IAAI,MAAM;IAIzB;;;;;;;;;;;;;OAaG;IACH,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,gBAAgB;CAGvC"}
package/dist/Record.js CHANGED
File without changes
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Schema module - placeholder for future schema definition and migration features
3
+ *
4
+ * Future capabilities:
5
+ * - Schema versioning and migrations
6
+ * - Schema validation and comparison
7
+ * - Automatic migration generation
8
+ * - Schema import/export
9
+ *
10
+ * @module Schema
11
+ * @packageDocumentation
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,CAAC"}
package/dist/Schema.js CHANGED
File without changes
@@ -0,0 +1,158 @@
1
+ import IDatabaseAdapter from "@core/interfaces/IDatabaseAdapter";
2
+ import { DefaultQueryOptions, QueryOptions, QueryParameters, ReadableTableColumnInfo, TableColumnInfo } from "./types/index";
3
+ import Record from "@core/Record";
4
+ /**
5
+ * Table class for interacting with a specific database table
6
+ * Provides methods for querying, inserting, and retrieving table metadata
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const users = db.Table('users');
11
+ *
12
+ * // Get all records
13
+ * const allUsers = users.Records();
14
+ *
15
+ * // Get filtered records
16
+ * const activeUsers = users.Records({
17
+ * where: { status: 'active' }
18
+ * });
19
+ *
20
+ * // Insert a record
21
+ * users.Insert({ name: 'John', email: 'john@example.com' });
22
+ * ```
23
+ */
24
+ export default class Table {
25
+ private readonly name;
26
+ private readonly adapter;
27
+ /**
28
+ * Private constructor - use Table.create() instead
29
+ *
30
+ * @param name - Name of the table
31
+ * @param adapter - Database adapter instance
32
+ */
33
+ private constructor();
34
+ /**
35
+ * Create a Table instance (async factory method)
36
+ *
37
+ * @param name - Name of the table
38
+ * @param adapter - Database adapter instance
39
+ * @param skipValidation - Skip table existence validation (used when creating new tables)
40
+ * @returns Table instance
41
+ * @throws Error if the table does not exist in the database
42
+ */
43
+ static create(name: string, adapter: IDatabaseAdapter, skipValidation?: boolean): Promise<Table>;
44
+ /**
45
+ * Get the name of the table
46
+ *
47
+ * @returns The table name
48
+ */
49
+ get Name(): string;
50
+ /**
51
+ * Get raw column information from SQLite PRAGMA
52
+ *
53
+ * @returns Array of column metadata from SQLite
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const columns = await table.TableColumnInformation();
58
+ * // [{ cid: 0, name: 'id', type: 'INTEGER', notnull: 0, dflt_value: null, pk: 1 }, ...]
59
+ * ```
60
+ */
61
+ TableColumnInformation(): Promise<TableColumnInfo[]>;
62
+ /**
63
+ * Get readable, formatted column information
64
+ *
65
+ * @returns Array of formatted column metadata with readable properties
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const columns = await table.ReadableTableColumnInformation();
70
+ * // [{ name: 'id', type: 'INTEGER', nullable: false, isPrimaryKey: true, defaultValue: null }, ...]
71
+ * ```
72
+ */
73
+ ReadableTableColumnInformation(): Promise<ReadableTableColumnInfo[]>;
74
+ Drop(): Promise<void>;
75
+ /**
76
+ * Fetch records from the table with optional filtering, ordering, and pagination
77
+ * @param options Query options for selecting records
78
+ * @returns Array of records matching the criteria
79
+ *
80
+ * @example
81
+ * // Get all records
82
+ * table.Records();
83
+ *
84
+ * @example
85
+ * // Get specific columns with filters
86
+ * table.Records({
87
+ * select: 'id, name',
88
+ * where: { status: 'active', age: 25 }
89
+ * });
90
+ *
91
+ * @example
92
+ * // With ordering and pagination
93
+ * table.Records({
94
+ * orderBy: 'created_at DESC',
95
+ * limit: 10,
96
+ * offset: 20
97
+ * });
98
+ */
99
+ Records<Type>(options?: DefaultQueryOptions & QueryOptions): Promise<Record<Type>[]>;
100
+ /**
101
+ * Fetch a single record from the table
102
+ *
103
+ * @param options - Query options for selecting a record
104
+ * @param options.select - Columns to select (default: "*")
105
+ * @param options.where - Filter conditions as key-value pairs
106
+ * @param options.orderBy - SQL ORDER BY clause (e.g., "created_at DESC")
107
+ * @returns Single Record instance or undefined if not found
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * // Get record by ID
112
+ * const user = table.Record({ where: { id: 1 } });
113
+ *
114
+ * // Get most recent record
115
+ * const latest = table.Record({ orderBy: 'created_at DESC' });
116
+ *
117
+ * // Update the record
118
+ * user?.update({ status: 'inactive' });
119
+ * ```
120
+ */
121
+ Record<Type>(options?: DefaultQueryOptions & QueryOptions): Promise<Record<Type> | undefined>;
122
+ /**
123
+ * Get the total count of records in the table
124
+ *
125
+ * @returns Number of records in the table
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const totalUsers = table.RecordsCount;
130
+ * console.log(`Total users: ${totalUsers}`);
131
+ * ```
132
+ */
133
+ RecordsCount(): Promise<number>;
134
+ /**
135
+ * Insert one or multiple records into the table
136
+ * Validates data types against table schema before insertion
137
+ *
138
+ * @param values - Single object or array of objects to insert
139
+ * @returns Insert result with lastInsertRowid and changes count
140
+ * @throws Error if values is empty or contains no columns
141
+ * @throws Error if validation fails (wrong types, missing required fields)
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * // Insert single record
146
+ * const result = table.Insert({ name: 'John', age: 30 });
147
+ * console.log(`Inserted row ID: ${result.lastInsertRowid}`);
148
+ *
149
+ * // Insert multiple records (uses transaction for atomicity)
150
+ * table.Insert([
151
+ * { name: 'John', age: 30 },
152
+ * { name: 'Jane', age: 25 }
153
+ * ]);
154
+ * ```
155
+ */
156
+ Insert<Type>(values: QueryParameters): Promise<Record<Type> | undefined>;
157
+ }
158
+ //# sourceMappingURL=Table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../src/Table.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,mCAAmC,CAAC;AACjE,OAAO,EACH,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,uBAAuB,EAEvB,eAAe,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,MAAM,MAAM,cAAc,CAAC;AAGlC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAE3C;;;;;OAKG;IACH,OAAO;IAKP;;;;;;;;OAQG;WACiB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,cAAc,UAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;IAe3G;;;;OAIG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;;;;;;;;;OAUG;IACU,sBAAsB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAIjE;;;;;;;;;;OAUG;IACU,8BAA8B,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC;IAWpE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAMlC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,OAAO,CAAC,IAAI,EACrB,OAAO,CAAC,EAAE,mBAAmB,GAAG,YAAY,GAC7C,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;IAoB1B;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,MAAM,CAAC,IAAI,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAAG,YAAY,GAC7C,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IAWpC;;;;;;;;;;OAUG;IACU,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAM5C;;;;;;;;;;;;;;;;;;;;;OAqBG;IACU,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;CA0FxF"}
package/dist/Table.js CHANGED
File without changes