@tfadev/easy-sqlite
Advanced tools
Comparing version 0.1.1 to 1.0.0
@@ -100,2 +100,4 @@ "use strict"; | ||
for (const value of values) { | ||
if (typeof value === 'string' && (value === 'boolean-true' || 'boolean-false')) | ||
throw new Error('The method is not allowed.'); | ||
if (typeof value === 'boolean') { | ||
@@ -102,0 +104,0 @@ newValues.push(`${value ? 'boolean-true' : 'boolean-false'}`); |
{ | ||
"name": "@tfadev/easy-sqlite", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "SQlite3 database but simplified with easy methods and TypeScript support!", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -29,6 +29,6 @@ <h1 align="center"> @tfadev/easy-sqlite</h1> | ||
const db = new SQLiteDatabase('path/to/your/sql/file.db'); | ||
const db = new SQLiteDatabase('path/to/your/file.db'); | ||
``` | ||
Here are the available methods to use. | ||
Here are the available methods to use with `SQLiteDatabase` class. | ||
@@ -41,27 +41,22 @@ > **Note** | ||
await db.create({ | ||
{ | ||
name: 'users', | ||
overwrite: true, // IF EXISTS | ||
keys: { | ||
id: ['INTEGER', { | ||
primary: true, // PRIMARY KEY | ||
autoincrement: true // AUTOINCREMENT | ||
}], | ||
username: ['TEXT'], | ||
age: ['INTEGER'], | ||
alive: ['BOOLEAN', { | ||
name: 'users', | ||
overwrite: true, // IF EXISTS | ||
keys: { | ||
id: ['INTEGER', { | ||
primary: true, // PRIMARY KEY | ||
autoincrement: true // AUTOINCREMENT | ||
}], | ||
username: ['TEXT'], | ||
age: ['INTEGER'], | ||
alive: ['BOOLEAN', { | ||
nullable: true | ||
}], | ||
languages: ['ARRAY'] | ||
} | ||
}], | ||
languages: ['ARRAY'] | ||
} | ||
}); | ||
// Deletes a table: | ||
await db.drop('users', ...); | ||
// Insert a new row in a table: | ||
await db.insert('users', { | ||
username: 'T.F.A', | ||
age: 17, | ||
username: 'John', | ||
age: 35, | ||
alive: true, | ||
@@ -74,15 +69,21 @@ languages: ['Python', 'Typescript', 'C++'] | ||
await db.select('users', { username: 'T.F.A' }); // → [{ ... }] | ||
await db.select('users', { age: 17 }); // → [{ ... }] | ||
await db.select('users', { username: 'T.F.A', age: 19 }); // → [] | ||
await db.select('users', { username: 'John' }); // → [{ ... }] | ||
await db.select('users', { age: 35 }); // → [{ ... }] | ||
await db.select('users', { username: 'John', age: 40 }); // → [] | ||
// Ensure if a table exist or not: | ||
// Ensure if a table exist or not, or by using filter: | ||
await db.ensure('users'); // → true | ||
await db.ensure('users', { username: 'T.F.A' }); // → true | ||
await db.ensure('users', { age: 17 }); // → true | ||
await db.ensure('users', { username: 'T.F.A', age: 19 }); // → false | ||
await db.ensure('users', { username: 'John' }); // → true | ||
await db.ensure('users', { age: 35 }); // → true | ||
await db.ensure('users', { username: 'John', age: 40 });// → false | ||
// Deletes a row from a table: | ||
await db.delete('users', { username: 'T.F.A' }); | ||
await db.delete('users', { username: 'John' }); | ||
// Deletes a table: | ||
await db.drop('users'); | ||
// Close the database: | ||
await db.close(); | ||
``` | ||
@@ -92,6 +93,6 @@ | ||
The class has a type parameter, it serves for the typings of each method, here is an example: | ||
The class has a type parameter with type of array, you can include many schemas as you want, just make sure the types are correct and equal to created tables. | ||
```ts | ||
type Schema = { | ||
type UsersSchema = { | ||
name: 'users', | ||
@@ -101,3 +102,3 @@ keys: { | ||
age: number, | ||
alive?: boolean, | ||
alive?: boolean, // ← Nullable | ||
languages: string[] | ||
@@ -107,3 +108,3 @@ } | ||
const db = new SQLiteDatabase<Schema>(...); | ||
new SQLiteDatabase<[UsersSchema, ...]>(...); | ||
``` | ||
@@ -110,0 +111,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
58887
340
1
107