@rwillians/qx 0.1.17 → 0.1.19

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.
@@ -1,7 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineMigrations = void 0;
3
+ exports.defineMigrations = exports.create = void 0;
4
4
  const index_1 = require("./index");
5
+ // // // // // // // // // // // // // // // // // // // // // // // //
6
+ // CREATE STATEMENTS //
7
+ // // // // // // // // // // // // // // // // // // // // // // // //
8
+ /**
9
+ * @public Create statement builder.
10
+ * @since 0.1.0
11
+ * @version 1
12
+ */
13
+ exports.create = {
14
+ /**
15
+ * @public Prepares a create table statement.
16
+ * @since 0.1.0
17
+ * @version 1
18
+ */
19
+ table: (table, options = {}) => ({
20
+ /**
21
+ * @public Executes the create table statement onto the given
22
+ * database.
23
+ * @since 0.1.0
24
+ * @version 1
25
+ */
26
+ onto: async (db) => db.createTable({
27
+ ...options,
28
+ table: table.name,
29
+ columns: Object.values(table.columns),
30
+ }),
31
+ }),
32
+ };
33
+ // // // // // // // // // // // // // // // // // // // // // // // //
34
+ // MIGRATIONS MANAGEMENT //
35
+ // // // // // // // // // // // // // // // // // // // // // // // //
36
+ /**
37
+ * @private Defines the schema migrations table.
38
+ * @since 0.1.6
39
+ * @version 1
40
+ */
5
41
  const migrations = (0, index_1.table)('schema_migrations', t => ({
6
42
  id: t.string({ size: 36 }).primaryKey(),
7
43
  timestamp: t.datetime(),
@@ -11,9 +47,33 @@ const migrations = (0, index_1.table)('schema_migrations', t => ({
11
47
  * database.
12
48
  * @since 0.1.6
13
49
  * @version 2
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * // src/db/migrations.ts
54
+ * import { create, defineMigrations } from '@rwillians/qx/experimental-migrations';
55
+ * import { users } from './users';
56
+ * import { profiles } from './profiles';
57
+ *
58
+ * export const migrate = defineMigrations({
59
+ * '0001': async (db) => {
60
+ * await create.table(users).onto(db);
61
+ * },
62
+ * '0002': async (db) => {
63
+ * await create.table(profiles).onto(db);
64
+ * },
65
+ * });
66
+ *
67
+ * // src/index.ts
68
+ * import * as sqlite from '@rwillians/qx/bun-sqlite';
69
+ * import { migrate } from './db/migrations';
70
+ *
71
+ * const db = sqlite.connect('./db.sqlite');
72
+ * await migrate(db)
73
+ * ```
14
74
  */
15
75
  const defineMigrations = (migs) => async (db) => {
16
- await index_1.create.table(migrations, { ifNotExists: true }).onto(db);
76
+ await exports.create.table(migrations, { ifNotExists: true }).onto(db);
17
77
  const { mostRecentId } = await (0, index_1.from)(migrations.as('m'))
18
78
  .orderBy(({ m }) => [index_1.expr.desc(m.timestamp)])
19
79
  .select(({ m }) => ({ mostRecentId: m.id }))
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.t = exports.transaction = exports.is = exports.into = exports.from = exports.expr = exports.table = exports.create = void 0;
3
+ exports.t = exports.transaction = exports.is = exports.into = exports.from = exports.expr = exports.table = void 0;
4
4
  const std = require("./standard-schema");
5
5
  const u = require("./utils");
6
6
  // // // // // // // // // // // // // // // // // // // // // // // //
@@ -471,35 +471,6 @@ exports.is = is;
471
471
  const transaction = async (db, fn) => db.transaction(fn);
472
472
  exports.transaction = transaction;
473
473
  // // // // // // // // // // // // // // // // // // // // // // // //
474
- // CREATE STATEMENTS //
475
- // // // // // // // // // // // // // // // // // // // // // // // //
476
- /**
477
- * @public Create statement builder.
478
- * @since 0.1.0
479
- * @version 1
480
- */
481
- const create = {
482
- /**
483
- * @public Prepares a create table statement.
484
- * @since 0.1.0
485
- * @version 1
486
- */
487
- table: (table, options = {}) => ({
488
- /**
489
- * @public Executes the create table statement onto the given
490
- * database.
491
- * @since 0.1.0
492
- * @version 1
493
- */
494
- onto: async (db) => db.createTable({
495
- ...options,
496
- table: table.name,
497
- columns: Object.values(table.columns),
498
- }),
499
- }),
500
- };
501
- exports.create = create;
502
- // // // // // // // // // // // // // // // // // // // // // // // //
503
474
  // INSERT STATEMENT //
504
475
  // // // // // // // // // // // // // // // // // // // // // // // //
505
476
  /**
@@ -1,4 +1,40 @@
1
- import { create, expr, from, into, table, transaction } from './index';
1
+ import { expr, from, into, table, transaction, } from './index';
2
+ // // // // // // // // // // // // // // // // // // // // // // // //
3
+ // CREATE STATEMENTS //
4
+ // // // // // // // // // // // // // // // // // // // // // // // //
5
+ /**
6
+ * @public Create statement builder.
7
+ * @since 0.1.0
8
+ * @version 1
9
+ */
10
+ export const create = {
11
+ /**
12
+ * @public Prepares a create table statement.
13
+ * @since 0.1.0
14
+ * @version 1
15
+ */
16
+ table: (table, options = {}) => ({
17
+ /**
18
+ * @public Executes the create table statement onto the given
19
+ * database.
20
+ * @since 0.1.0
21
+ * @version 1
22
+ */
23
+ onto: async (db) => db.createTable({
24
+ ...options,
25
+ table: table.name,
26
+ columns: Object.values(table.columns),
27
+ }),
28
+ }),
29
+ };
30
+ // // // // // // // // // // // // // // // // // // // // // // // //
31
+ // MIGRATIONS MANAGEMENT //
32
+ // // // // // // // // // // // // // // // // // // // // // // // //
33
+ /**
34
+ * @private Defines the schema migrations table.
35
+ * @since 0.1.6
36
+ * @version 1
37
+ */
2
38
  const migrations = table('schema_migrations', t => ({
3
39
  id: t.string({ size: 36 }).primaryKey(),
4
40
  timestamp: t.datetime(),
@@ -8,6 +44,30 @@ const migrations = table('schema_migrations', t => ({
8
44
  * database.
9
45
  * @since 0.1.6
10
46
  * @version 2
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * // src/db/migrations.ts
51
+ * import { create, defineMigrations } from '@rwillians/qx/experimental-migrations';
52
+ * import { users } from './users';
53
+ * import { profiles } from './profiles';
54
+ *
55
+ * export const migrate = defineMigrations({
56
+ * '0001': async (db) => {
57
+ * await create.table(users).onto(db);
58
+ * },
59
+ * '0002': async (db) => {
60
+ * await create.table(profiles).onto(db);
61
+ * },
62
+ * });
63
+ *
64
+ * // src/index.ts
65
+ * import * as sqlite from '@rwillians/qx/bun-sqlite';
66
+ * import { migrate } from './db/migrations';
67
+ *
68
+ * const db = sqlite.connect('./db.sqlite');
69
+ * await migrate(db)
70
+ * ```
11
71
  */
12
72
  export const defineMigrations = (migs) => async (db) => {
13
73
  await create.table(migrations, { ifNotExists: true }).onto(db);
package/dist/esm/index.js CHANGED
@@ -463,34 +463,6 @@ const is = {
463
463
  */
464
464
  const transaction = async (db, fn) => db.transaction(fn);
465
465
  // // // // // // // // // // // // // // // // // // // // // // // //
466
- // CREATE STATEMENTS //
467
- // // // // // // // // // // // // // // // // // // // // // // // //
468
- /**
469
- * @public Create statement builder.
470
- * @since 0.1.0
471
- * @version 1
472
- */
473
- const create = {
474
- /**
475
- * @public Prepares a create table statement.
476
- * @since 0.1.0
477
- * @version 1
478
- */
479
- table: (table, options = {}) => ({
480
- /**
481
- * @public Executes the create table statement onto the given
482
- * database.
483
- * @since 0.1.0
484
- * @version 1
485
- */
486
- onto: async (db) => db.createTable({
487
- ...options,
488
- table: table.name,
489
- columns: Object.values(table.columns),
490
- }),
491
- }),
492
- };
493
- // // // // // // // // // // // // // // // // // // // // // // // //
494
466
  // INSERT STATEMENT //
495
467
  // // // // // // // // // // // // // // // // // // // // // // // //
496
468
  /**
@@ -717,4 +689,4 @@ const from = (table) => new QueryBuilder({
717
689
  // // // // // // // // // // // // // // // // // // // // // // // //
718
690
  // EXPORTS //
719
691
  // // // // // // // // // // // // // // // // // // // // // // // //
720
- export { create, defineTable as table, expr, from, into, is, transaction, types as t, };
692
+ export { defineTable as table, expr, from, into, is, transaction, types as t, };
@@ -1,4 +1,28 @@
1
- import { type IDatabase } from './index';
1
+ import { type IDatabase, type Table } from './index';
2
+ /**
3
+ * @public Create statement builder.
4
+ * @since 0.1.0
5
+ * @version 1
6
+ */
7
+ export declare const create: {
8
+ /**
9
+ * @public Prepares a create table statement.
10
+ * @since 0.1.0
11
+ * @version 1
12
+ */
13
+ table: <T extends Table, S extends {
14
+ ifNotExists?: true;
15
+ unlogged?: true;
16
+ }>(table: T, options?: S) => {
17
+ /**
18
+ * @public Executes the create table statement onto the given
19
+ * database.
20
+ * @since 0.1.0
21
+ * @version 1
22
+ */
23
+ onto: (db: IDatabase) => Promise<void>;
24
+ };
25
+ };
2
26
  /**
3
27
  * @private Defines the type for a migration function.
4
28
  * @since 0.1.6
@@ -10,6 +34,30 @@ type Migration = (db: IDatabase) => Promise<void>;
10
34
  * database.
11
35
  * @since 0.1.6
12
36
  * @version 2
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * // src/db/migrations.ts
41
+ * import { create, defineMigrations } from '@rwillians/qx/experimental-migrations';
42
+ * import { users } from './users';
43
+ * import { profiles } from './profiles';
44
+ *
45
+ * export const migrate = defineMigrations({
46
+ * '0001': async (db) => {
47
+ * await create.table(users).onto(db);
48
+ * },
49
+ * '0002': async (db) => {
50
+ * await create.table(profiles).onto(db);
51
+ * },
52
+ * });
53
+ *
54
+ * // src/index.ts
55
+ * import * as sqlite from '@rwillians/qx/bun-sqlite';
56
+ * import { migrate } from './db/migrations';
57
+ *
58
+ * const db = sqlite.connect('./db.sqlite');
59
+ * await migrate(db)
60
+ * ```
13
61
  */
14
62
  export declare const defineMigrations: (migs: Record<string, Migration>) => (db: IDatabase) => Promise<void>;
15
63
  export {};
@@ -1040,30 +1040,6 @@ interface IDatabase {
1040
1040
  * @version 1
1041
1041
  */
1042
1042
  declare const transaction: <T>(db: IDatabase, fn: () => Promise<T>) => Promise<T>;
1043
- /**
1044
- * @public Create statement builder.
1045
- * @since 0.1.0
1046
- * @version 1
1047
- */
1048
- declare const create: {
1049
- /**
1050
- * @public Prepares a create table statement.
1051
- * @since 0.1.0
1052
- * @version 1
1053
- */
1054
- table: <T extends Table, S extends {
1055
- ifNotExists?: true;
1056
- unlogged?: true;
1057
- }>(table: T, options?: S) => {
1058
- /**
1059
- * @public Executes the create table statement onto the given
1060
- * database.
1061
- * @since 0.1.0
1062
- * @version 1
1063
- */
1064
- onto: (db: IDatabase) => Promise<void>;
1065
- };
1066
- };
1067
1043
  /**
1068
1044
  * @public Insert statement builder.
1069
1045
  * @since 0.1.0
@@ -1248,4 +1224,4 @@ declare class QueryBuilder<T extends Record<string, Aliased<string, Table>>, S e
1248
1224
  * @version 1
1249
1225
  */
1250
1226
  declare const from: <S extends string, T extends Aliased<S, Table>>(table: T) => QueryBuilder<{ [K in T[typeof TABLE_ALIAS]]: T; }, T>;
1251
- export { type CodecsRegistry, type Column, type CreateTableStatement, type DDL, type Expr, type ExprAnd, type ExprBinaryOp, type ExprEq, type ExprGt, type ExprGte, type ExprIn, type ExprIs, type ExprIsNot, type ExprLike, type ExprLiteral, type ExprLt, type ExprLte, type ExprNe, type ExprNot, type ExprNotIn, type ExprNotLike, type ExprOr, type IDatabase, type ILogger, type Join, type InsertStatement, type OrderDirection, type Primitive, type PrimitiveToNativeTypeFactory, type SelectStatement, type Table, create, defineTable as table, expr, from, into, is, transaction, types as t, };
1227
+ export { type CodecsRegistry, type Column, type CreateTableStatement, type DDL, type Expr, type ExprAnd, type ExprBinaryOp, type ExprEq, type ExprGt, type ExprGte, type ExprIn, type ExprIs, type ExprIsNot, type ExprLike, type ExprLiteral, type ExprLt, type ExprLte, type ExprNe, type ExprNot, type ExprNotIn, type ExprNotLike, type ExprOr, type IDatabase, type ILogger, type Join, type InsertStatement, type OrderDirection, type Primitive, type PrimitiveToNativeTypeFactory, type SelectStatement, type Table, defineTable as table, expr, from, into, is, transaction, types as t, };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rwillians/qx",
3
3
  "description": "A zero-dependencies teeny tiny ORM for SQLite.",
4
- "version": "0.1.17",
4
+ "version": "0.1.19",
5
5
  "author": "Rafael Willians <me@rwillians.com>",
6
6
  "license": "MIT",
7
7
  "repository": {