driftsql 0.0.1
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/README.md +83 -0
- package/dist/client.d.ts +68 -0
- package/dist/functions/create.d.ts +6 -0
- package/dist/functions/delete.d.ts +5 -0
- package/dist/functions/deleteMany.d.ts +5 -0
- package/dist/functions/findFirst.d.ts +5 -0
- package/dist/functions/findMany.d.ts +7 -0
- package/dist/functions/findOne.d.ts +5 -0
- package/dist/functions/update.d.ts +6 -0
- package/dist/lib/clean.d.ts +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +3 -0
- package/dist/main.js.map +91 -0
- package/package.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Drift SQL
|
|
2
|
+
|
|
3
|
+
Driftsql is a SQL client for libsql and sqlitecloud to provide a simple & fast way to query your data.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add driftsql # or npm install driftsql
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
For now docs are is very basic, but I will add more soon.
|
|
14
|
+
|
|
15
|
+
Setup client:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { DriftClient } from 'driftsql';
|
|
19
|
+
|
|
20
|
+
const db = new DriftClient({
|
|
21
|
+
driver: 'libsql', // More drivers coming soon
|
|
22
|
+
auth: {
|
|
23
|
+
url: 'libsql://',
|
|
24
|
+
token: 'your-token',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Type-safety
|
|
30
|
+
|
|
31
|
+
You can add an type to your database client to get type-safety and autocompletion. Example:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { DriftClient } from 'driftsql';
|
|
35
|
+
|
|
36
|
+
interface Database {
|
|
37
|
+
users: {
|
|
38
|
+
id: number;
|
|
39
|
+
name: string;
|
|
40
|
+
email: string;
|
|
41
|
+
password: string;
|
|
42
|
+
created_at: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const db = new DriftClient<Database>({
|
|
47
|
+
driver: 'libsql',
|
|
48
|
+
auth: {
|
|
49
|
+
url: 'libsql://',
|
|
50
|
+
token: 'your-token',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Now you can query your database with a developer-friendly api inspired by Prisma.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// Find all users
|
|
59
|
+
// in every find method, you can pass a where object to filter the results
|
|
60
|
+
const users = await db.findMany({ table: 'users' });
|
|
61
|
+
|
|
62
|
+
// Find a single user
|
|
63
|
+
const user = await db.findOne({ table: 'users', id: 1 });
|
|
64
|
+
|
|
65
|
+
// Find the first user
|
|
66
|
+
const user = await db.findFirst({ table: 'users', where: { id: 1 } });
|
|
67
|
+
|
|
68
|
+
// Create a new user
|
|
69
|
+
const user = await db.create({ table: 'users', data: { name: 'John Doe', email: 'john@doe.com', password: 'password' } });
|
|
70
|
+
|
|
71
|
+
// Update a user
|
|
72
|
+
const user = await db.update({ table: 'users', where: { id: 1 }, data: { name: 'John Doe' } });
|
|
73
|
+
|
|
74
|
+
// Delete a user
|
|
75
|
+
const user = await db.delete({ table: 'users', where: { id: 1 } });
|
|
76
|
+
|
|
77
|
+
// Delete many users
|
|
78
|
+
const users = await db.deleteMany({ table: 'users', where: { id: [1, 2, 3] } });
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type ResultSet } from '@libsql/client';
|
|
3
|
+
declare const optionsSchema: z.ZodObject<{
|
|
4
|
+
driver: z.ZodEnum<["libsql"]>;
|
|
5
|
+
auth: z.ZodObject<{
|
|
6
|
+
url: z.ZodString;
|
|
7
|
+
token: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
url: string;
|
|
10
|
+
token?: string | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
url: string;
|
|
13
|
+
token?: string | undefined;
|
|
14
|
+
}>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
driver: "libsql";
|
|
17
|
+
auth: {
|
|
18
|
+
url: string;
|
|
19
|
+
token?: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
}, {
|
|
22
|
+
driver: "libsql";
|
|
23
|
+
auth: {
|
|
24
|
+
url: string;
|
|
25
|
+
token?: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
type Options = z.infer<typeof optionsSchema>;
|
|
29
|
+
export declare class DriftClient<T extends Record<string, any>> {
|
|
30
|
+
private url;
|
|
31
|
+
private token?;
|
|
32
|
+
private driver;
|
|
33
|
+
private libsqlClient?;
|
|
34
|
+
constructor(options: Options);
|
|
35
|
+
findMany<K extends keyof T>({ table, where, limit }: {
|
|
36
|
+
table: K;
|
|
37
|
+
where?: Partial<T[K]>;
|
|
38
|
+
limit?: number;
|
|
39
|
+
}): Promise<T[K][] | undefined>;
|
|
40
|
+
findOne<K extends keyof T>({ table, id }: {
|
|
41
|
+
table: K;
|
|
42
|
+
id: any;
|
|
43
|
+
}): Promise<T[K] | undefined>;
|
|
44
|
+
findFirst<K extends keyof T>({ table, where }: {
|
|
45
|
+
table: K;
|
|
46
|
+
where: Partial<T[K]>;
|
|
47
|
+
}): Promise<T[K] | undefined>;
|
|
48
|
+
create<K extends keyof T>({ table, data }: {
|
|
49
|
+
table: K;
|
|
50
|
+
data: Partial<T[K]>;
|
|
51
|
+
}): Promise<T[K] | undefined>;
|
|
52
|
+
update<K extends keyof T>({ table, where, data }: {
|
|
53
|
+
table: K;
|
|
54
|
+
where: Partial<T[K]>;
|
|
55
|
+
data: Partial<T[K]>;
|
|
56
|
+
}): Promise<T[K] | undefined>;
|
|
57
|
+
delete<K extends keyof T>({ table, where }: {
|
|
58
|
+
table: K;
|
|
59
|
+
where: Partial<T[K]>;
|
|
60
|
+
}): Promise<T[K] | undefined>;
|
|
61
|
+
deleteMany<K extends keyof T>({ table, where }: {
|
|
62
|
+
table: K;
|
|
63
|
+
where: Partial<T[K]>;
|
|
64
|
+
}): Promise<T[K] | undefined>;
|
|
65
|
+
sql(strings: TemplateStringsArray, ...values: any[]): Promise<ResultSet | undefined>;
|
|
66
|
+
private sanitizeValue;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const cleanSqlRows: <T extends Record<string, any>>(rows: T[]) => Partial<T>[];
|
package/dist/main.d.ts
ADDED