🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

@effect/sql-sqlite-react-native

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effect/sql-sqlite-react-native - npm Package Compare versions

Comparing version

to
0.0.0-snapshot-e1ebaaa379fd8da009fc70115350394e6295b9d4

@@ -11,2 +11,3 @@ "use strict";

var Sqlite = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@op-engineering/op-sqlite"));
var Otel = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@opentelemetry/semantic-conventions"));
var Config = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Config"));

@@ -19,3 +20,5 @@ var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Context"));

var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
var Queue = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Queue"));
var Scope = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Scope"));
var Stream = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Stream"));
function _getRequireWildcardCache(e) {

@@ -76,2 +79,11 @@ if ("function" != typeof WeakMap) return null;

const make = options => Effect.gen(function* (_) {
const clientOptions = {
name: options.filename
};
if (options.location) {
clientOptions.location = options.location;
}
if (options.encryptionKey) {
clientOptions.encryptionKey = options.encryptionKey;
}
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);

@@ -83,7 +95,3 @@ const transformRows = Statement.defaultTransforms(options.transformResultNames).array;

const makeConnection = Effect.gen(function* (_) {
const db = Sqlite.open({
name: options.filename,
location: options.location,
encryptionKey: options.encryptionKey
});
const db = Sqlite.open(clientOptions);
yield* _(Effect.addFinalizer(() => Effect.sync(() => db.close())));

@@ -124,2 +132,16 @@ const run = (sql, params = []) => Effect.withFiberRuntime(fiber => {

return Effect.dieMessage("executeStream not implemented");
},
reactive(statement, tables) {
const [query, params] = statement.compile();
return Queue.sliding(1).pipe(Effect.tap(queue => this.execute(query, params).pipe(Effect.flatMap(rows => queue.offer(rows)))), Effect.tap(queue => Effect.acquireRelease(Effect.try({
try: () => db.reactiveExecute({
query,
arguments: params,
tables: tables,
callback(data) {
queue.unsafeOffer(data.rows);
}
}),
catch: handleError
}), cancel => Effect.sync(cancel))), Effect.map(Stream.fromQueue), Stream.unwrapScoped);
}

@@ -136,6 +158,9 @@ });

transactionAcquirer,
spanAttributes: [["db.system", "sqlite"]]
spanAttributes: [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), [Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]]
}), {
[TypeId]: TypeId,
config: options
config: options,
reactive(statement, tables) {
return Stream.unwrap(Effect.map(acquirer, connection => connection.reactive(statement, tables)));
}
});

@@ -142,0 +167,0 @@ });

@@ -5,2 +5,4 @@ /**

import * as Client from "@effect/sql/Client";
import { SqlError } from "@effect/sql/Error";
import * as Statement from "@effect/sql/Statement";
import * as Config from "effect/Config";

@@ -13,2 +15,3 @@ import type { ConfigError } from "effect/ConfigError";

import * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";
/**

@@ -31,2 +34,3 @@ * @category type ids

readonly config: SqliteClientConfig;
readonly reactive: <A>(statement: Statement.Statement<A>, tables: ReadonlyArray<string>) => Stream.Stream<ReadonlyArray<A>, SqlError>;
/** Not supported in sqlite */

@@ -48,2 +52,3 @@ readonly updateValues: never;

readonly encryptionKey?: string | undefined;
readonly spanAttributes?: Record<string, unknown> | undefined;
readonly transformResultNames?: ((str: string) => string) | undefined;

@@ -50,0 +55,0 @@ readonly transformQueryNames?: ((str: string) => string) | undefined;

@@ -8,2 +8,3 @@ /**

import * as Sqlite from "@op-engineering/op-sqlite";
import * as Otel from "@opentelemetry/semantic-conventions";
import * as Config from "effect/Config";

@@ -16,3 +17,5 @@ import * as Context from "effect/Context";

import * as Layer from "effect/Layer";
import * as Queue from "effect/Queue";
import * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";
/**

@@ -43,2 +46,11 @@ * @category type ids

export const make = options => Effect.gen(function* (_) {
const clientOptions = {
name: options.filename
};
if (options.location) {
clientOptions.location = options.location;
}
if (options.encryptionKey) {
clientOptions.encryptionKey = options.encryptionKey;
}
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);

@@ -50,7 +62,3 @@ const transformRows = Statement.defaultTransforms(options.transformResultNames).array;

const makeConnection = Effect.gen(function* (_) {
const db = Sqlite.open({
name: options.filename,
location: options.location,
encryptionKey: options.encryptionKey
});
const db = Sqlite.open(clientOptions);
yield* _(Effect.addFinalizer(() => Effect.sync(() => db.close())));

@@ -91,2 +99,16 @@ const run = (sql, params = []) => Effect.withFiberRuntime(fiber => {

return Effect.dieMessage("executeStream not implemented");
},
reactive(statement, tables) {
const [query, params] = statement.compile();
return Queue.sliding(1).pipe(Effect.tap(queue => this.execute(query, params).pipe(Effect.flatMap(rows => queue.offer(rows)))), Effect.tap(queue => Effect.acquireRelease(Effect.try({
try: () => db.reactiveExecute({
query,
arguments: params,
tables: tables,
callback(data) {
queue.unsafeOffer(data.rows);
}
}),
catch: handleError
}), cancel => Effect.sync(cancel))), Effect.map(Stream.fromQueue), Stream.unwrapScoped);
}

@@ -103,6 +125,9 @@ });

transactionAcquirer,
spanAttributes: [["db.system", "sqlite"]]
spanAttributes: [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), [Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]]
}), {
[TypeId]: TypeId,
config: options
config: options,
reactive(statement, tables) {
return Stream.unwrap(Effect.map(acquirer, connection => connection.reactive(statement, tables)));
}
});

@@ -109,0 +134,0 @@ });

{
"name": "@effect/sql-sqlite-react-native",
"version": "0.0.0-snapshot-b4323ccacbf56b5c574bb69e7775d11cb8d2178a",
"version": "0.0.0-snapshot-e1ebaaa379fd8da009fc70115350394e6295b9d4",
"description": "A SQLite toolkit for Effect",

@@ -13,7 +13,8 @@ "license": "MIT",

"dependencies": {
"@op-engineering/op-sqlite": "5.0.5"
"@opentelemetry/semantic-conventions": "^1.24.1"
},
"peerDependencies": {
"@effect/sql": "^0.0.0-snapshot-b4323ccacbf56b5c574bb69e7775d11cb8d2178a",
"effect": "^0.0.0-snapshot-b4323ccacbf56b5c574bb69e7775d11cb8d2178a"
"@op-engineering/op-sqlite": "6.0.2-beta1",
"@effect/sql": "^0.0.0-snapshot-e1ebaaa379fd8da009fc70115350394e6295b9d4",
"effect": "^0.0.0-snapshot-e1ebaaa379fd8da009fc70115350394e6295b9d4"
},

@@ -20,0 +21,0 @@ "publishConfig": {

@@ -9,2 +9,3 @@ /**

import * as Sqlite from "@op-engineering/op-sqlite"
import * as Otel from "@opentelemetry/semantic-conventions"
import * as Config from "effect/Config"

@@ -18,3 +19,5 @@ import type { ConfigError } from "effect/ConfigError"

import * as Layer from "effect/Layer"
import * as Queue from "effect/Queue"
import * as Scope from "effect/Scope"
import * as Stream from "effect/Stream"

@@ -40,2 +43,6 @@ /**

readonly config: SqliteClientConfig
readonly reactive: <A>(
statement: Statement.Statement<A>,
tables: ReadonlyArray<string>
) => Stream.Stream<ReadonlyArray<A>, SqlError>

@@ -60,2 +67,3 @@ /** Not supported in sqlite */

readonly encryptionKey?: string | undefined
readonly spanAttributes?: Record<string, unknown> | undefined
readonly transformResultNames?: ((str: string) => string) | undefined

@@ -80,2 +88,9 @@ readonly transformQueryNames?: ((str: string) => string) | undefined

interface SqliteConnection extends Connection {
readonly reactive: <A>(
statement: Statement.Statement<A>,
tables: ReadonlyArray<string>
) => Stream.Stream<ReadonlyArray<A>, SqlError>
}
/**

@@ -89,2 +104,12 @@ * @category constructor

Effect.gen(function*(_) {
const clientOptions: Parameters<typeof Sqlite.open>[0] = {
name: options.filename
}
if (options.location) {
clientOptions.location = options.location
}
if (options.encryptionKey) {
clientOptions.encryptionKey = options.encryptionKey
}
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames)

@@ -94,11 +119,6 @@ const transformRows = Statement.defaultTransforms(

).array
const handleError = (error: any) => new SqlError({ error })
const makeConnection = Effect.gen(function*(_) {
const db = Sqlite.open({
name: options.filename,
location: options.location!,
encryptionKey: options.encryptionKey!
})
const db = Sqlite.open(clientOptions)
yield* _(Effect.addFinalizer(() => Effect.sync(() => db.close())))

@@ -130,3 +150,3 @@

return identity<Connection>({
return identity<SqliteConnection>({
execute(sql, params) {

@@ -152,2 +172,31 @@ return runTransform(sql, params)

return Effect.dieMessage("executeStream not implemented")
},
reactive<A>(statement: Statement.Statement<A>, tables: ReadonlyArray<string>) {
const [query, params] = statement.compile()
return Queue.sliding<ReadonlyArray<A>>(1).pipe(
Effect.tap((queue) =>
this.execute(query, params).pipe(
Effect.flatMap((rows) => queue.offer(rows))
)
),
Effect.tap((queue) =>
Effect.acquireRelease(
Effect.try({
try: () =>
db.reactiveExecute({
query,
arguments: params as any,
tables: tables as Array<string>,
callback(data) {
queue.unsafeOffer(data.rows)
}
}),
catch: handleError
}),
(cancel) => Effect.sync(cancel)
)
),
Effect.map(Stream.fromQueue),
Stream.unwrapScoped
)
}

@@ -179,5 +228,17 @@ })

transactionAcquirer,
spanAttributes: [["db.system", "sqlite"]]
spanAttributes: [
...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
[Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]
]
}) as SqliteClient,
{ [TypeId]: TypeId, config: options }
{
[TypeId]: TypeId,
config: options,
reactive<A>(statement: Statement.Statement<A>, tables: ReadonlyArray<string>) {
return Stream.unwrap(Effect.map(
acquirer,
(connection) => connection.reactive(statement, tables)
))
}
}
)

@@ -184,0 +245,0 @@ })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet