@atscript/db-sqlite 0.1.36 → 0.1.38

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.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { BaseDbAdapter, TDbInsertResult, TDbInsertManyResult, DbQuery, FilterExpr, TDbUpdateResult, TDbDeleteResult, TExistingColumn, TColumnDiff, TSyncColumnResult, DbSpace } from '@atscript/utils-db';
1
+ import { BaseDbAdapter, TDbInsertResult, TDbInsertManyResult, DbQuery, FilterExpr, TDbUpdateResult, TDbDeleteResult, TExistingColumn, TColumnDiff, TSyncColumnResult, TSearchIndexInfo, DbSpace } from '@atscript/db';
2
2
  import { TAtscriptAnnotatedType } from '@atscript/typescript/utils';
3
3
  import * as better_sqlite3 from 'better-sqlite3';
4
4
  import { FilterExpr as FilterExpr$1 } from '@uniqu/core';
5
+ import { TSqlFragment } from '@atscript/db-sql-tools';
6
+ export { TSqlFragment } from '@atscript/db-sql-tools';
5
7
 
6
8
  /**
7
9
  * Result of a SQL statement that modifies data (INSERT, UPDATE, DELETE).
@@ -65,6 +67,7 @@ interface TSqliteDriver {
65
67
  */
66
68
  declare class SqliteAdapter extends BaseDbAdapter {
67
69
  protected readonly driver: TSqliteDriver;
70
+ supportsNativeValueDefaults(): boolean;
68
71
  constructor(driver: TSqliteDriver);
69
72
  protected _beginTransaction(): Promise<unknown>;
70
73
  protected _commitTransaction(): Promise<void>;
@@ -84,6 +87,7 @@ declare class SqliteAdapter extends BaseDbAdapter {
84
87
  findOne(query: DbQuery): Promise<Record<string, unknown> | null>;
85
88
  findMany(query: DbQuery): Promise<Array<Record<string, unknown>>>;
86
89
  count(query: DbQuery): Promise<number>;
90
+ aggregate(query: DbQuery): Promise<Array<Record<string, unknown>>>;
87
91
  updateOne(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
88
92
  updateMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
89
93
  replaceOne(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
@@ -91,6 +95,12 @@ declare class SqliteAdapter extends BaseDbAdapter {
91
95
  deleteOne(filter: FilterExpr): Promise<TDbDeleteResult>;
92
96
  deleteMany(filter: FilterExpr): Promise<TDbDeleteResult>;
93
97
  ensureTable(): Promise<void>;
98
+ private _incrementSeeded;
99
+ /**
100
+ * Seeds the sqlite_sequence table for auto-increment fields that have a start value.
101
+ * Only applies once per adapter instance (idempotent via INSERT OR IGNORE + flag).
102
+ */
103
+ private _seedIncrementStart;
94
104
  ensureView(): Promise<void>;
95
105
  getExistingColumns(): Promise<TExistingColumn[]>;
96
106
  syncColumns(diff: TColumnDiff): Promise<TSyncColumnResult>;
@@ -106,6 +116,33 @@ declare class SqliteAdapter extends BaseDbAdapter {
106
116
  }): string;
107
117
  getExistingColumnsForTable(tableName: string): Promise<TExistingColumn[]>;
108
118
  syncIndexes(): Promise<void>;
119
+ getSearchIndexes(): TSearchIndexInfo[];
120
+ search(text: string, query: DbQuery, indexName?: string): Promise<Array<Record<string, unknown>>>;
121
+ searchWithCount(text: string, query: DbQuery, indexName?: string): Promise<{
122
+ data: Array<Record<string, unknown>>;
123
+ count: number;
124
+ }>;
125
+ /** Builds FTS table name from index name: `<table>__fts__<indexName>`. */
126
+ private _ftsTableName;
127
+ /** Returns fulltext indexes from table metadata. */
128
+ private _getFulltextIndexes;
129
+ /** Resolves a fulltext index by name, or returns the first available. */
130
+ private _resolveFtsIndex;
131
+ /**
132
+ * Builds the shared FROM+JOIN+WHERE fragment for FTS5 queries.
133
+ * Both data and count queries reuse this to avoid duplicating index resolution and filter translation.
134
+ */
135
+ private _buildFtsBase;
136
+ /**
137
+ * Creates/drops FTS5 virtual tables and sync triggers to match desired fulltext indexes.
138
+ */
139
+ private _syncFtsIndexes;
140
+ /** Creates an FTS5 virtual table with sync triggers and rebuilds the index. */
141
+ private _createFtsTable;
142
+ /** Drops an FTS5 virtual table and its sync triggers. */
143
+ private _dropFtsTable;
144
+ /** Drops all FTS virtual tables and triggers for a content table. */
145
+ private _dropAllFtsTables;
109
146
  }
110
147
 
111
148
  /**
@@ -144,10 +181,6 @@ declare class BetterSqlite3Driver implements TSqliteDriver {
144
181
  close(): void;
145
182
  }
146
183
 
147
- interface TSqlFragment {
148
- sql: string;
149
- params: unknown[];
150
- }
151
184
  /**
152
185
  * Translates a uniqu filter expression into a parameterized SQL WHERE clause.
153
186
  *
@@ -159,4 +192,4 @@ declare function buildWhere(filter: FilterExpr$1): TSqlFragment;
159
192
  declare function createAdapter(connection: string, options?: Record<string, unknown>): DbSpace;
160
193
 
161
194
  export { BetterSqlite3Driver, SqliteAdapter, buildWhere, createAdapter };
162
- export type { TSqlFragment, TSqliteDriver, TSqliteRunResult };
195
+ export type { TSqliteDriver, TSqliteRunResult };