sasat 0.19.18 → 0.19.20

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.
@@ -67,7 +67,7 @@ const makeDefaultValueMethod = (node) => {
67
67
  return tsg
68
68
  .method('getDefaultValueString', [], columns.length !== 0
69
69
  ? tsg.typeRef(node.name.name).pick(...columns.map(it => it.fieldName))
70
- : tsg.typeRef('Record<string, never>'), [body])
70
+ : tsg.typeRef(node.name.name).partial(), [body])
71
71
  .modifiers(tsg.methodModifiers().protected());
72
72
  };
73
73
  const makeFindMethods = (node) => {
package/lib/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export type { TypeFieldDefinition } from './generatorv2/codegen/ts/scripts/typeD
16
16
  export type { SasatMigration } from './migration/front/migration.js';
17
17
  export type { CommandResponse, QueryResponse, } from './db/connectors/dbClient.js';
18
18
  export { QExpr } from './runtime/dsl/factory.js';
19
+ export { QExpr as qe } from './runtime/dsl/factory.js';
19
20
  export { gqlResolveInfoToField } from './runtime/gqlResolveInfoToField.js';
20
21
  export { SasatDBDatasource, EntityResult, EntityType, ListQueryOption, QueryOptions, } from './runtime/sasatDBDatasource.js';
21
22
  export { getCurrentDateTimeString } from './util/dateUtil.js';
package/lib/index.js CHANGED
@@ -3,6 +3,7 @@ export { Queries } from './migration/makeQuery.js';
3
3
  export { Mutations } from './migration/makeMutaion.js';
4
4
  export { Conditions } from './migration/makeCondition.js';
5
5
  export { QExpr } from './runtime/dsl/factory.js';
6
+ export { QExpr as qe } from './runtime/dsl/factory.js';
6
7
  export { gqlResolveInfoToField } from './runtime/gqlResolveInfoToField.js';
7
8
  export { SasatDBDatasource, } from './runtime/sasatDBDatasource.js';
8
9
  export { getCurrentDateTimeString } from './util/dateUtil.js';
@@ -10,6 +10,7 @@ export class MigrationController {
10
10
  async migrate(options) {
11
11
  const fileNames = await compileMigrationFiles();
12
12
  const currentMigration = await getCurrentMigration();
13
+ Console.log('--current migration--: ' + currentMigration);
13
14
  let store = await createCurrentMigrationDataStore(currentMigration);
14
15
  const target = getMigrationTargets(fileNames, currentMigration);
15
16
  for (const tsFileName of target.files) {
@@ -0,0 +1,20 @@
1
+ import { DateColumnBuilder, DecimalColumnBuilder, FloatColumnBuilder, IntegerColumnBuilder, StringColumnBuilder, TextColumnBuilder, TimeStampColumnBuilder } from './columnBuilder.js';
2
+ export type CreateColumn = {
3
+ char: (length: number) => StringColumnBuilder;
4
+ varchar: (length: number) => StringColumnBuilder;
5
+ text: () => TextColumnBuilder;
6
+ tinyInt: (length?: number) => IntegerColumnBuilder;
7
+ smallInt: (length?: number) => IntegerColumnBuilder;
8
+ mediumInt: (length?: number) => IntegerColumnBuilder;
9
+ int: (length?: number) => IntegerColumnBuilder;
10
+ bigInt: (length?: number) => IntegerColumnBuilder;
11
+ float: (length?: number, scale?: number) => FloatColumnBuilder;
12
+ double: (length?: number, scale?: number) => FloatColumnBuilder;
13
+ decimal: (length?: number, scale?: number) => DecimalColumnBuilder;
14
+ year: () => DateColumnBuilder;
15
+ date: () => DateColumnBuilder;
16
+ time: () => DateColumnBuilder;
17
+ dateTime: () => TimeStampColumnBuilder;
18
+ timestamp: () => TimeStampColumnBuilder;
19
+ };
20
+ export declare const createColumn: (name: string) => CreateColumn;
@@ -0,0 +1,20 @@
1
+ import { DateColumnBuilder, DecimalColumnBuilder, FloatColumnBuilder, IntegerColumnBuilder, StringColumnBuilder, TextColumnBuilder, TimeStampColumnBuilder, } from './columnBuilder.js';
2
+ import { DBColumnTypes } from '../column/columnTypes.js';
3
+ export const createColumn = (name) => ({
4
+ char: (length) => new StringColumnBuilder(name, DBColumnTypes.char, length),
5
+ varchar: (length) => new StringColumnBuilder(name, DBColumnTypes.varchar, length),
6
+ text: () => new TextColumnBuilder(name, DBColumnTypes.text),
7
+ tinyInt: (length) => new IntegerColumnBuilder(name, DBColumnTypes.tinyInt, length),
8
+ smallInt: (length) => new IntegerColumnBuilder(name, DBColumnTypes.smallInt, length),
9
+ mediumInt: (length) => new IntegerColumnBuilder(name, DBColumnTypes.mediumInt, length),
10
+ int: (length) => new IntegerColumnBuilder(name, DBColumnTypes.int, length),
11
+ bigInt: (length) => new IntegerColumnBuilder(name, DBColumnTypes.bigInt, length),
12
+ float: (length, scale) => new FloatColumnBuilder(name, DBColumnTypes.float, length, scale),
13
+ double: (length, scale) => new FloatColumnBuilder(name, DBColumnTypes.double, length, scale),
14
+ decimal: (length, scale) => new DecimalColumnBuilder(name, DBColumnTypes.decimal, length, scale),
15
+ year: () => new DateColumnBuilder(name, DBColumnTypes.year),
16
+ date: () => new DateColumnBuilder(name, DBColumnTypes.date),
17
+ time: () => new DateColumnBuilder(name, DBColumnTypes.time),
18
+ dateTime: () => new TimeStampColumnBuilder(name, DBColumnTypes.dateTime),
19
+ timestamp: () => new TimeStampColumnBuilder(name, DBColumnTypes.timestamp),
20
+ });
@@ -28,11 +28,11 @@ export const getCurrentMigration = async () => {
28
28
  "direction enum('up', 'down') not null, migrated_at timestamp default current_timestamp)");
29
29
  const result = await client.rawQuery(`SELECT name, direction
30
30
  FROM ${migrationTable}
31
- ORDER BY migrated_at ASC LIMIT 1`);
31
+ ORDER BY id ASC`);
32
32
  if (!result.length)
33
33
  return;
34
34
  const runs = calcRunMigrationFileNames(result);
35
- if (runs.length)
35
+ if (runs.length === 0)
36
36
  return;
37
37
  runs.forEach((run, i) => {
38
38
  if (files[i] !== run)
@@ -41,6 +41,5 @@ Invalid migration order: Migration must be performed in the same order
41
41
  Found : ${files[i]}
42
42
  in migration history: ${run}`);
43
43
  });
44
- console.log(runs[runs.length - 1]);
45
44
  return runs[runs.length - 1];
46
45
  };
@@ -6,10 +6,13 @@ import { BaseColumn } from '../serializable/column.js';
6
6
  import { SerializedTable } from '../serialized/serializedStore.js';
7
7
  import { DBType } from '../column/columnTypes.js';
8
8
  import { DBIndex } from '../data/index.js';
9
+ import { CreateColumn } from '../creators/createColumn.js';
10
+ import { ColumnBuilder } from '../creators/columnBuilder.js';
9
11
  export interface MigrationTable extends Table {
10
12
  addIndex(...columns: string[]): MigrationTable;
11
13
  removeIndex(...columns: string[]): MigrationTable;
12
- addColumn(column: SerializedColumn): MigrationTable;
14
+ addColumn(name: string, create: (column: CreateColumn) => ColumnBuilder): MigrationTable;
15
+ _addColumn(column: SerializedColumn): MigrationTable;
13
16
  dropColumn(columnName: string): MigrationTable;
14
17
  addForeignKey(reference: Reference): MigrationTable;
15
18
  changeColumnType(columnName: string, type: DBType): MigrationTable;
@@ -32,7 +35,8 @@ export declare class TableMigrator implements MigrationTable {
32
35
  serialize(): SerializedTable;
33
36
  addIndex(...columns: string[]): MigrationTable;
34
37
  removeIndex(...columns: string[]): MigrationTable;
35
- addColumn(column: SerializedNormalColumn): MigrationTable;
38
+ _addColumn(column: SerializedNormalColumn): MigrationTable;
39
+ addColumn(name: string, create: (column: CreateColumn) => ColumnBuilder): MigrationTable;
36
40
  dropColumn(columnName: string): MigrationTable;
37
41
  enableGQL(): MigrationTable;
38
42
  setGQLOption(option: GQLOption): MigrationTable;
@@ -3,6 +3,7 @@ import { NormalColumn, } from '../serializable/column.js';
3
3
  import { SqlCreator } from '../../db/sql/sqlCreater.js';
4
4
  import { SqlString } from '../../runtime/sql/sqlString.js';
5
5
  import { DBIndex } from '../data/index.js';
6
+ import { createColumn } from '../creators/createColumn.js';
6
7
  export class TableMigrator {
7
8
  constructor(table, store) {
8
9
  this.table = table;
@@ -41,11 +42,15 @@ export class TableMigrator {
41
42
  this.store.addQuery(new DBIndex(this.tableName, columns).dropSql());
42
43
  return this;
43
44
  }
44
- addColumn(column) {
45
+ _addColumn(column) {
45
46
  this.table.addColumn(new NormalColumn(column, this.table));
46
47
  this.store.addQuery(SqlCreator.addColumn(this.tableName, column));
47
48
  return this;
48
49
  }
50
+ addColumn(name, create) {
51
+ const column = create(createColumn(name)).build();
52
+ return this._addColumn(column.data);
53
+ }
49
54
  dropColumn(columnName) {
50
55
  this.table.dropColumn(columnName);
51
56
  this.store.addQuery(SqlCreator.dropColumn(this.tableName, columnName));
@@ -1,7 +1,43 @@
1
1
  import { BetweenExpression, BooleanValueExpression, ComparisonExpression, Field, Fn, InExpression, IsNullExpression, Join, JoinType, Literal, ParenthesisExpression, Query, QueryTable, Sort, SortDirection, Value } from './query/query.js';
2
2
  import { ComparisonOperators } from '../../db/sql/expression/comparison.js';
3
+ type ValueType = string | boolean | number | null;
3
4
  export declare const QExpr: {
5
+ readonly field: (table: string, name: string, alias?: string) => Field;
6
+ readonly fn: (fnName: string, args: Value[]) => Fn;
7
+ readonly paren: (expression: BooleanValueExpression) => ParenthesisExpression;
8
+ readonly table: (name: string, joins: Join[], alias: string) => QueryTable;
9
+ readonly subQueryTable: (query: Query, joins: Join[], alias: string) => QueryTable;
10
+ readonly join: (table: QueryTable, conditions: BooleanValueExpression, type?: JoinType) => Join;
11
+ readonly value: (value: ValueType) => Literal;
12
+ readonly sort: (field: Field, direction: SortDirection) => Sort;
13
+ readonly order: (field: Field, direction: SortDirection) => Sort;
14
+ readonly simpleWhere: (tableNameOrAlias: string, where: {
15
+ [field: string]: ValueType | [ComparisonOperators, ValueType];
16
+ }, isOr?: boolean) => BooleanValueExpression;
17
+ readonly and: (...expr: Array<BooleanValueExpression | undefined | null>) => BooleanValueExpression;
18
+ readonly or: (...expr: Array<BooleanValueExpression | undefined | null>) => BooleanValueExpression;
19
+ readonly eq: (left: Value, right: Value) => ComparisonExpression;
20
+ readonly neq: (left: Value, right: Value) => ComparisonExpression;
21
+ readonly gt: (left: Value, right: Value) => ComparisonExpression;
22
+ readonly gte: (left: Value, right: Value) => ComparisonExpression;
23
+ readonly lt: (left: Value, right: Value) => ComparisonExpression;
24
+ readonly lte: (left: Value, right: Value) => ComparisonExpression;
25
+ readonly comparison: (left: Value, operator: ComparisonOperators, right: Value) => ComparisonExpression;
26
+ readonly contains: (left: Value, right: string) => BooleanValueExpression;
27
+ readonly notContains: (left: Value, right: string) => BooleanValueExpression;
28
+ readonly statsWiths: (left: Value, right: string) => BooleanValueExpression;
29
+ readonly notStatsWiths: (left: Value, right: string) => BooleanValueExpression;
30
+ readonly endsWiths: (left: Value, right: string) => BooleanValueExpression;
31
+ readonly notEndsWiths: (left: Value, right: string) => BooleanValueExpression;
32
+ readonly In: (left: Value, values: (string | number)[]) => InExpression;
33
+ readonly notIn: (left: Value, values: (string | number)[]) => InExpression;
34
+ readonly between: (left: Value, begin: Value, end: Value) => BetweenExpression;
35
+ readonly isNull: (expr: Value) => IsNullExpression;
36
+ readonly isNotNull: (expr: Value) => IsNullExpression;
4
37
  readonly conditions: {
38
+ simpleWhere: (tableNameOrAlias: string, where: {
39
+ [field: string]: ValueType | [ComparisonOperators, ValueType];
40
+ }, isOr?: boolean) => BooleanValueExpression;
5
41
  and: (...expr: Array<BooleanValueExpression | undefined | null>) => BooleanValueExpression;
6
42
  or: (...expr: Array<BooleanValueExpression | undefined | null>) => BooleanValueExpression;
7
43
  eq: (left: Value, right: Value) => ComparisonExpression;
@@ -23,13 +59,5 @@ export declare const QExpr: {
23
59
  isNull: (expr: Value) => IsNullExpression;
24
60
  isNotNull: (expr: Value) => IsNullExpression;
25
61
  };
26
- readonly field: (table: string, name: string, alias?: string) => Field;
27
- readonly fn: (fnName: string, args: Value[]) => Fn;
28
- readonly paren: (expression: BooleanValueExpression) => ParenthesisExpression;
29
- readonly table: (name: string, joins: Join[], alias: string) => QueryTable;
30
- readonly subQueryTable: (query: Query, joins: Join[], alias: string) => QueryTable;
31
- readonly join: (table: QueryTable, conditions: BooleanValueExpression, type?: JoinType) => Join;
32
- readonly value: (value: string | boolean | number | null) => Literal;
33
- readonly sort: (field: Field, direction: SortDirection) => Sort;
34
- readonly order: (field: Field, direction: SortDirection) => Sort;
35
62
  };
63
+ export {};
@@ -61,7 +61,17 @@ const isNull = (isNot) => (expr) => ({
61
61
  expr,
62
62
  isNot,
63
63
  });
64
+ const simpleWhere = (tableNameOrAlias, where, isOr = false) => {
65
+ const compound = isOr ? or : and;
66
+ return compound(...Object.entries(where).map(([f, value]) => {
67
+ const fe = field(tableNameOrAlias, f);
68
+ if (Array.isArray(value))
69
+ return comparison(value[0])(fe, literal(value[1]));
70
+ return conditions.eq(fe, literal(value));
71
+ }));
72
+ };
64
73
  const conditions = {
74
+ simpleWhere,
65
75
  and,
66
76
  or,
67
77
  eq: comparison('='),
@@ -114,6 +124,7 @@ const sort = (field, direction) => ({
114
124
  });
115
125
  export const QExpr = {
116
126
  conditions,
127
+ ...conditions,
117
128
  field,
118
129
  fn,
119
130
  paren,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sasat",
3
- "version": "0.19.18",
3
+ "version": "0.19.20",
4
4
  "repository": "https://github.com/nin138/sasat.git",
5
5
  "author": "nin138 <ninian138@gmail.com>",
6
6
  "license": "MIT",