Comparing version 3.3.2 to 3.4.0
@@ -38,2 +38,4 @@ "use strict"; | ||
static transformValue(data, type) { | ||
if (data === null) | ||
return null; | ||
if (type === "BLOB") | ||
@@ -40,0 +42,0 @@ return data; |
import { TypedEmitter } from "tiny-typed-emitter"; | ||
import sql from "better-sqlite3"; | ||
import { DatabaseEvents, DatabaseOptions, DataResolvable, SortOptions, SqliteQueryOptions, TableResolvable } from "../typings"; | ||
import { DatabaseEvents, DatabaseOptions, DataResolvable, SortOptions, SqliteChanges, SqliteQueryOptions, TableResolvable } from "../typings"; | ||
import { Table } from "./Table"; | ||
@@ -122,3 +122,4 @@ /** | ||
*/ | ||
set<K = undefined>(table: TableResolvable, data: K extends undefined ? DataResolvable : K, options?: SqliteQueryOptions): (import("../typings").SqliteChanges | undefined)[]; | ||
set<K = undefined>(table: TableResolvable, data: K extends undefined ? DataResolvable : K): (SqliteChanges | undefined)[]; | ||
set<K = undefined>(table: TableResolvable, data: K extends undefined ? DataResolvable : K, options?: SqliteQueryOptions): (SqliteChanges | undefined)[]; | ||
/** | ||
@@ -130,3 +131,4 @@ * Deletes rows from a database, if no options are given it will clean the entire table. | ||
*/ | ||
delete(table: TableResolvable, options?: SqliteQueryOptions): import("../typings").SqliteChanges; | ||
delete(table: TableResolvable, primaryKey: string): SqliteChanges; | ||
delete(table: TableResolvable, options?: SqliteQueryOptions): SqliteChanges; | ||
/** | ||
@@ -139,3 +141,3 @@ * Insert one or multiple rows into the database. | ||
*/ | ||
insert<K = undefined>(table: TableResolvable, data: K extends undefined ? DataResolvable[] | DataResolvable : K): import("../typings").SqliteChanges; | ||
insert<K = undefined>(table: TableResolvable, data: K extends undefined ? DataResolvable[] | DataResolvable : K): SqliteChanges; | ||
/** | ||
@@ -154,2 +156,3 @@ * Gets a single row from the database. | ||
*/ | ||
get<K = undefined>(table: TableResolvable, primaryKey: string): K extends undefined ? DataResolvable : K; | ||
get<K = undefined>(table: TableResolvable, options: SqliteQueryOptions): K extends undefined ? DataResolvable : K; | ||
@@ -156,0 +159,0 @@ /** |
@@ -165,20 +165,22 @@ "use strict"; | ||
} | ||
/** | ||
* Sets a row into the database (or updates existing one). | ||
* @param table The table to perform this action on. | ||
* @param data The data to set. | ||
* @param options Options for this query. | ||
* @returns Sqlite result for this setter. | ||
*/ | ||
set(table, data, options) { | ||
return this.resolveTable(table).set(data, options); | ||
if (options) { | ||
return this.resolveTable(table).set(data, options); | ||
} | ||
const primary = this.resolveTable(table).columns.find(c => c.primary); | ||
if (!primary || !primary.name) | ||
throw new DatabaseError_1.DatabaseError(`Could not find any primary key to perform query.`); | ||
//@ts-ignore | ||
if (!data[primary.name]) | ||
throw new DatabaseError_1.DatabaseError(`Data does not contain ${primary.name} property.`); | ||
//@ts-ignore | ||
return this.resolveTable(table).set(data, { where: { column: primary.name, equals: data[primary.name] } }); | ||
} | ||
/** | ||
* Deletes rows from a database, if no options are given it will clean the entire table. | ||
* @param table The table to delete rows from. | ||
* @param options Options for this query. | ||
* @returns Affected rows and changes from the sqlite table. | ||
*/ | ||
delete(table, options) { | ||
return this.resolveTable(table).delete(options); | ||
if (typeof options === 'object') | ||
return this.resolveTable(table).delete(options); | ||
const key = this.resolveTable(table).columns.find(c => c.primary); | ||
if (!key) | ||
throw new DatabaseError_1.DatabaseError(`Could not find any primary key to perform query.`); | ||
return this.resolveTable(table).delete({ where: { column: key.name, equals: options } }); | ||
} | ||
@@ -195,17 +197,9 @@ /** | ||
} | ||
/** | ||
* Gets a single row from the database. | ||
* @param table The table to get a row from. | ||
* @param options The options for this query. | ||
* @returns A row from the database, if it exists. | ||
* @example | ||
* db.get("mytable", { | ||
* where: { | ||
* column: "id", | ||
* equals: "12345" | ||
* } | ||
* }) | ||
*/ | ||
get(table, options) { | ||
return this.resolveTable(table).get(options); | ||
if (typeof options === 'object') | ||
this.resolveTable(table).get(options); | ||
const key = this.resolveTable(table).columns.find(c => c.primary); | ||
if (!key) | ||
throw new DatabaseError_1.DatabaseError(`Could not find any primary key to perform query.`); | ||
return this.resolveTable(table).get({ where: { column: key.name, equals: options } }); | ||
} | ||
@@ -212,0 +206,0 @@ /** |
@@ -207,3 +207,3 @@ import { Column } from "../structures/Column"; | ||
*/ | ||
default?: any | null; | ||
default?: unknown | null; | ||
/** | ||
@@ -210,0 +210,0 @@ * Whether this column can be nullable in the database. |
{ | ||
"name": "dbdts.db", | ||
"version": "3.3.2", | ||
"version": "3.4.0", | ||
"description": "Easy to use wrapper for sqlite databases, mainly designed for use with dbd.ts package.", | ||
@@ -5,0 +5,0 @@ "exports": { |
@@ -72,2 +72,7 @@ # dbdts.db | ||
const db = new APIDatabase({ | ||
port: 3444, | ||
password: "youshallnotpass" | ||
}) | ||
const table = db.createTable("mytable").addColumns([ | ||
@@ -84,8 +89,2 @@ new Column() | ||
const db = new APIDatabase({ | ||
port: 3444, | ||
password: "youshallnotpass" | ||
}) | ||
db.open(async () => { | ||
@@ -92,0 +91,0 @@ console.log(`Database ready!`) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120829
1937
128