@mdsrs/postgres-drizzle 0.0.0
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 +29 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +206 -0
- package/dist/schema.d.ts +1379 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +43 -0
- package/migrations/0000_initial.sql +42 -0
- package/package.json +38 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBnB,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBtB,CAAC;AAEF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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E7D,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC;AACtC,MAAM,MAAM,eAAe,GAAG,aAAa,CAAC;AAC5C,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC;AAC1C,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAC"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { bigserial, boolean, date, doublePrecision, foreignKey, integer, pgTable, text, timestamp } from 'drizzle-orm/pg-core';
|
|
2
|
+
export const srsCards = pgTable('srs_cards', {
|
|
3
|
+
cardHash: text('card_hash').primaryKey(),
|
|
4
|
+
deckName: text('deck_name').notNull(),
|
|
5
|
+
filePath: text('file_path').notNull(),
|
|
6
|
+
familyHash: text('family_hash'),
|
|
7
|
+
frontMarkdown: text('front_markdown').notNull(),
|
|
8
|
+
backMarkdown: text('back_markdown').notNull(),
|
|
9
|
+
cardType: text('card_type').notNull(),
|
|
10
|
+
active: boolean('active').notNull().default(true),
|
|
11
|
+
addedAt: timestamp('added_at', { withTimezone: true }).notNull().defaultNow(),
|
|
12
|
+
lastSeenAt: timestamp('last_seen_at', { withTimezone: true }).notNull().defaultNow(),
|
|
13
|
+
lastReviewedAt: timestamp('last_reviewed_at', { withTimezone: true }),
|
|
14
|
+
stability: doublePrecision('stability'),
|
|
15
|
+
difficulty: doublePrecision('difficulty'),
|
|
16
|
+
intervalRaw: doublePrecision('interval_raw'),
|
|
17
|
+
intervalDays: integer('interval_days'),
|
|
18
|
+
dueDate: date('due_date'),
|
|
19
|
+
reviewCount: integer('review_count').notNull().default(0)
|
|
20
|
+
});
|
|
21
|
+
export const srsReviews = pgTable('srs_reviews', {
|
|
22
|
+
reviewId: bigserial('review_id', { mode: 'number' }).primaryKey(),
|
|
23
|
+
reviewCardHash: text('review_card_hash').notNull(),
|
|
24
|
+
reviewedAt: timestamp('reviewed_at', { withTimezone: true }).notNull(),
|
|
25
|
+
grade: text('grade').notNull(),
|
|
26
|
+
stability: doublePrecision('stability').notNull(),
|
|
27
|
+
difficulty: doublePrecision('difficulty').notNull(),
|
|
28
|
+
intervalRaw: doublePrecision('interval_raw').notNull(),
|
|
29
|
+
intervalDays: integer('interval_days').notNull(),
|
|
30
|
+
dueDate: date('due_date').notNull()
|
|
31
|
+
}, (table) => [
|
|
32
|
+
foreignKey({
|
|
33
|
+
columns: [table.reviewCardHash],
|
|
34
|
+
foreignColumns: [srsCards.cardHash],
|
|
35
|
+
name: 'srs_reviews_review_card_hash_srs_cards_card_hash_fk'
|
|
36
|
+
}).onDelete('cascade')
|
|
37
|
+
]);
|
|
38
|
+
export const schema = {
|
|
39
|
+
srsCards,
|
|
40
|
+
srsReviews
|
|
41
|
+
};
|
|
42
|
+
export const mdsrsCards = srsCards;
|
|
43
|
+
export const mdsrsReviews = srsReviews;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS "srs_cards" (
|
|
2
|
+
"card_hash" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"deck_name" text NOT NULL,
|
|
4
|
+
"file_path" text NOT NULL,
|
|
5
|
+
"family_hash" text,
|
|
6
|
+
"front_markdown" text NOT NULL,
|
|
7
|
+
"back_markdown" text NOT NULL,
|
|
8
|
+
"card_type" text NOT NULL,
|
|
9
|
+
"active" boolean DEFAULT true NOT NULL,
|
|
10
|
+
"added_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
11
|
+
"last_seen_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
12
|
+
"last_reviewed_at" timestamp with time zone,
|
|
13
|
+
"stability" double precision,
|
|
14
|
+
"difficulty" double precision,
|
|
15
|
+
"interval_raw" double precision,
|
|
16
|
+
"interval_days" integer,
|
|
17
|
+
"due_date" date,
|
|
18
|
+
"review_count" integer DEFAULT 0 NOT NULL
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
CREATE TABLE IF NOT EXISTS "srs_reviews" (
|
|
22
|
+
"review_id" bigserial PRIMARY KEY NOT NULL,
|
|
23
|
+
"review_card_hash" text NOT NULL,
|
|
24
|
+
"reviewed_at" timestamp with time zone NOT NULL,
|
|
25
|
+
"grade" text NOT NULL,
|
|
26
|
+
"stability" double precision NOT NULL,
|
|
27
|
+
"difficulty" double precision NOT NULL,
|
|
28
|
+
"interval_raw" double precision NOT NULL,
|
|
29
|
+
"interval_days" integer NOT NULL,
|
|
30
|
+
"due_date" date NOT NULL,
|
|
31
|
+
CONSTRAINT "srs_reviews_review_card_hash_srs_cards_card_hash_fk"
|
|
32
|
+
FOREIGN KEY ("review_card_hash")
|
|
33
|
+
REFERENCES "srs_cards"("card_hash")
|
|
34
|
+
ON DELETE cascade
|
|
35
|
+
ON UPDATE no action
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
CREATE INDEX IF NOT EXISTS "srs_cards_active_due_idx"
|
|
39
|
+
ON "srs_cards" ("active", "due_date");
|
|
40
|
+
|
|
41
|
+
CREATE INDEX IF NOT EXISTS "srs_reviews_card_hash_idx"
|
|
42
|
+
ON "srs_reviews" ("review_card_hash");
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdsrs/postgres-drizzle",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./schema": {
|
|
12
|
+
"types": "./dist/schema.d.ts",
|
|
13
|
+
"default": "./dist/schema.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"migrations"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"drizzle-orm": "^0.45.2",
|
|
22
|
+
"@mdsrs/core": "0.0.0",
|
|
23
|
+
"@mdsrs/store": "0.0.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^24.0.0",
|
|
27
|
+
"@types/pg": "^8.20.0",
|
|
28
|
+
"pg": "^8.21.0",
|
|
29
|
+
"typescript": "^6.0.3",
|
|
30
|
+
"vitest": "^4.0.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -p tsconfig.json",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:integration": "vitest run src/postgres.integration.test.ts",
|
|
36
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
37
|
+
}
|
|
38
|
+
}
|