@stacksjs/database 0.75.599 → 0.75.602

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.
@@ -2,6 +2,19 @@ import type { QueryBuilderDialect } from './dialect';
2
2
  export declare function tableExistsSql(dialect: QueryBuilderDialect): string;
3
3
  /** `runner` and `dialect` default to the configured `db` and its dialect. */
4
4
  export declare function tableExists(table: string, runner?: TableCatalogRunner, dialect?: QueryBuilderDialect): Promise<boolean>;
5
+ /**
6
+ * Whether a table has a column, asked of the same catalog. False when the
7
+ * table itself is absent.
8
+ *
9
+ * For a table name the framework and an application can both claim. `sessions`
10
+ * is the legacy auth session store, and it is also what an analytics product
11
+ * calls its visitor sessions: the column a query is about to filter on says
12
+ * which one this database holds, and asking first means no statement fails
13
+ * inside the caller's transaction to find out.
14
+ */
15
+ export declare function tableHasColumnSql(dialect: QueryBuilderDialect): string;
16
+ /** `runner` and `dialect` default to the configured `db` and its dialect. */
17
+ export declare function tableHasColumn(table: string, column: string, runner?: TableCatalogRunner, dialect?: QueryBuilderDialect): Promise<boolean>;
5
18
  /**
6
19
  * Whether a table exists, asked of the database's own catalog.
7
20
  *
@@ -1 +1 @@
1
- import{sqlHelpers}from"./sql-helpers";import{db,getDatabaseDialect}from"./utils";export function tableExistsSql(dialect){const param=sqlHelpers(dialect).param(1);if(dialect==="postgres")return`SELECT 1 AS present WHERE to_regclass(quote_ident(${param})) IS NOT NULL`;if(dialect==="sqlite")return`SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = ${param}`;return`SELECT 1 AS present FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ${param}`}export async function tableExists(table,runner=db,dialect=getDatabaseDialect()){const rows=await runner.unsafe(tableExistsSql(dialect),[table]).execute();return Array.isArray(rows)&&rows.length>0}
1
+ import{sqlHelpers}from"./sql-helpers";import{db,getDatabaseDialect}from"./utils";export function tableExistsSql(dialect){const param=sqlHelpers(dialect).param(1);if(dialect==="postgres")return`SELECT 1 AS present WHERE to_regclass(quote_ident(${param})) IS NOT NULL`;if(dialect==="sqlite")return`SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = ${param}`;return`SELECT 1 AS present FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ${param}`}export async function tableExists(table,runner=db,dialect=getDatabaseDialect()){const rows=await runner.unsafe(tableExistsSql(dialect),[table]).execute();return Array.isArray(rows)&&rows.length>0}export function tableHasColumnSql(dialect){const helpers=sqlHelpers(dialect);const table=helpers.param(1);const column=helpers.param(2);if(dialect==="postgres")return`SELECT 1 AS present FROM pg_attribute WHERE attrelid = to_regclass(quote_ident(${table})) AND attname = ${column} AND attnum > 0 AND NOT attisdropped`;if(dialect==="sqlite")return`SELECT 1 AS present FROM pragma_table_info(${table}) WHERE name = ${column}`;return`SELECT 1 AS present FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ${table} AND COLUMN_NAME = ${column}`}export async function tableHasColumn(table,column,runner=db,dialect=getDatabaseDialect()){const rows=await runner.unsafe(tableHasColumnSql(dialect),[table,column]).execute();return Array.isArray(rows)&&rows.length>0}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/database",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.599",
5
+ "version": "0.75.602",
6
6
  "description": "The Stacks database integration.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -66,26 +66,26 @@
66
66
  "prepublishOnly": "bun run build"
67
67
  },
68
68
  "dependencies": {
69
- "@stacksjs/config": "0.75.599",
70
- "@stacksjs/env": "0.75.599",
71
- "@stacksjs/error-handling": "0.75.599",
72
- "@stacksjs/faker": "0.75.599",
73
- "@stacksjs/features": "0.75.599",
74
- "@stacksjs/logging": "0.75.599",
75
- "@stacksjs/model-meta": "0.75.599",
76
- "@stacksjs/path": "0.75.599",
77
- "@stacksjs/query-builder": "0.75.599",
78
- "@stacksjs/security": "0.75.599",
79
- "@stacksjs/storage": "0.75.599",
80
- "@stacksjs/strings": "0.75.599",
69
+ "@stacksjs/config": "0.75.602",
70
+ "@stacksjs/env": "0.75.602",
71
+ "@stacksjs/error-handling": "0.75.602",
72
+ "@stacksjs/faker": "0.75.602",
73
+ "@stacksjs/features": "0.75.602",
74
+ "@stacksjs/logging": "0.75.602",
75
+ "@stacksjs/model-meta": "0.75.602",
76
+ "@stacksjs/path": "0.75.602",
77
+ "@stacksjs/query-builder": "0.75.602",
78
+ "@stacksjs/security": "0.75.602",
79
+ "@stacksjs/storage": "0.75.602",
80
+ "@stacksjs/strings": "0.75.602",
81
81
  "@stacksjs/ts-validation": "^0.5.7",
82
82
  "bun-query-builder": "^0.6.0",
83
83
  "dynamodb-tooling": "^0.3.6"
84
84
  },
85
85
  "devDependencies": {
86
- "@stacksjs/cli": "0.75.599",
87
- "@stacksjs/router": "0.75.599",
88
- "@stacksjs/utils": "0.75.599",
86
+ "@stacksjs/cli": "0.75.602",
87
+ "@stacksjs/router": "0.75.602",
88
+ "@stacksjs/utils": "0.75.602",
89
89
  "better-dx": "^0.2.39"
90
90
  }
91
91
  }